MessageHandler.c 730 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130
  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. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. //ConfigurationMaxKeys
  12. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  13. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  14. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  15. //=================================
  16. // StatusNotification cycle
  17. //=================================
  18. static int server_cycle_Status = 120;
  19. //===============================
  20. // Configuration: unknownkey
  21. //===============================
  22. static char unknownkey[10][20] = {0};
  23. static int UnknownKeynum = 0;
  24. //===============================
  25. // Gun Total Numbers
  26. //===============================
  27. static int gunTotalNumber = 0;
  28. static uint8_t gunType[4] = {0};
  29. //===============================
  30. // Local List Version
  31. //===============================
  32. static int localversion=0;
  33. static char idTagAuthorization[32] = {0};
  34. //===============================
  35. // OCPP sign variable
  36. //===============================
  37. static int server_sign = FALSE;
  38. int server_pending = FALSE;
  39. static int BootNotificationInterval = 0;
  40. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  41. //===============================
  42. // OCPP auth variable
  43. //===============================
  44. static int authorizeRetryTimes = 0; //number of Retry times
  45. //===============================
  46. // OCPP other variables
  47. //===============================
  48. static int HeartBeatWaitTime = 10;
  49. static int FirstHeartBeat = 0;
  50. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  51. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  52. static char CurrentChargingProfileScheduleStr[30] = {0};
  53. //========================================
  54. // OCPP status/previous related variables
  55. //========================================
  56. static int GunStatusInterval = 10;
  57. static uint8_t statusModeChage[CONNECTOR_QUANTITY] = {FALSE};
  58. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  59. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  60. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  61. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  62. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  63. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  64. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  65. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  66. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  67. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  68. static int TransactionMessageAttemptsValue = 0;
  69. static int TransactionMessageRetryIntervalValue = 0;
  70. static int TempMeterValueInterval = 0;
  71. static struct OCPPAuthLocalElemet
  72. {
  73. int listVersionInt;
  74. char idTagstr[20];
  75. char parentIdTag[20];
  76. char expiryDate[30];
  77. char idTagstatus[16];
  78. }idTagQuery;
  79. //=============================================
  80. // OCPP HeartBeat Response Not Receive Counts
  81. //============================================
  82. static int HeartBeatWithNOResponse = 0;
  83. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  84. extern sqlite3 *db;
  85. int TransactionMessageAttemptsGet(void);
  86. int TransactionMessageRetryIntervalGet(void);
  87. int GetOcppConnStatus(void);
  88. void SetOcppConnStatus(uint8_t status);
  89. int setKeyValue(char *key, char *value);
  90. void OCPP_get_TableAuthlocalAllData(void);
  91. void processUnkownKey(void);
  92. struct StructOCPPMeterValue
  93. {
  94. unsigned char TimeStamp[28];
  95. struct StructSampledValue SampledValue[10];
  96. };
  97. struct ClientTime
  98. {
  99. unsigned int Heartbeat;
  100. unsigned int StatusNotification[CONNECTOR_QUANTITY];
  101. unsigned int StartTransaction;
  102. unsigned int StopTransaction;
  103. unsigned int MeterValues[CONNECTOR_QUANTITY];
  104. }clientTime;
  105. typedef union
  106. {
  107. //Operations Initiated by Central System
  108. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  109. struct
  110. {
  111. //CsMsgValue[0]
  112. unsigned char StatusNotificationReq:1; //bit 0,
  113. unsigned char StatusNotificationConf:1; //bit 1,
  114. unsigned char TriggerMeterValue:1; //bit 2,
  115. unsigned char :5; //bit 5~7
  116. }bits[CONNECTOR_QUANTITY];
  117. }CpinitiateMsg;
  118. CpinitiateMsg cpinitateMsg;
  119. //GetConfiguration Array
  120. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  121. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  122. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  123. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  124. #if 0
  125. static char *ChargePointErrorCodeStr[] = {
  126. MACROSTR(ConnectorLockFailure),
  127. MACROSTR(EVCommunicationError),
  128. MACROSTR(GroundFailure),
  129. MACROSTR(HighTemperature),
  130. MACROSTR(InternalError),
  131. MACROSTR(LocalListConflict),
  132. MACROSTR(NoError),
  133. MACROSTR(OtherError),
  134. MACROSTR(OverCurrentFailure),
  135. MACROSTR(OverVoltage),
  136. MACROSTR(PowerMeterFailure),
  137. MACROSTR(PowerSwitchFailure),
  138. MACROSTR(ReaderFailure),
  139. MACROSTR(ResetFailure),
  140. MACROSTR(UnderVoltage),
  141. MACROSTR(WeakSignal)
  142. };
  143. #endif
  144. static char * ChargePointStatusStr[] = {
  145. MACROSTR(Available),
  146. MACROSTR(Preparing),
  147. MACROSTR(Charging),
  148. MACROSTR(SuspendedEVSE),
  149. MACROSTR(SuspendedEV),
  150. MACROSTR(Finishing),
  151. MACROSTR(Reserved),
  152. MACROSTR(Unavailable),
  153. MACROSTR(Faulted)
  154. };
  155. static char *RegistrationStatusStr[] = {
  156. MACROSTR(Accepted),
  157. MACROSTR(Pending),
  158. MACROSTR(Rejected)
  159. };
  160. static char *AvailabilityTypeStr[] = {
  161. MACROSTR(Inoperative),
  162. MACROSTR(Operative)
  163. };
  164. static char *AvailabilityStatusStr[] = {
  165. MACROSTR(Accepted),
  166. MACROSTR(Rejected),
  167. MACROSTR(Scheduled)
  168. };
  169. static char *ConfigurationStatusStr[] = {
  170. MACROSTR(Accepted),
  171. MACROSTR(Rejected),
  172. MACROSTR(RebootRequired),
  173. MACROSTR(NotSupported)
  174. };
  175. static char *ClearCacheStatusStr[] = {
  176. MACROSTR(Accepted),
  177. MACROSTR(Rejected)
  178. };
  179. static char *ChargingProfilePurposeTypeStr[] = {
  180. MACROSTR(ChargePointMaxProfile),
  181. MACROSTR(TxDefaultProfile),
  182. MACROSTR(TxProfile)
  183. };
  184. static char *ChargingProfileStatusStr[] = {
  185. MACROSTR(Accepted),
  186. MACROSTR(Rejected),
  187. MACROSTR(NotSupported)
  188. };
  189. static char *ClearChargingProfileStatusStr[] = {
  190. MACROSTR(Accepted),
  191. MACROSTR(Unknown)
  192. };
  193. static char *GetCompositeScheduleStatusStr[] = {
  194. MACROSTR(Accepted),
  195. MACROSTR(Rejected)
  196. };
  197. static char *UpdateTypeStr[] = {
  198. MACROSTR(Differential),
  199. MACROSTR(Full)
  200. };
  201. static char *UpdateStatusStr[] = {
  202. MACROSTR(Accepted),
  203. MACROSTR(Failed),
  204. MACROSTR(NotSupported),
  205. MACROSTR(VersionMismatch)
  206. };
  207. static char *RemoteStartStopStatusStr[] = {
  208. MACROSTR(Accepted),
  209. MACROSTR(Rejected)
  210. };
  211. static char *ReservationStatusStr[] = {
  212. MACROSTR(Accepted),
  213. MACROSTR(Faulted),
  214. MACROSTR(Occupied),
  215. MACROSTR(Rejected),
  216. MACROSTR(Unavailable)
  217. };
  218. static char *ResetTypeStr[] = {
  219. MACROSTR(Hard),
  220. MACROSTR(Soft)
  221. };
  222. static char *ResetStatusStr[] = {
  223. MACROSTR(Accepted),
  224. MACROSTR(Rejected)
  225. };
  226. static char * DiagnosticsStatusStr[] = {
  227. MACROSTR(Idle),
  228. MACROSTR(Uploaded),
  229. MACROSTR(UploadFailed),
  230. MACROSTR(Uploading)
  231. };
  232. static char * FirmwareStatusStr[] = {
  233. MACROSTR(Downloaded),
  234. MACROSTR(DownloadFailed),
  235. MACROSTR(Downloading),
  236. MACROSTR(Idle),
  237. MACROSTR(InstallationFailed),
  238. MACROSTR(Installing),
  239. MACROSTR(Installed)
  240. };
  241. static char * MessageTriggerStr[] = {
  242. MACROSTR(BootNotification),
  243. MACROSTR(DiagnosticsStatusNotification),
  244. MACROSTR(FirmwareStatusNotification),
  245. MACROSTR(Heartbeat),
  246. MACROSTR(MeterValues),
  247. MACROSTR(StatusNotification)
  248. };
  249. static char * TriggerMessageStatusStr[] = {
  250. MACROSTR(Accepted),
  251. MACROSTR(Rejected),
  252. MACROSTR(NotImplemented)
  253. };
  254. static char * UnlockStatusStr[] = {
  255. MACROSTR(Unlocked),
  256. MACROSTR(UnlockFailed),
  257. MACROSTR(NotSupported)
  258. };
  259. #if 0
  260. static char * StopTransactionReasonStr[] = {
  261. MACROSTR(EmergencyStop),
  262. MACROSTR(EVDisconnected),
  263. MACROSTR(HardReset),
  264. MACROSTR(Local),
  265. MACROSTR(Other),
  266. MACROSTR(PowerLoss),
  267. MACROSTR(Reboot),
  268. MACROSTR(Remote),
  269. MACROSTR(SoftReset),
  270. MACROSTR(UnlockCommand),
  271. MACROSTR(DeAuthorized)
  272. };
  273. #endif
  274. static char * CancelReservationStatusStr[] = {
  275. MACROSTR(Accepted),
  276. MACROSTR(Rejected)
  277. };
  278. static char * ReadingContextStr[] = {
  279. MACROSTR(Interruption.Begin),
  280. MACROSTR(Interruption.End),
  281. MACROSTR(Other),
  282. MACROSTR(Sample.Clock),
  283. MACROSTR(Sample.Periodic),
  284. MACROSTR(Transaction.Begin),
  285. MACROSTR(Transaction.End),
  286. MACROSTR(Trigger)
  287. };
  288. static char * ValueFormatStr[] = {
  289. MACROSTR(Raw),
  290. MACROSTR(SignedData)
  291. };
  292. static char * MeasurandStr[] = {
  293. MACROSTR(Current.Export),
  294. MACROSTR(Current.Import),
  295. MACROSTR(Current.Offered),
  296. MACROSTR(Energy.Active.Export.Register),
  297. MACROSTR(Energy.Active.Import.Register),
  298. MACROSTR(Energy.Reactive.Export.Register),
  299. MACROSTR(Energy.Reactive.Import.Register),
  300. MACROSTR(Energy.Active.Export.Interval),
  301. MACROSTR(Energy.Active.Import.Interval),
  302. MACROSTR(Energy.Reactive.Export.Interval),
  303. MACROSTR(Energy.Reactive.Import.Interval),
  304. MACROSTR(Frequency),
  305. MACROSTR(Power.Active.Export),
  306. MACROSTR(Power.Active.Import),
  307. MACROSTR(Power.Factor),
  308. MACROSTR(Power.Offered),
  309. MACROSTR(Power.Reactive.ExportMACROSTR),
  310. MACROSTR(Power.Reactive.Import),
  311. MACROSTR(RPM),
  312. MACROSTR(SoC),
  313. MACROSTR(Temperature),
  314. MACROSTR(Voltage)
  315. };
  316. static char * LocationStr[] = {
  317. MACROSTR(Body),
  318. MACROSTR(Cable),
  319. MACROSTR(EV),
  320. MACROSTR(Inlet),
  321. MACROSTR(Outlet)
  322. };
  323. static char * PhaseStr[] = {
  324. MACROSTR(L1),
  325. MACROSTR(L2),
  326. MACROSTR(L3),
  327. MACROSTR(N),
  328. MACROSTR(L1-N),
  329. MACROSTR(L2-N),
  330. MACROSTR(L3-N),
  331. MACROSTR(L1-L2),
  332. MACROSTR(L2-L3),
  333. MACROSTR(L3-L1)
  334. };
  335. static char * UnitOfMeasureStr[] = {
  336. MACROSTR(Wh),
  337. MACROSTR(kWh),
  338. MACROSTR(varh),
  339. MACROSTR(kvarh),
  340. MACROSTR(W),
  341. MACROSTR(kW),
  342. MACROSTR(VA),
  343. MACROSTR(kVA),
  344. MACROSTR(var),
  345. MACROSTR(kvar),
  346. MACROSTR(A),
  347. MACROSTR(V),
  348. MACROSTR(Celsius),
  349. MACROSTR(Fahrenheit),
  350. MACROSTR(K),
  351. MACROSTR(Percent)
  352. };
  353. //==========================================
  354. // Check time passed since today
  355. //==========================================
  356. long long DiffTimebWithNow(struct timeb ST)
  357. {
  358. //return milli-second
  359. struct timeb ET;
  360. long long StartTime,StopTime;
  361. ftime(&ET);
  362. StartTime=(long long)ST.time;
  363. StopTime=(long long)ET.time;
  364. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  365. }
  366. int getTimePassSinceToday()
  367. {
  368. int result = -1;
  369. static time_t lastTime;
  370. time_t t;
  371. struct tm *tmStartToday;
  372. struct timeb tbStartToday;
  373. t=time(NULL);
  374. if(difftime(t, lastTime)>0)
  375. {
  376. tmStartToday=localtime(&t);
  377. tmStartToday->tm_hour = 0;
  378. tmStartToday->tm_min = 0;
  379. tmStartToday->tm_sec = 0;
  380. tbStartToday.time = mktime(tmStartToday);
  381. tbStartToday.millitm = 0;
  382. result = DiffTimebWithNow(tbStartToday)/1000;
  383. lastTime = t;
  384. }
  385. return result;
  386. }
  387. void getNowDatetime(uint8_t *data)
  388. {
  389. time_t t = time(NULL);
  390. struct tm tm = *localtime(&t);
  391. sprintf((char*)data, "%04d-%02d-%02dT%02d:%02d:%02dZ", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
  392. }
  393. //==========================================
  394. // GetCompositeSchedule logic related function
  395. //==========================================
  396. int DiffTimebSec(struct timeb ST, struct timeb ET)
  397. {
  398. //return milli-second
  399. unsigned int StartTime,StopTime;
  400. StartTime=(unsigned int)ST.time;
  401. StopTime=(unsigned int)ET.time;
  402. return (StopTime-StartTime);
  403. }
  404. int DiffTimebWithNowSec(struct timeb ST)
  405. {
  406. //return milli-second
  407. struct timeb ET;
  408. unsigned int StartTime,StopTime;
  409. ftime(&ET);
  410. StartTime=(unsigned int)ST.time;
  411. StopTime=(unsigned int)ET.time;
  412. return (StopTime-StartTime);
  413. }
  414. int getStartStop(uint8_t *start, uint8_t *stop)
  415. {
  416. int result = -1;
  417. struct tm tmStart;
  418. struct timeb tbStart;
  419. struct tm tmStop;
  420. struct timeb tbStop;
  421. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  422. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  423. {
  424. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  425. //DEBUG_INFO("Stop: %d-%d-%d %d:%d:%d\n", tmStop.tm_year, tmStop.tm_mon, tmStop.tm_mday, tmStop.tm_hour, tmStop.tm_min, tmStop.tm_sec);
  426. tmStart.tm_year -= 1900;
  427. tmStart.tm_mon -= 1;
  428. tbStart.time = mktime(&tmStart);
  429. tbStart.millitm = 0;
  430. tmStop.tm_year -= 1900;
  431. tmStop.tm_mon -= 1;
  432. tbStop.time = mktime(&tmStop);
  433. tbStop.millitm = 0;
  434. result = DiffTimebSec(tbStart, tbStop);
  435. //DEBUG_INFO("getStartStop(): %d\n", result);
  436. }
  437. else
  438. {
  439. DEBUG_WARN("Start or stop date parsing error.\r\n");
  440. }
  441. return result;
  442. }
  443. int isOvertNow(uint8_t *start)
  444. {
  445. int result = NO;
  446. struct tm tmStart;
  447. struct timeb tbStart;
  448. 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))
  449. {
  450. //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);
  451. tmStart.tm_year -= 1900;
  452. tmStart.tm_mon -= 1;
  453. tbStart.time = mktime(&tmStart);
  454. tbStart.millitm = 0;
  455. if(DiffTimebWithNowSec(tbStart) <= 0)
  456. result = NO;
  457. else
  458. result = YES;
  459. }
  460. else
  461. {
  462. DEBUG_WARN("Start date parsing error.\n");
  463. }
  464. return result;
  465. }
  466. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  467. {
  468. int result = -1;
  469. struct tm tmStart;
  470. struct timeb tbStart;
  471. struct tm tmStop;
  472. struct timeb tbStop;
  473. 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) &&
  474. (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))
  475. {
  476. tmStart.tm_year -= 1900;
  477. tmStart.tm_mon -= 1;
  478. tbStart.time = mktime(&tmStart);
  479. tbStart.millitm = 0;
  480. tmStop.tm_year -= 1900;
  481. tmStop.tm_mon -= 1;
  482. tbStop.time = mktime(&tmStop);
  483. tbStop.millitm = 0;
  484. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  485. }
  486. return result;
  487. }
  488. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  489. {
  490. FILE *fp;
  491. char profileFileName[128];
  492. char *line = NULL;
  493. size_t len = 0;
  494. time_t CurrentTime;
  495. struct tm *tmComposite;
  496. struct StructChargingProfile maxProfile;
  497. struct StructChargingProfile defaultTxProfile;
  498. struct StructChargingProfile txProfile;
  499. struct StructChargingSchedulePeriod tmpPeriod;
  500. uint8_t limitMax=0;
  501. uint8_t limitDef=0;
  502. uint8_t limitTx=0;
  503. int compositePeriodIdx = 0;
  504. CurrentTime = time(NULL);
  505. tmComposite=localtime(&CurrentTime);
  506. 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);
  507. if(isUnitA)
  508. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  509. else
  510. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  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. if(isUnitA)
  586. {
  587. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  588. 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++)
  589. {
  590. 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"));
  591. 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?
  592. 3:
  593. 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")));
  594. 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*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):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")));
  595. }
  596. }
  597. else
  598. {
  599. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  600. 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++)
  601. {
  602. 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"));
  603. 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?
  604. 3:
  605. 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")));
  606. 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")):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*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  607. }
  608. }
  609. // Optional item
  610. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  611. {
  612. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  613. }
  614. else
  615. {
  616. sprintf((char*)txProfile.ValidFrom, " ");
  617. }
  618. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  619. {
  620. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  621. }
  622. else
  623. {
  624. sprintf((char*)txProfile.ValidTo, " ");
  625. }
  626. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  627. {
  628. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  629. }
  630. else
  631. {
  632. sprintf((char*)txProfile.RecurrencyKind, " ");
  633. }
  634. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  635. {
  636. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  637. }
  638. else
  639. {
  640. txProfile.TransactionId = -1;
  641. }
  642. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  643. {
  644. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  645. }
  646. else
  647. {
  648. txProfile.ChargingSchedule.Duration = 86400;
  649. }
  650. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  651. {
  652. 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")));
  653. }
  654. else
  655. {
  656. 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));
  657. }
  658. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  659. {
  660. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  661. }
  662. else
  663. {
  664. txProfile.ChargingSchedule.MinChargingRate = -1;
  665. }
  666. }
  667. }
  668. }
  669. else
  670. {
  671. if(txProfile.ChargingProfileId == -1)
  672. DEBUG_INFO("TxProfile found.\n");
  673. else
  674. DEBUG_INFO("TxProfile updated.\n");
  675. // Required item
  676. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  677. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  678. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  679. if(isUnitA)
  680. {
  681. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  682. 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++)
  683. {
  684. 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"));
  685. 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?
  686. 3:
  687. 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")));
  688. 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*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):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")));
  689. }
  690. }
  691. else
  692. {
  693. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  694. 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++)
  695. {
  696. 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"));
  697. 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?
  698. 3:
  699. 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")));
  700. 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")):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*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  701. }
  702. }
  703. // Optional item
  704. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  705. {
  706. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  707. }
  708. else
  709. {
  710. sprintf((char*)txProfile.ValidFrom, " ");
  711. }
  712. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  713. {
  714. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  715. }
  716. else
  717. {
  718. sprintf((char*)txProfile.ValidTo, " ");
  719. }
  720. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  721. {
  722. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  723. }
  724. else
  725. {
  726. sprintf((char*)txProfile.RecurrencyKind, " ");
  727. }
  728. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  729. {
  730. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  731. }
  732. else
  733. {
  734. txProfile.TransactionId = -1;
  735. }
  736. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  737. {
  738. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  739. }
  740. else
  741. {
  742. txProfile.ChargingSchedule.Duration = 86400;
  743. }
  744. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  745. {
  746. 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")));
  747. }
  748. else
  749. {
  750. 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));
  751. }
  752. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  753. {
  754. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  755. }
  756. else
  757. {
  758. txProfile.ChargingSchedule.MinChargingRate = -1;
  759. }
  760. }
  761. }
  762. }
  763. json_object_put(obj);
  764. }
  765. fclose(fp);
  766. /*
  767. if(txProfile.ChargingProfileId != -1)
  768. {
  769. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  770. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  771. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  772. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  773. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  774. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  775. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  776. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  777. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  778. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  779. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  780. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  781. {
  782. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  783. {
  784. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  785. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  786. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  787. }
  788. }
  789. }
  790. else
  791. DEBUG_INFO("TxProfile not found.\n");*/
  792. }
  793. // Search default tx profile
  794. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  795. if((access(profileFileName, F_OK))==-1)
  796. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  797. if((access(profileFileName, F_OK))!=-1)
  798. {
  799. fp = fopen(profileFileName, "r");
  800. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  801. {
  802. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  803. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  804. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  805. }
  806. defaultTxProfile.ChargingProfileId = -1;
  807. defaultTxProfile.StackLevel = -1;
  808. while(getline(&line, &len, fp) != -1)
  809. {
  810. json_object *obj = NULL;
  811. obj = json_tokener_parse(line);
  812. if(is_error(obj))
  813. {
  814. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  815. }
  816. else
  817. {
  818. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  819. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  820. )
  821. {
  822. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  823. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  824. )
  825. {
  826. struct tm tmFrom, tmTo;
  827. struct timeb tbFrom, tbTo;
  828. 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) &&
  829. (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))
  830. {
  831. tmFrom.tm_year -= 1900;
  832. tmFrom.tm_mon -= 1;
  833. tbFrom.time = mktime(&tmFrom);
  834. tmTo.tm_year -= 1900;
  835. tmTo.tm_mon -= 1;
  836. tbTo.time = mktime(&tmTo);
  837. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  838. {
  839. if(defaultTxProfile.ChargingProfileId == -1)
  840. DEBUG_INFO("TxDefaultProfile found.\n");
  841. else
  842. DEBUG_INFO("TxDefaultProfile updated.\n");
  843. // Required item
  844. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  845. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  846. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  847. if(isUnitA)
  848. {
  849. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  850. 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++)
  851. {
  852. 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"));
  853. 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?
  854. 3:
  855. 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")));
  856. 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*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):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")));
  857. }
  858. }
  859. else
  860. {
  861. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  862. 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++)
  863. {
  864. 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"));
  865. 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?
  866. 3:
  867. 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")));
  868. 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")):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*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  869. }
  870. }
  871. // Optional item
  872. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  873. {
  874. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  875. }
  876. else
  877. {
  878. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  879. }
  880. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  881. {
  882. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  883. }
  884. else
  885. {
  886. sprintf((char*)defaultTxProfile.ValidTo, " ");
  887. }
  888. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  889. {
  890. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  891. }
  892. else
  893. {
  894. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  895. }
  896. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  897. {
  898. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  899. }
  900. else
  901. {
  902. defaultTxProfile.TransactionId = -1;
  903. }
  904. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  905. {
  906. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  907. }
  908. else
  909. {
  910. defaultTxProfile.ChargingSchedule.Duration = 86400;
  911. }
  912. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  913. {
  914. 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")));
  915. }
  916. else
  917. {
  918. 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));
  919. }
  920. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  921. {
  922. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  923. }
  924. else
  925. {
  926. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  927. }
  928. }
  929. }
  930. }
  931. else
  932. {
  933. if(defaultTxProfile.ChargingProfileId == -1)
  934. DEBUG_INFO("TxDefaultProfile found.\n");
  935. else
  936. DEBUG_INFO("TxDefaultProfile updated.\n");
  937. // Required item
  938. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  939. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  940. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  941. if(isUnitA)
  942. {
  943. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  944. 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++)
  945. {
  946. 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"));
  947. 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?
  948. 3:
  949. 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")));
  950. 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*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):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")));
  951. }
  952. }
  953. else
  954. {
  955. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  956. 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++)
  957. {
  958. 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"));
  959. 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?
  960. 3:
  961. 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")));
  962. 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")):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*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  963. }
  964. }
  965. // Optional item
  966. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  967. {
  968. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  969. }
  970. else
  971. {
  972. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  973. }
  974. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  975. {
  976. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  977. }
  978. else
  979. {
  980. sprintf((char*)defaultTxProfile.ValidTo, " ");
  981. }
  982. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  983. {
  984. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  985. }
  986. else
  987. {
  988. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  989. }
  990. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  991. {
  992. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  993. }
  994. else
  995. {
  996. defaultTxProfile.TransactionId = -1;
  997. }
  998. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  999. {
  1000. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1001. }
  1002. else
  1003. {
  1004. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1005. }
  1006. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1007. {
  1008. 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")));
  1009. }
  1010. else
  1011. {
  1012. 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));
  1013. }
  1014. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1015. {
  1016. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1017. }
  1018. else
  1019. {
  1020. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1021. }
  1022. }
  1023. }
  1024. }
  1025. json_object_put(obj);
  1026. }
  1027. fclose(fp);
  1028. /*
  1029. if(defaultTxProfile.ChargingProfileId != -1)
  1030. {
  1031. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1032. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1033. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1034. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1035. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1036. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1037. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1038. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  1039. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1040. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1041. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1042. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1043. {
  1044. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1045. {
  1046. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1047. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1048. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1049. }
  1050. }
  1051. }
  1052. else
  1053. DEBUG_INFO("TxDefaultProfile not found.\n");
  1054. DEBUG_INFO("------------------------------------\n");*/
  1055. }
  1056. // Search max profile
  1057. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1058. if((access(profileFileName, F_OK))!=-1)
  1059. {
  1060. fp = fopen(profileFileName, "r");
  1061. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1062. {
  1063. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1064. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1065. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1066. }
  1067. maxProfile.ChargingProfileId = -1;
  1068. maxProfile.StackLevel = -1;
  1069. while(getline(&line, &len, fp) != -1)
  1070. {
  1071. json_object *obj = NULL;
  1072. obj = json_tokener_parse(line);
  1073. if(is_error(obj))
  1074. {
  1075. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1076. }
  1077. else
  1078. {
  1079. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  1080. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1081. )
  1082. {
  1083. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1084. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1085. )
  1086. {
  1087. struct tm tmFrom, tmTo;
  1088. struct timeb tbFrom, tbTo;
  1089. 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) &&
  1090. (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))
  1091. {
  1092. tmFrom.tm_year -= 1900;
  1093. tmFrom.tm_mon -= 1;
  1094. tbFrom.time = mktime(&tmFrom);
  1095. tmTo.tm_year -= 1900;
  1096. tmTo.tm_mon -= 1;
  1097. tbTo.time = mktime(&tmTo);
  1098. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1099. {
  1100. if(maxProfile.ChargingProfileId == -1)
  1101. DEBUG_INFO("MaxProfile found.\n");
  1102. else
  1103. DEBUG_INFO("MaxProfile updated.\n");
  1104. // Required item
  1105. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1106. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1107. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1108. if(isUnitA)
  1109. {
  1110. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1111. 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++)
  1112. {
  1113. 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"));
  1114. 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?
  1115. 3:
  1116. 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")));
  1117. 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*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):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")));
  1118. }
  1119. }
  1120. else
  1121. {
  1122. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1123. 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++)
  1124. {
  1125. 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"));
  1126. 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?
  1127. 3:
  1128. 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")));
  1129. 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")):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*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1130. }
  1131. }
  1132. // Optional item
  1133. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1134. {
  1135. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1136. }
  1137. else
  1138. {
  1139. sprintf((char*)maxProfile.ValidFrom, " ");
  1140. }
  1141. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1142. {
  1143. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1144. }
  1145. else
  1146. {
  1147. sprintf((char*)maxProfile.ValidTo, " ");
  1148. }
  1149. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1150. {
  1151. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1152. }
  1153. else
  1154. {
  1155. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1156. }
  1157. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1158. {
  1159. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1160. }
  1161. else
  1162. {
  1163. maxProfile.TransactionId = -1;
  1164. }
  1165. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1166. {
  1167. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1168. }
  1169. else
  1170. {
  1171. maxProfile.ChargingSchedule.Duration = 86400;
  1172. }
  1173. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1174. {
  1175. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1176. }
  1177. else
  1178. {
  1179. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1180. }
  1181. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1182. {
  1183. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1184. }
  1185. else
  1186. {
  1187. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1188. }
  1189. }
  1190. }
  1191. }
  1192. else
  1193. {
  1194. if(maxProfile.ChargingProfileId == -1)
  1195. DEBUG_INFO("MaxProfile found.\n");
  1196. else
  1197. DEBUG_INFO("MaxProfile updated.\n");
  1198. // Required item
  1199. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1200. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1201. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1202. if(isUnitA)
  1203. {
  1204. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1205. 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++)
  1206. {
  1207. 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"));
  1208. 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?
  1209. 3:
  1210. 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")));
  1211. 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*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):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")));
  1212. }
  1213. }
  1214. else
  1215. {
  1216. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1217. 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++)
  1218. {
  1219. 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"));
  1220. 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?
  1221. 3:
  1222. 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")));
  1223. 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")):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*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1224. }
  1225. }
  1226. // Optional item
  1227. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1228. {
  1229. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1230. }
  1231. else
  1232. {
  1233. sprintf((char*)maxProfile.ValidFrom, " ");
  1234. }
  1235. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1236. {
  1237. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1238. }
  1239. else
  1240. {
  1241. sprintf((char*)maxProfile.ValidTo, " ");
  1242. }
  1243. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1244. {
  1245. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1246. }
  1247. else
  1248. {
  1249. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1250. }
  1251. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1252. {
  1253. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1254. }
  1255. else
  1256. {
  1257. maxProfile.TransactionId = -1;
  1258. }
  1259. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1260. {
  1261. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1262. }
  1263. else
  1264. {
  1265. maxProfile.ChargingSchedule.Duration = 86400;
  1266. }
  1267. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1268. {
  1269. 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")));
  1270. }
  1271. else
  1272. {
  1273. 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));
  1274. }
  1275. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1276. {
  1277. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1278. }
  1279. else
  1280. {
  1281. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1282. }
  1283. }
  1284. }
  1285. }
  1286. json_object_put(obj);
  1287. }
  1288. fclose(fp);
  1289. /*
  1290. if(maxProfile.ChargingProfileId !=-1)
  1291. {
  1292. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1293. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1294. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1295. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1296. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1297. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1298. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1299. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1300. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1301. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1302. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1303. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1304. {
  1305. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1306. {
  1307. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1308. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1309. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1310. }
  1311. }
  1312. }
  1313. else
  1314. DEBUG_INFO("MaxProfile not found.\n");
  1315. DEBUG_INFO("------------------------------------\n");*/
  1316. }
  1317. /*
  1318. * Align found profile start schedule & periods
  1319. */
  1320. //DEBUG_INFO("====================================\n");
  1321. /*
  1322. // For local test usage, force modify found profile start schedule info
  1323. 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);
  1324. 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);
  1325. 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);
  1326. */
  1327. if(txProfile.ChargingProfileId != -1)
  1328. {
  1329. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  1330. {
  1331. if(txProfile.ChargingSchedule.Duration != -1)
  1332. {
  1333. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1334. 0:
  1335. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1336. }
  1337. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1338. {
  1339. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1340. {
  1341. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1342. 0:
  1343. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1344. if(idxPeriod > 0)
  1345. {
  1346. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1347. {
  1348. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1349. }
  1350. }
  1351. }
  1352. }
  1353. }
  1354. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  1355. {
  1356. if(txProfile.ChargingSchedule.Duration != -1)
  1357. {
  1358. 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?
  1359. 0:
  1360. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1361. }
  1362. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1363. {
  1364. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1365. {
  1366. 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?
  1367. 0:
  1368. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1369. if(idxPeriod > 0)
  1370. {
  1371. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1372. {
  1373. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1374. }
  1375. }
  1376. }
  1377. }
  1378. }
  1379. else
  1380. {
  1381. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  1382. {
  1383. if(txProfile.ChargingSchedule.Duration != -1)
  1384. {
  1385. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1386. 0:
  1387. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1388. }
  1389. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1390. {
  1391. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1392. {
  1393. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1394. 0:
  1395. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1396. if(idxPeriod > 0)
  1397. {
  1398. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1399. {
  1400. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1401. }
  1402. }
  1403. }
  1404. }
  1405. }
  1406. else
  1407. {
  1408. if(txProfile.ChargingSchedule.Duration != -1)
  1409. {
  1410. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1411. 0:
  1412. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1413. }
  1414. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1415. {
  1416. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1417. {
  1418. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1419. 0:
  1420. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1421. if(idxPeriod > 0)
  1422. {
  1423. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1424. {
  1425. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1426. }
  1427. }
  1428. }
  1429. }
  1430. }
  1431. }
  1432. /*
  1433. DEBUG_INFO("txProfile after align.\n");
  1434. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1435. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1436. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1437. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1438. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1439. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1440. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1441. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1442. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1443. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1444. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1445. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1446. {
  1447. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1448. {
  1449. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1450. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1451. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1452. }
  1453. }*/
  1454. }
  1455. if(defaultTxProfile.ChargingProfileId != -1)
  1456. {
  1457. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  1458. {
  1459. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1460. {
  1461. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1462. 0:
  1463. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1464. }
  1465. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1466. {
  1467. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1468. {
  1469. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1470. 0:
  1471. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1472. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1473. {
  1474. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1475. }
  1476. if(idxPeriod > 0)
  1477. {
  1478. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1479. {
  1480. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1481. }
  1482. }
  1483. }
  1484. }
  1485. }
  1486. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  1487. {
  1488. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1489. {
  1490. 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?
  1491. 0:
  1492. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1493. }
  1494. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1495. {
  1496. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1497. {
  1498. 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?
  1499. 0:
  1500. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1501. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1502. {
  1503. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1504. }
  1505. if(idxPeriod > 0)
  1506. {
  1507. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1508. {
  1509. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1510. }
  1511. }
  1512. }
  1513. }
  1514. }
  1515. else
  1516. {
  1517. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  1518. {
  1519. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1520. {
  1521. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1522. 0:
  1523. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1524. }
  1525. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1526. {
  1527. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1528. {
  1529. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1530. 0:
  1531. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1532. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1533. {
  1534. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1535. }
  1536. if(idxPeriod > 0)
  1537. {
  1538. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1539. {
  1540. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1541. }
  1542. }
  1543. }
  1544. }
  1545. }
  1546. else
  1547. {
  1548. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1549. {
  1550. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1551. 0:
  1552. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1553. }
  1554. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1555. {
  1556. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1557. {
  1558. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1559. 0:
  1560. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1561. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1562. {
  1563. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1564. }
  1565. if(idxPeriod > 0)
  1566. {
  1567. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1568. {
  1569. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1570. }
  1571. }
  1572. }
  1573. }
  1574. }
  1575. }
  1576. /*
  1577. DEBUG_INFO("defaultTxProfile after align.\n");
  1578. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1579. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1580. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1581. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1582. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1583. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1584. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1585. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1586. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1587. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1588. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1589. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1590. {
  1591. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1592. {
  1593. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1594. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1595. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1596. }
  1597. }
  1598. DEBUG_INFO("------------------------------------\n");*/
  1599. }
  1600. if(maxProfile.ChargingProfileId != -1)
  1601. {
  1602. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1603. {
  1604. if(maxProfile.ChargingSchedule.Duration != -1)
  1605. {
  1606. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1607. 0:
  1608. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1609. }
  1610. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1611. {
  1612. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1613. {
  1614. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1615. 0:
  1616. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1617. if(idxPeriod > 0)
  1618. {
  1619. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1620. {
  1621. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1622. }
  1623. }
  1624. }
  1625. }
  1626. }
  1627. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1628. {
  1629. if(maxProfile.ChargingSchedule.Duration != -1)
  1630. {
  1631. 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?
  1632. 0:
  1633. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1634. }
  1635. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1636. {
  1637. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1638. {
  1639. 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?
  1640. 0:
  1641. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1642. if(idxPeriod > 0)
  1643. {
  1644. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1645. {
  1646. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1647. }
  1648. }
  1649. }
  1650. }
  1651. }
  1652. else
  1653. {
  1654. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1655. {
  1656. if(maxProfile.ChargingSchedule.Duration != -1)
  1657. {
  1658. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1659. 0:
  1660. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1661. }
  1662. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1663. {
  1664. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1665. {
  1666. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1667. 0:
  1668. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1669. if(idxPeriod > 0)
  1670. {
  1671. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1672. {
  1673. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1674. }
  1675. }
  1676. }
  1677. }
  1678. }
  1679. else
  1680. {
  1681. if(maxProfile.ChargingSchedule.Duration != -1)
  1682. {
  1683. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1684. 0:
  1685. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1686. }
  1687. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1688. {
  1689. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1690. {
  1691. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1692. 0:
  1693. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1694. if(idxPeriod > 0)
  1695. {
  1696. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1697. {
  1698. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1699. }
  1700. }
  1701. }
  1702. }
  1703. }
  1704. }
  1705. /*
  1706. DEBUG_INFO("MaxProfile after align.\n");
  1707. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1708. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1709. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1710. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1711. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1712. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1713. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1714. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1715. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1716. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1717. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1718. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1719. {
  1720. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1721. {
  1722. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1723. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1724. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1725. }
  1726. }
  1727. DEBUG_INFO("------------------------------------\n");*/
  1728. }
  1729. /*
  1730. * Merge to conposite schedule
  1731. */
  1732. //DEBUG_INFO("====================================\n");
  1733. // Find each profile period quantity
  1734. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1735. {
  1736. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1737. limitMax = idx+1;
  1738. }
  1739. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1740. {
  1741. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1742. limitDef = idx+1;
  1743. }
  1744. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1745. {
  1746. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1747. limitTx = idx+1;
  1748. }
  1749. // TxProfile found, composite schedule based on it
  1750. if(txProfile.ChargingProfileId != -1)
  1751. {
  1752. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  1753. {
  1754. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  1755. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  1756. (txProfile.ChargingSchedule.Duration > 0))
  1757. {
  1758. if(maxProfile.ChargingProfileId != -1)
  1759. {
  1760. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1761. {
  1762. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  1763. {
  1764. if((maxProfile.ChargingSchedule.Duration > 0))
  1765. {
  1766. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1767. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1768. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1769. }
  1770. else
  1771. {
  1772. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1773. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1774. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  1775. }
  1776. }
  1777. if(idxMaxPeriod == (limitMax-1))
  1778. {
  1779. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1780. {
  1781. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1782. {
  1783. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1784. compositePeriodIdx++;
  1785. }
  1786. else
  1787. {
  1788. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1789. }
  1790. }
  1791. }
  1792. }
  1793. }
  1794. else
  1795. {
  1796. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1797. {
  1798. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1799. compositePeriodIdx++;
  1800. }
  1801. else
  1802. {
  1803. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1804. }
  1805. }
  1806. }
  1807. if(idxTxPeriod == (limitTx-1))
  1808. {
  1809. if(defaultTxProfile.ChargingProfileId != -1)
  1810. {
  1811. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1812. {
  1813. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  1814. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  1815. (defaultTxProfile.ChargingSchedule.Duration>0))
  1816. {
  1817. if(maxProfile.ChargingProfileId != -1)
  1818. {
  1819. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1820. {
  1821. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1822. {
  1823. if((maxProfile.ChargingSchedule.Duration > 0))
  1824. {
  1825. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1826. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1827. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1828. }
  1829. else
  1830. {
  1831. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1832. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1833. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  1834. }
  1835. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1836. {
  1837. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1838. {
  1839. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1840. compositePeriodIdx++;
  1841. }
  1842. else
  1843. {
  1844. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1845. }
  1846. }
  1847. break;
  1848. }
  1849. }
  1850. }
  1851. else
  1852. {
  1853. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1854. {
  1855. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1856. compositePeriodIdx++;
  1857. }
  1858. else
  1859. {
  1860. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1861. }
  1862. }
  1863. }
  1864. }
  1865. }
  1866. }
  1867. }
  1868. }
  1869. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  1870. else if(defaultTxProfile.ChargingProfileId != -1)
  1871. {
  1872. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1873. {
  1874. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  1875. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  1876. (defaultTxProfile.ChargingSchedule.Duration > 0))
  1877. {
  1878. if(maxProfile.ChargingProfileId != -1)
  1879. {
  1880. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1881. {
  1882. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1883. {
  1884. if((maxProfile.ChargingSchedule.Duration > 0))
  1885. {
  1886. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1887. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1888. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  1889. }
  1890. else
  1891. {
  1892. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1893. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1894. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  1895. }
  1896. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1897. {
  1898. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1899. {
  1900. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1901. compositePeriodIdx++;
  1902. }
  1903. else
  1904. {
  1905. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1906. }
  1907. }
  1908. break;
  1909. }
  1910. }
  1911. }
  1912. else
  1913. {
  1914. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1915. {
  1916. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1917. compositePeriodIdx++;
  1918. }
  1919. else
  1920. {
  1921. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1922. }
  1923. }
  1924. }
  1925. }
  1926. }
  1927. // Fill other period by MaxProfile
  1928. if(maxProfile.ChargingProfileId != -1)
  1929. {
  1930. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1931. {
  1932. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1933. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1934. (maxProfile.ChargingSchedule.Duration > 0))
  1935. {
  1936. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  1937. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  1938. {
  1939. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  1940. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  1941. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1942. }
  1943. if((maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  1944. {
  1945. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.Duration;
  1946. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  1947. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1948. }
  1949. if(tmpPeriod.Limit != -1)
  1950. {
  1951. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1952. {
  1953. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1954. {
  1955. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1956. compositePeriodIdx++;
  1957. }
  1958. else
  1959. {
  1960. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1961. }
  1962. }
  1963. }
  1964. }
  1965. }
  1966. }
  1967. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  1968. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1969. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1970. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1971. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1972. {
  1973. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1974. {
  1975. compositeProfile->ChargingProfileId = 1;
  1976. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1977. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1978. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1979. }
  1980. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1981. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1982. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1983. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1984. }
  1985. if(line)
  1986. free(line);
  1987. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  1988. }
  1989. //==========================================
  1990. // Init all share memory
  1991. //==========================================
  1992. int InitShareMemory()
  1993. {
  1994. int result = PASS;
  1995. int MeterSMId;
  1996. //creat ShmSysConfigAndInfo
  1997. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  1998. {
  1999. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  2000. result = FAIL;
  2001. }
  2002. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2003. {
  2004. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  2005. result = FAIL;
  2006. }
  2007. else
  2008. {}
  2009. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  2010. {
  2011. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  2012. result = FAIL;
  2013. }
  2014. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2015. {
  2016. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  2017. result = FAIL;
  2018. }
  2019. else
  2020. {}
  2021. //creat ShmPsuData
  2022. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  2023. {
  2024. DEBUG_ERROR("shmget ShmPsuData NG\n");
  2025. result = FAIL;
  2026. }
  2027. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2028. {
  2029. DEBUG_ERROR("shmat ShmPsuData NG\n");
  2030. result = FAIL;
  2031. }
  2032. else
  2033. {}
  2034. //creat ShmOCPP16Data
  2035. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  2036. {
  2037. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  2038. result = FAIL;
  2039. }
  2040. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2041. {
  2042. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  2043. result = FAIL;
  2044. }
  2045. else
  2046. {}
  2047. /****************************** For Initial Settings************************************************/
  2048. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  2049. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  2050. // allocate Configuration memory address
  2051. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  2052. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  2053. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  2054. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  2055. //offline MeterValue Interval
  2056. TempMeterValueInterval = 0;
  2057. return result;
  2058. }
  2059. int ProcessShareMemory()
  2060. {
  2061. if(InitShareMemory() == FAIL)
  2062. {
  2063. DEBUG_ERROR("InitShareMemory NG\n");
  2064. if(ShmStatusCodeData!=NULL)
  2065. {
  2066. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  2067. }
  2068. sleep(5);
  2069. return FAIL;
  2070. }
  2071. return PASS;
  2072. }
  2073. //---------------------common routine---------------------------//
  2074. //---------------------------------------------
  2075. // new:
  2076. // enum SYSTEM_STATUS
  2077. // {
  2078. // SYS_MODE_BOOTING = 0,
  2079. // SYS_MODE_IDLE = 1,
  2080. // SYS_MODE_AUTHORIZING = 2,
  2081. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  2082. // SYS_MODE_REASSIGN = 4,
  2083. // SYS_MODE_PREPARING = 5,
  2084. // SYS_MODE_PREPARE_FOR_EV = 6,
  2085. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  2086. // SYS_MODE_CHARGING = 8,
  2087. // SYS_MODE_TERMINATING = 9,
  2088. // SYS_MODE_COMPLETE = 10,
  2089. // SYS_MODE_ALARM = 11,
  2090. // SYS_MODE_FAULT = 12,
  2091. // SYS_MODE_RESERVATION = 13,
  2092. // SYS_MODE_BOOKING = 14,
  2093. // SYS_MODE_MAINTAIN = 15,
  2094. // SYS_MODE_DEBUG = 16,
  2095. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  2096. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  2097. // SYS_MODE_UPDATE = 19
  2098. // };
  2099. //
  2100. //
  2101. //-----------------------------------------
  2102. void CheckSystemValue(void)
  2103. {
  2104. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  2105. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  2106. char filenmae[100]={0};
  2107. char str[100]={0};
  2108. int tempIndex = 0;
  2109. //===============================
  2110. // send Heartbeat
  2111. //===============================
  2112. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2113. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  2114. {
  2115. clientTime.Heartbeat=time((time_t*)NULL);
  2116. if(server_sign == TRUE)
  2117. {
  2118. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2119. }
  2120. else
  2121. {
  2122. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  2123. }
  2124. }
  2125. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  2126. {
  2127. //parameter for test
  2128. sendHeartbeatRequest(0);
  2129. //==============================================
  2130. // Reset Waiting Time
  2131. //==============================================
  2132. HeartBeatWithNOResponse += 1;
  2133. }
  2134. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  2135. {
  2136. //==========================================
  2137. // csu trigger DataTransferReq
  2138. //==========================================
  2139. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  2140. {
  2141. sendDataTransferRequest(gun_index);
  2142. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  2143. }
  2144. //===============================
  2145. // CSU Trigger Reset Conf
  2146. //===============================
  2147. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  2148. {
  2149. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  2150. }
  2151. //===============================
  2152. // CSU Trigger Authorize Request
  2153. //===============================
  2154. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  2155. {
  2156. sendAuthorizeRequest(0);
  2157. authorizeRetryTimes = authorizeRetryTimes + 1;
  2158. if(authorizeRetryTimes < 3)
  2159. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2160. }
  2161. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  2162. {
  2163. authorizeRetryTimes = 0;
  2164. SetOcppConnStatus(FALSE);
  2165. server_sign = FALSE;
  2166. }
  2167. 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))
  2168. {
  2169. sendAuthorizeRequest(0);
  2170. }
  2171. //==============================================
  2172. // CSU Trigger Smart Charging Profilw
  2173. //==============================================
  2174. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  2175. {
  2176. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  2177. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  2178. }
  2179. //==============================================
  2180. // Charger start transaction
  2181. //==============================================
  2182. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2183. {
  2184. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  2185. sendStartTransactionRequest(gun_index);
  2186. clientTime.StartTransaction = time((time_t*)NULL);
  2187. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2188. storeTempStopTransaction(gun_index);
  2189. }
  2190. //==============================================
  2191. // Charger stop transaction
  2192. //==============================================
  2193. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2194. {
  2195. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2196. sendStopTransactionRequest(gun_index);
  2197. clientTime.StopTransaction = time((time_t*)NULL);
  2198. }
  2199. //==============================================
  2200. // Charger status report
  2201. //==============================================
  2202. //--- Check Mode Change ---//
  2203. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2204. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2205. {
  2206. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2207. {
  2208. tempIndex = ((gun_index==2) ? 1: 0);
  2209. }
  2210. else
  2211. {
  2212. tempIndex = gun_index;
  2213. }
  2214. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2215. {
  2216. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2217. {
  2218. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  2219. {
  2220. // Sent unplug message for California pricing logic
  2221. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  2222. {
  2223. uint8_t ts[20];
  2224. getNowDatetime(ts);
  2225. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2226. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2227. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2228. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2229. }
  2230. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2231. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2232. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2233. statusModeChage[gun_index] = TRUE;
  2234. }
  2235. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2236. {
  2237. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2238. if((access(filenmae,F_OK))!=-1)
  2239. {
  2240. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2241. sprintf(str,"rm -f %s",filenmae);
  2242. system(str);
  2243. }
  2244. }
  2245. #if 1 // for TempStopTransaction
  2246. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2247. {
  2248. checkTempStopTransaction(gun_index);
  2249. }
  2250. #endif
  2251. }
  2252. }
  2253. }
  2254. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2255. {
  2256. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2257. {
  2258. tempIndex = ((gun_index==2) ? 1: 0);
  2259. }
  2260. else
  2261. {
  2262. tempIndex = gun_index;
  2263. }
  2264. for (int index = 0; index < CCS_QUANTITY; index++)
  2265. {
  2266. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2267. {
  2268. 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]*/ )
  2269. {
  2270. // Sent unplug message for California pricing logic
  2271. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  2272. {
  2273. uint8_t ts[20];
  2274. getNowDatetime(ts);
  2275. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2276. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2277. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2278. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2279. }
  2280. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2281. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2282. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2283. statusModeChage[gun_index] = TRUE;
  2284. }
  2285. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2286. {
  2287. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2288. if((access(filenmae,F_OK))!=-1)
  2289. {
  2290. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2291. sprintf(str,"rm -f %s",filenmae);
  2292. system(str);
  2293. }
  2294. }
  2295. #if 1 // for TempStopTransaction
  2296. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2297. {
  2298. checkTempStopTransaction(gun_index);
  2299. }
  2300. #endif
  2301. }
  2302. }
  2303. }
  2304. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2305. {
  2306. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2307. {
  2308. tempIndex = ((gun_index==2) ? 1: 0);
  2309. }
  2310. else
  2311. {
  2312. tempIndex = gun_index;
  2313. }
  2314. for (int index = 0; index < GB_QUANTITY; index++)
  2315. {
  2316. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2317. {
  2318. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  2319. {
  2320. // Sent unplug message for California pricing logic
  2321. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  2322. {
  2323. uint8_t ts[20];
  2324. getNowDatetime(ts);
  2325. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2326. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2327. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2328. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2329. }
  2330. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2331. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2332. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2333. statusModeChage[gun_index] = TRUE;
  2334. }
  2335. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2336. {
  2337. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2338. if((access(filenmae,F_OK))!=-1)
  2339. {
  2340. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2341. sprintf(str,"rm -f %s",filenmae);
  2342. system(str);
  2343. }
  2344. }
  2345. #if 1 // for TempStopTransaction
  2346. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2347. {
  2348. checkTempStopTransaction(gun_index);
  2349. }
  2350. #endif
  2351. }
  2352. }
  2353. }
  2354. else if(gunType[gun_index] == GUN_TYPE_DO)
  2355. {
  2356. tempIndex = gun_index;
  2357. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2358. {
  2359. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2360. {
  2361. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  2362. {
  2363. // Sent unplug message for California pricing logic
  2364. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  2365. {
  2366. uint8_t ts[20];
  2367. getNowDatetime(ts);
  2368. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2369. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2370. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2371. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2372. }
  2373. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  2374. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  2375. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2376. statusModeChage[gun_index] = TRUE;
  2377. }
  2378. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARING))) // complete
  2379. {
  2380. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2381. if((access(filenmae,F_OK))!=-1)
  2382. {
  2383. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2384. sprintf(str,"rm -f %s",filenmae);
  2385. system(str);
  2386. }
  2387. }
  2388. #if 1 // for TempStopTransaction
  2389. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2390. {
  2391. checkTempStopTransaction(gun_index);
  2392. }
  2393. #endif
  2394. }
  2395. }
  2396. }
  2397. else
  2398. {
  2399. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2400. {
  2401. tempIndex = 2;
  2402. }
  2403. else
  2404. {
  2405. tempIndex = gun_index;
  2406. }
  2407. for (int index = 0; index < AC_QUANTITY; index++)
  2408. {
  2409. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2410. {
  2411. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  2412. {
  2413. // Sent unplug message for California pricing logic
  2414. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)
  2415. {
  2416. uint8_t ts[20];
  2417. getNowDatetime(ts);
  2418. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2419. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2420. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2421. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2422. }
  2423. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2424. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2425. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2426. statusModeChage[gun_index] = TRUE;
  2427. }
  2428. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2429. {
  2430. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2431. if((access(filenmae,F_OK))!=-1)
  2432. {
  2433. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2434. sprintf(str,"rm -f %s",filenmae);
  2435. system(str);
  2436. }
  2437. }
  2438. #if 1 // for TempStopTransaction
  2439. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2440. {
  2441. checkTempStopTransaction(gun_index);
  2442. }
  2443. #endif
  2444. }
  2445. }// END
  2446. }
  2447. if(isWebsocketSendable && (server_sign == TRUE) &&
  2448. (
  2449. (statusModeChage[gun_index] == TRUE) ||
  2450. //((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index))) ||
  2451. ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 10))
  2452. )
  2453. )
  2454. {
  2455. if(SystemInitial > 0)
  2456. SystemInitial -= 1;
  2457. sendStatusNotificationRequest(gun_index);
  2458. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2459. statusModeChage[gun_index] = FALSE;
  2460. }
  2461. //==============================================
  2462. // Meter report
  2463. //==============================================
  2464. // Trigger MeterValue
  2465. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  2466. {
  2467. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  2468. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  2469. }
  2470. // ClockAlign MeterValue
  2471. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  2472. {
  2473. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2474. {
  2475. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2476. {
  2477. tempIndex = ((gun_index==2) ? 1: 0);
  2478. }
  2479. else
  2480. {
  2481. tempIndex = gun_index;
  2482. }
  2483. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2484. {
  2485. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2486. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2487. {
  2488. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2489. {
  2490. reqClockAlignMeter[gun_index] = 1;
  2491. }
  2492. }
  2493. }// End for CHAdeMO
  2494. }
  2495. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2496. {
  2497. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2498. {
  2499. tempIndex = ((gun_index==2) ? 1: 0);
  2500. }
  2501. else
  2502. {
  2503. tempIndex = gun_index;
  2504. }
  2505. for (int index = 0; index < CCS_QUANTITY; index++)
  2506. {
  2507. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2508. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2509. {
  2510. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2511. {
  2512. reqClockAlignMeter[gun_index] = 1;
  2513. }
  2514. }
  2515. } // End for CCS
  2516. }
  2517. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2518. {
  2519. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2520. {
  2521. tempIndex = ((gun_index==2) ? 1: 0);
  2522. }
  2523. else
  2524. {
  2525. tempIndex = gun_index;
  2526. }
  2527. for (int index = 0; index < GB_QUANTITY; index++)
  2528. {
  2529. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2530. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2531. {
  2532. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2533. {
  2534. reqClockAlignMeter[gun_index] = 1;
  2535. }
  2536. }
  2537. }// End for GB
  2538. }
  2539. else if(gunType[gun_index] == GUN_TYPE_DO)
  2540. {
  2541. tempIndex = gun_index;
  2542. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2543. {
  2544. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2545. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2546. {
  2547. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_CHARGING)
  2548. {
  2549. reqClockAlignMeter[gun_index] = 1;
  2550. }
  2551. }
  2552. }
  2553. }
  2554. else
  2555. {
  2556. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2557. {
  2558. tempIndex = 2;
  2559. }
  2560. else
  2561. {
  2562. tempIndex = gun_index;
  2563. }
  2564. for (int index = 0; index < AC_QUANTITY; index++)
  2565. {
  2566. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2567. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2568. {
  2569. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2570. {
  2571. reqClockAlignMeter[gun_index] = 1;
  2572. }
  2573. }
  2574. }//End for AC
  2575. }
  2576. if(reqClockAlignMeter[gun_index] == 1)
  2577. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  2578. }
  2579. // Sample period MeterValue
  2580. if((((time((time_t*)NULL) - clientTime.MeterValues[gun_index]) > (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1))))
  2581. {
  2582. //check Transaction active
  2583. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2584. {
  2585. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2586. {
  2587. tempIndex = ((gun_index==2) ? 1: 0);
  2588. }
  2589. else
  2590. {
  2591. tempIndex = gun_index;
  2592. }
  2593. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2594. {
  2595. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2596. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2597. {
  2598. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2599. {
  2600. reqSampleMeter[gun_index] = 1;
  2601. }
  2602. }
  2603. }// End for CHAdeMO
  2604. }
  2605. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2606. {
  2607. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2608. {
  2609. tempIndex = ((gun_index==2) ? 1: 0);
  2610. }
  2611. else
  2612. {
  2613. tempIndex = gun_index;
  2614. }
  2615. for (int index = 0; index < CCS_QUANTITY; index++)
  2616. {
  2617. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2618. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2619. {
  2620. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2621. {
  2622. reqSampleMeter[gun_index] = 1;
  2623. }
  2624. }
  2625. } // End for CCS
  2626. }
  2627. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2628. {
  2629. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2630. {
  2631. tempIndex = ((gun_index==2) ? 1: 0);
  2632. }
  2633. else
  2634. {
  2635. tempIndex = gun_index;
  2636. }
  2637. for (int index = 0; index < GB_QUANTITY; index++)
  2638. {
  2639. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2640. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2641. {
  2642. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2643. {
  2644. reqSampleMeter[gun_index] = 1;
  2645. }
  2646. }
  2647. }// End for GB
  2648. }
  2649. else if(gunType[gun_index] == GUN_TYPE_DO)
  2650. {
  2651. tempIndex = gun_index;
  2652. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2653. {
  2654. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2655. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2656. {
  2657. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  2658. {
  2659. reqSampleMeter[gun_index] = 1;
  2660. }
  2661. }
  2662. }
  2663. }
  2664. else
  2665. {
  2666. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2667. {
  2668. tempIndex = 2;
  2669. }
  2670. else
  2671. {
  2672. tempIndex = gun_index;
  2673. }
  2674. for (int index = 0; index < AC_QUANTITY; index++)
  2675. {
  2676. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2677. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2678. {
  2679. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  2680. {
  2681. reqSampleMeter[gun_index] = 1;
  2682. }
  2683. }
  2684. }//End for AC
  2685. }
  2686. if(reqSampleMeter[gun_index] == 1)
  2687. {
  2688. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  2689. storeTempStopTransaction(gun_index);
  2690. }
  2691. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2692. }
  2693. //==============================================
  2694. // Check Connector reserved
  2695. //==============================================
  2696. //===============================
  2697. // Check if Reserve is expired
  2698. //===============================
  2699. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  2700. {
  2701. double diff_t;
  2702. struct tm tp;
  2703. // current time
  2704. time_t t = time(NULL);
  2705. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  2706. tp.tm_isdst = -1;
  2707. time_t utc = mktime(&tp);
  2708. diff_t = difftime(utc, t);
  2709. if(diff_t <= 0)
  2710. {
  2711. DEBUG_INFO("reserve expired.\n");
  2712. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  2713. }
  2714. }//END OF Check if Reserve is expired
  2715. //==========================================
  2716. // csu trigger FirmwareStatusNotificationReq
  2717. //==========================================
  2718. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  2719. {
  2720. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  2721. }
  2722. //==========================================
  2723. // csu trigger CancelReservationConf
  2724. //==========================================
  2725. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  2726. {
  2727. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  2728. }
  2729. //==========================================
  2730. // csu trigger ChangeAvailabilityConf
  2731. //==========================================
  2732. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  2733. {
  2734. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  2735. }
  2736. //==========================================
  2737. // csu trigger UnlockConnectorConf
  2738. //==========================================
  2739. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  2740. {
  2741. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  2742. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  2743. }
  2744. //==========================================
  2745. // csu trigger ReserveNowConf
  2746. //==========================================
  2747. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  2748. {
  2749. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  2750. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  2751. }
  2752. }
  2753. }
  2754. //==========================================
  2755. // send request routine
  2756. //==========================================
  2757. int sendAuthorizeRequest(int gun_index)
  2758. {
  2759. mtrace();
  2760. int result = FAIL;
  2761. char message[100]={0};
  2762. char guid[37];
  2763. char tempdata[65]={0};
  2764. DEBUG_INFO("sendAuthorizeRequest...\n");
  2765. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  2766. //Local Authorize
  2767. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  2768. {
  2769. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  2770. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2771. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  2772. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  2773. result = PASS;
  2774. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2775. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2776. authorizeRetryTimes = 0;
  2777. return result;
  2778. }
  2779. 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))||
  2780. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  2781. {
  2782. // Query from cache
  2783. DEBUG_INFO("Authorize from cache.\n");
  2784. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2785. // Query from list
  2786. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  2787. {
  2788. DEBUG_INFO("Authorize from list.\n");
  2789. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2790. }
  2791. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  2792. {
  2793. if(strcmp(idTagQuery.idTagstr,"") == 0)
  2794. {
  2795. DEBUG_INFO("off-line Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  2796. }
  2797. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  2798. {
  2799. DEBUG_INFO("off-line Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  2800. }
  2801. DEBUG_INFO("off-line Local Authorization Fail !!!!\n");
  2802. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2803. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2804. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  2805. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  2806. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2807. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2808. authorizeRetryTimes = 0;
  2809. return result;
  2810. }
  2811. else
  2812. {
  2813. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  2814. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  2815. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2816. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  2817. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  2818. else
  2819. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  2820. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  2821. result = PASS;
  2822. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2823. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2824. authorizeRetryTimes = 0;
  2825. return result;
  2826. }
  2827. }
  2828. //initialize struct Authorize
  2829. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  2830. //get data from shared memory
  2831. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2832. random_uuid(guid);
  2833. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  2834. LWS_Send(message);
  2835. sprintf(tempdata, "Authorize,%d", gun_index);
  2836. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2837. {
  2838. result = PASS;
  2839. DEBUG_INFO("Authorize mapItem pass\n");
  2840. }
  2841. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2842. return result;
  2843. }
  2844. int sendBootNotificationRequest(void)
  2845. {
  2846. mtrace();
  2847. int result = FAIL;
  2848. char message[500]={0}, payload[700]={0};
  2849. char guid[37]={0};
  2850. char tempdata[65]={0};
  2851. // Fill BootNotification fields
  2852. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  2853. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  2854. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  2855. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2856. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  2857. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  2858. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  2859. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  2860. ShmOCPP16Data->ChargeBoxId
  2861. ,ShmSysConfigAndInfo->SysConfig.ModelName
  2862. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  2863. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  2864. ,ShmOCPP16Data->BootNotification.CpFwVersion
  2865. ,ShmOCPP16Data->BootNotification.CpIccid
  2866. ,ShmOCPP16Data->BootNotification.CpImsi);
  2867. random_uuid(guid);
  2868. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  2869. LWS_Send(message);
  2870. sprintf(tempdata, "BootNotification,0");
  2871. 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*/)
  2872. {
  2873. result = PASS;
  2874. }
  2875. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  2876. strcpy(queuedata,message);
  2877. return result;
  2878. }
  2879. int sendDataTransferRequest(int gun_index)
  2880. {
  2881. mtrace();
  2882. char message[1000]={0};
  2883. char guid[37]={0};
  2884. char tempdata[65]={0};
  2885. int result = FAIL;
  2886. random_uuid(guid);
  2887. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  2888. MESSAGE_TYPE_CALL,
  2889. guid,
  2890. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  2891. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  2892. ShmOCPP16Data->DataTransfer[gun_index].Data);
  2893. LWS_Send(message);
  2894. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  2895. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2896. {
  2897. result = PASS;
  2898. DEBUG_INFO("DataTransfer mapItem pass\n");
  2899. }
  2900. return result;
  2901. }
  2902. int sendDiagnosticsStatusNotificationRequest(char *status)
  2903. {
  2904. mtrace();
  2905. int result = FAIL;
  2906. char message[110]={0};
  2907. char guid[37]={0};
  2908. char tempdata[65]={0};
  2909. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  2910. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  2911. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  2912. random_uuid(guid);
  2913. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  2914. LWS_SendNow(message);
  2915. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  2916. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2917. {
  2918. result = PASS;
  2919. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  2920. }
  2921. //#ifdef SystemLogMessage
  2922. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  2923. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2924. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  2925. //#endif
  2926. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  2927. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  2928. //record status
  2929. if(strcmp(status,"Idle")==0)
  2930. {
  2931. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  2932. }
  2933. else if(strcmp(status,"Uploaded")==0)
  2934. {
  2935. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  2936. }
  2937. else if(strcmp(status,"UploadFailed")==0)
  2938. {
  2939. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  2940. }
  2941. else if(strcmp(status,"Uploading")==0)
  2942. {
  2943. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  2944. }
  2945. return result;
  2946. }
  2947. int sendFirmwareStatusNotificationRequest(char *status)
  2948. {
  2949. mtrace();
  2950. int result = FAIL;
  2951. char message[110]={0};
  2952. char guid[37]={0};
  2953. char tempdata[65]={0};
  2954. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  2955. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  2956. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  2957. random_uuid(guid);
  2958. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  2959. LWS_SendNow(message);
  2960. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  2961. 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*/)
  2962. {
  2963. result = PASS;
  2964. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  2965. }
  2966. //#ifdef SystemLogMessage
  2967. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  2968. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2969. //#endif
  2970. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  2971. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  2972. //record status
  2973. if(strcmp(status,"Downloaded")==0)
  2974. {
  2975. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  2976. }
  2977. else if(strcmp(status,"DownloadFailed")==0)
  2978. {
  2979. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  2980. }
  2981. else if(strcmp(status,"Downloading")==0)
  2982. {
  2983. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  2984. }
  2985. else if(strcmp(status,"Idle")==0)
  2986. {
  2987. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  2988. }
  2989. else if(strcmp(status,"InstallationFailed")==0)
  2990. {
  2991. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  2992. }
  2993. else if(strcmp(status,"Installing")==0)
  2994. {
  2995. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  2996. }
  2997. else if(strcmp(status,"Installed")==0)
  2998. {
  2999. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  3000. }
  3001. return result;
  3002. }
  3003. int sendHeartbeatRequest(int gun_index)
  3004. {
  3005. mtrace();
  3006. int result = FAIL;
  3007. char message[80]={0};
  3008. char guid[37]={0};
  3009. char tempdata[65]={0};
  3010. random_uuid(guid);
  3011. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  3012. , MESSAGE_TYPE_CALL
  3013. , guid );
  3014. LWS_Send(message);
  3015. sprintf(tempdata, "Heartbeat,%d", 0);
  3016. 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*/)
  3017. {
  3018. result = PASS;
  3019. }
  3020. return result;
  3021. }
  3022. int sendStartTransactionRequest(int gun_index)
  3023. {
  3024. mtrace();
  3025. int result = FAIL;
  3026. char message[250]={0};
  3027. char guid[37]={0};
  3028. struct timeval tmnow;
  3029. struct tm *tm;
  3030. char buf[28];//, usec_buf[6];
  3031. char tempdata[65]={0};
  3032. int tempIndex = 0;
  3033. DEBUG_INFO("sendStartTransactionRequest...\n");
  3034. gettimeofday(&tmnow, NULL);
  3035. time_t t;
  3036. t = time(NULL);
  3037. /*UTC time and date*/
  3038. tm = gmtime(&t);
  3039. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3040. #if 0 // remove temporally
  3041. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3042. strcat(buf,".");
  3043. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3044. strcat(buf,usec_buf);
  3045. #endif
  3046. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  3047. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  3048. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3049. // clear StartTransaction Response
  3050. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  3051. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  3052. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  3053. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  3054. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3055. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3056. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3057. {
  3058. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3059. {
  3060. tempIndex = ((gun_index==2) ? 1: 0);
  3061. }
  3062. else
  3063. {
  3064. tempIndex = gun_index;
  3065. }
  3066. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3067. {
  3068. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3069. {
  3070. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3071. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  3072. }
  3073. }
  3074. }
  3075. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3076. {
  3077. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3078. {
  3079. tempIndex = ((gun_index==2) ? 1: 0);
  3080. }
  3081. else
  3082. {
  3083. tempIndex = gun_index;
  3084. }
  3085. for (int index = 0; index < CCS_QUANTITY; index++)
  3086. {
  3087. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3088. {
  3089. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3090. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  3091. }
  3092. }
  3093. }
  3094. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3095. {
  3096. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3097. {
  3098. tempIndex = ((gun_index==2) ? 1: 0);
  3099. }
  3100. else
  3101. {
  3102. tempIndex = gun_index;
  3103. }
  3104. for (int index = 0; index < GB_QUANTITY; index++)
  3105. {
  3106. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3107. {
  3108. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3109. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  3110. }
  3111. }
  3112. }
  3113. else if(gunType[gun_index] == GUN_TYPE_DO)
  3114. {
  3115. tempIndex = gun_index;
  3116. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3117. {
  3118. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3119. {
  3120. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3121. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  3122. }
  3123. }
  3124. }
  3125. else
  3126. {
  3127. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3128. {
  3129. tempIndex = 2;
  3130. }
  3131. else
  3132. {
  3133. tempIndex = gun_index;
  3134. }
  3135. for (int index = 0; index < AC_QUANTITY; index++)
  3136. {
  3137. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3138. {
  3139. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3140. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  3141. }
  3142. }
  3143. }
  3144. random_uuid(guid);
  3145. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  3146. {
  3147. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  3148. , gun_index +1
  3149. , MESSAGE_TYPE_CALL
  3150. , guid
  3151. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3152. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3153. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3154. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3155. }
  3156. else
  3157. {
  3158. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  3159. , gun_index +1
  3160. , MESSAGE_TYPE_CALL
  3161. , guid
  3162. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3163. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3164. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3165. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  3166. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3167. }
  3168. #if 1
  3169. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  3170. 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*/)
  3171. {
  3172. result = PASS;
  3173. }
  3174. #endif
  3175. strcpy(queuedata, message);
  3176. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3177. return result;
  3178. }
  3179. int sendStatusNotificationRequest(int gun_index)
  3180. {
  3181. mtrace();
  3182. int result = FAIL;
  3183. char message[600]={0};
  3184. char guid[37];
  3185. int currentStatus = 0;
  3186. struct timeval tmnow;
  3187. struct tm *tm;
  3188. char buf[28];//, usec_buf[6];
  3189. char tempdata[65]={0};
  3190. int tempIndex = 0;
  3191. DEBUG_INFO("sendStatusNotificationRequest...\n");
  3192. gettimeofday(&tmnow, NULL);
  3193. time_t t;
  3194. t = time(NULL);
  3195. /*UTC time and date*/
  3196. tm = gmtime(&t);
  3197. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3198. #if 0 // remove temporally
  3199. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3200. strcat(buf,".");
  3201. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3202. strcat(buf,usec_buf);
  3203. #endif
  3204. printf("%s",buf);
  3205. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  3206. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  3207. // it's option
  3208. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  3209. /*
  3210. enum _SYSTEM_STATUS
  3211. {
  3212. S_BOOTING = 0,
  3213. S_IDLE, = 1
  3214. S_AUTHORIZING, =2
  3215. S_REASSIGN_CHECK, =3
  3216. S_REASSIGN, =4
  3217. S_PRECHARGE, =5
  3218. S_PREPARING_FOR_EV, =6
  3219. S_PREPARING_FOR_EVSE, =7
  3220. S_CHARGING, =8
  3221. S_TERMINATING, =9
  3222. S_COMPLETE, =10
  3223. S_ALARM, =11
  3224. S_FAULT =12
  3225. }
  3226. */
  3227. //check Transaction active
  3228. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3229. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3230. {
  3231. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3232. {
  3233. tempIndex = ((gun_index==2) ? 1: 0);
  3234. }
  3235. else
  3236. {
  3237. tempIndex = gun_index;
  3238. }
  3239. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3240. {
  3241. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  3242. {
  3243. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  3244. {
  3245. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3246. {
  3247. currentStatus = Preparing; //OCPP Status: Preparing
  3248. }
  3249. else
  3250. {
  3251. currentStatus = Available; //OCPP Status: Available
  3252. }
  3253. }
  3254. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3255. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3256. ) //S_PRECHARGE
  3257. {
  3258. currentStatus = Preparing; //OCPP Status: Preparing
  3259. }
  3260. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3261. {
  3262. currentStatus = Charging; //OCPP Status: Charging
  3263. }
  3264. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3265. {
  3266. currentStatus = Finishing; //OCPP Status: Finishing
  3267. }
  3268. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3269. {
  3270. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3271. }
  3272. 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
  3273. {
  3274. currentStatus = Unavailable; //OCPP Status: Unavailable
  3275. }
  3276. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3277. {
  3278. currentStatus = Faulted; //OCPP Status: Faulted
  3279. }
  3280. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3281. {
  3282. currentStatus = Reserved; //OCPP Status: Reserved
  3283. }
  3284. } //end of the same index
  3285. }//end of for CHAdeMO_QUANTITY
  3286. }
  3287. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3288. {
  3289. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3290. {
  3291. tempIndex = ((gun_index==2) ? 1: 0);
  3292. }
  3293. else
  3294. {
  3295. tempIndex = gun_index;
  3296. }
  3297. for (int index = 0; index < CCS_QUANTITY; index++)
  3298. {
  3299. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3300. {
  3301. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3302. {
  3303. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3304. {
  3305. currentStatus = Preparing; //OCPP Status: Preparing
  3306. }
  3307. else
  3308. {
  3309. currentStatus = Available; //OCPP Status: Available
  3310. }
  3311. }
  3312. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3313. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3314. ) //S_PRECHARGE
  3315. {
  3316. currentStatus = Preparing; //OCPP Status: Preparing
  3317. }
  3318. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3319. {
  3320. currentStatus = Charging; //OCPP Status: Charging
  3321. }
  3322. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3323. {
  3324. currentStatus = Finishing; //OCPP Status: Finishing
  3325. }
  3326. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3327. {
  3328. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3329. }
  3330. 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
  3331. {
  3332. currentStatus = Unavailable; //OCPP Status : Unavailable
  3333. }
  3334. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3335. {
  3336. currentStatus = Faulted; //OCPP Status: Faulted
  3337. }
  3338. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3339. {
  3340. currentStatus = Reserved; //OCPP Status: Reserved
  3341. }
  3342. } //end of the same index
  3343. } // end of for CCS_QUANTITY
  3344. }
  3345. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3346. {
  3347. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3348. {
  3349. tempIndex = ((gun_index==2) ? 1: 0);
  3350. }
  3351. else
  3352. {
  3353. tempIndex = gun_index;
  3354. }
  3355. for (int index = 0; index < GB_QUANTITY; index++)
  3356. {
  3357. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3358. {
  3359. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3360. {
  3361. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3362. {
  3363. currentStatus = Preparing; //OCPP Status: Preparing
  3364. }
  3365. else
  3366. {
  3367. currentStatus = Available; //OCPP Status: Available
  3368. }
  3369. }
  3370. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3371. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3372. ) //S_PRECHARGE
  3373. {
  3374. currentStatus = Preparing; //OCPP Status: Preparing
  3375. }
  3376. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3377. {
  3378. currentStatus = Charging; //OCPP Status: Charging
  3379. }
  3380. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3381. {
  3382. currentStatus = Finishing; //OCPP Status: Finishing
  3383. }
  3384. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3385. {
  3386. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3387. }
  3388. 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
  3389. {
  3390. currentStatus = Unavailable; //OCPP Status: Unavailable
  3391. }
  3392. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3393. {
  3394. currentStatus = Faulted; //OCPP Status: Faulted
  3395. }
  3396. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3397. {
  3398. currentStatus = Reserved; //OCPP Status: Reserved
  3399. }
  3400. } //end of the same index
  3401. } // end of for GB_QUANTITY
  3402. }
  3403. else if(gunType[gun_index] == GUN_TYPE_DO)
  3404. {
  3405. tempIndex = gun_index;
  3406. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3407. {
  3408. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3409. {
  3410. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3411. {
  3412. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3413. {
  3414. currentStatus = Preparing; //OCPP Status: Preparing
  3415. }
  3416. else
  3417. {
  3418. currentStatus = Available; //OCPP Status: Available
  3419. }
  3420. }
  3421. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3422. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3423. ) //S_PRECHARGE
  3424. {
  3425. currentStatus = Preparing; //OCPP Status: Preparing
  3426. }
  3427. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3428. {
  3429. currentStatus = Charging; //OCPP Status: Charging
  3430. }
  3431. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3432. {
  3433. currentStatus = Finishing; //OCPP Status: Finishing
  3434. }
  3435. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3436. {
  3437. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3438. }
  3439. 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
  3440. {
  3441. currentStatus = Unavailable; //OCPP Status: Unavailable
  3442. }
  3443. 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
  3444. {
  3445. currentStatus = Faulted; //OCPP Status: Faulted
  3446. }
  3447. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3448. {
  3449. currentStatus = Reserved; //OCPP Status: Reserved
  3450. }
  3451. } //end of the same index
  3452. }
  3453. }
  3454. else
  3455. {
  3456. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3457. {
  3458. tempIndex = 2;
  3459. }
  3460. else
  3461. {
  3462. tempIndex = gun_index;
  3463. }
  3464. for (int index = 0; index < AC_QUANTITY; index++)
  3465. {
  3466. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3467. {
  3468. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3469. {
  3470. 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))
  3471. {
  3472. currentStatus = Preparing; //OCPP Status: Preparing
  3473. }
  3474. else
  3475. {
  3476. currentStatus = Available; //OCPP Status: Available
  3477. }
  3478. }
  3479. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  3480. {
  3481. currentStatus = Preparing; //OCPP Status: Preparing
  3482. }
  3483. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3484. {
  3485. currentStatus = Charging; //OCPP Status: Charging
  3486. }
  3487. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3488. {
  3489. currentStatus = Finishing; //OCPP Status: Finishing
  3490. }
  3491. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3492. {
  3493. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3494. }
  3495. 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
  3496. {
  3497. currentStatus = Unavailable; //OCPP Status: Unavailable
  3498. }
  3499. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3500. {
  3501. currentStatus = Faulted; //OCPP Status: Faulted
  3502. }
  3503. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3504. {
  3505. currentStatus = Reserved; //OCPP Status: Reserved
  3506. }
  3507. }//end of the same index
  3508. }//end of for AC_QUANTITY
  3509. }
  3510. //it's option
  3511. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3512. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3513. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3514. random_uuid(guid);
  3515. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3516. , MESSAGE_TYPE_CALL
  3517. , guid
  3518. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3519. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3520. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3521. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3522. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3523. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3524. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3525. if((server_sign == TRUE))
  3526. {
  3527. LWS_Send(message);
  3528. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3529. 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*/)
  3530. {
  3531. //DEBUG_ERROR("statusNotification mapitem pass");
  3532. result = PASS;
  3533. }
  3534. }
  3535. else
  3536. {
  3537. result = PASS;
  3538. }
  3539. return result;
  3540. }
  3541. int sendStopTransactionRequest(int gun_index)
  3542. {
  3543. mtrace();
  3544. int result = FAIL;
  3545. //char message[1500]={0};
  3546. char guid[37]={0};
  3547. char tempdata[65]={0};
  3548. int tempIndex = 0;
  3549. char TempStopTransaction[256];
  3550. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  3551. //int idx_sample=0;
  3552. DEBUG_INFO("sendStopTransactionRequest \n");
  3553. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3554. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  3555. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  3556. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3557. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3558. {
  3559. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3560. {
  3561. tempIndex = ((gun_index==2) ? 1: 0);
  3562. }
  3563. else
  3564. {
  3565. tempIndex = gun_index;
  3566. }
  3567. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3568. {
  3569. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3570. {
  3571. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3572. }
  3573. }// END OF CHAdeMO_QUANTITY
  3574. }
  3575. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3576. {
  3577. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3578. {
  3579. tempIndex = ((gun_index==2) ? 1: 0);
  3580. }
  3581. else
  3582. {
  3583. tempIndex = gun_index;
  3584. }
  3585. for (int index = 0; index < CCS_QUANTITY; index++)
  3586. {
  3587. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3588. {
  3589. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3590. }
  3591. }// END OF CCS_QUANTITY
  3592. }
  3593. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3594. {
  3595. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3596. {
  3597. tempIndex = ((gun_index==2) ? 1: 0);
  3598. }
  3599. else
  3600. {
  3601. tempIndex = gun_index;
  3602. }
  3603. for (int index = 0; index < GB_QUANTITY; index++)
  3604. {
  3605. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3606. {
  3607. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3608. }
  3609. }// END OF GB_QUANTITY
  3610. }
  3611. else if(gunType[gun_index] == GUN_TYPE_DO)
  3612. {
  3613. tempIndex = gun_index;
  3614. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3615. {
  3616. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3617. {
  3618. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3619. }
  3620. }// END OF GB_QUANTITY
  3621. }
  3622. else
  3623. {
  3624. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3625. {
  3626. tempIndex = 2;
  3627. }
  3628. else
  3629. {
  3630. tempIndex = gun_index;
  3631. }
  3632. for (int index = 0; index < AC_QUANTITY; index++)
  3633. {
  3634. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3635. {
  3636. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3637. }
  3638. }// END OF AC_QUANTITY
  3639. }
  3640. //====================================== Stop Transaction Time =====================================================
  3641. struct timeval tmnow;
  3642. struct tm *tm;
  3643. char buf[28];//, usec_buf[6];
  3644. gettimeofday(&tmnow, NULL);
  3645. time_t t;
  3646. t = time(NULL);
  3647. /*UTC time and date*/
  3648. tm = gmtime(&t);
  3649. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3650. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  3651. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  3652. random_uuid(guid);
  3653. /***********************************transactionData******************************************************/
  3654. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  3655. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  3656. //=================================
  3657. // Transaction_Begin
  3658. //=================================
  3659. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  3660. {
  3661. //============================================ Energy.Active.Import.Interval ================================
  3662. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  3663. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  3664. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  3665. 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*/]);
  3666. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3667. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  3668. {
  3669. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  3670. }
  3671. else
  3672. {
  3673. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  3674. }
  3675. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  3676. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3677. }
  3678. //=================================
  3679. // Transaction_End
  3680. //=================================
  3681. // ================================= Current.Import L1 ===============================================
  3682. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  3683. {
  3684. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  3685. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3686. {
  3687. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3688. {
  3689. tempIndex = ((gun_index==2) ? 1: 0);
  3690. }
  3691. else
  3692. {
  3693. tempIndex = gun_index;
  3694. }
  3695. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3696. {
  3697. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3698. {
  3699. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3700. }
  3701. }// End of for CHAdeMO_QUANTITY
  3702. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3703. }
  3704. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3705. {
  3706. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3707. {
  3708. tempIndex = ((gun_index==2) ? 1: 0);
  3709. }
  3710. else
  3711. {
  3712. tempIndex = gun_index;
  3713. }
  3714. for (int index = 0; index < CCS_QUANTITY; index++)
  3715. {
  3716. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3717. {
  3718. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3719. }
  3720. }// End of for CCS_QUANTITY
  3721. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3722. }
  3723. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3724. {
  3725. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3726. {
  3727. tempIndex = ((gun_index==2) ? 1: 0);
  3728. }
  3729. else
  3730. {
  3731. tempIndex = gun_index;
  3732. }
  3733. for (int index = 0; index < GB_QUANTITY; index++)
  3734. {
  3735. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3736. {
  3737. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3738. }
  3739. }// End of for GB_QUANTITY
  3740. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3741. }
  3742. else if(gunType[gun_index] == GUN_TYPE_DO)
  3743. {
  3744. tempIndex = gun_index;
  3745. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3746. {
  3747. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3748. {
  3749. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3750. }
  3751. }
  3752. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3753. }
  3754. else
  3755. {
  3756. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3757. {
  3758. tempIndex = 2;
  3759. }
  3760. else
  3761. {
  3762. tempIndex = gun_index;
  3763. }
  3764. for (int index = 0; index < AC_QUANTITY; index++)
  3765. {
  3766. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3767. {
  3768. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  3769. }
  3770. }// End of for AC_QUANTITY
  3771. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  3772. }
  3773. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3774. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  3775. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  3776. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  3777. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3778. }
  3779. // ================================= Energy.Active.Import.Interval ==============================================
  3780. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  3781. {
  3782. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3783. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3784. {
  3785. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3786. {
  3787. tempIndex = ((gun_index==2) ? 1: 0);
  3788. }
  3789. else
  3790. {
  3791. tempIndex = gun_index;
  3792. }
  3793. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3794. {
  3795. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3796. {
  3797. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3798. }
  3799. }// END OF CHAdeMO_QUANTITY
  3800. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3801. }
  3802. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3803. {
  3804. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3805. {
  3806. tempIndex = ((gun_index==2) ? 1: 0);
  3807. }
  3808. else
  3809. {
  3810. tempIndex = gun_index;
  3811. }
  3812. for (int index = 0; index < CCS_QUANTITY; index++)
  3813. {
  3814. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3815. {
  3816. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3817. }
  3818. }// END OF CCS_QUANTITY
  3819. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3820. }
  3821. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3822. {
  3823. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3824. {
  3825. tempIndex = ((gun_index==2) ? 1: 0);
  3826. }
  3827. else
  3828. {
  3829. tempIndex = gun_index;
  3830. }
  3831. for (int index = 0; index < GB_QUANTITY; index++)
  3832. {
  3833. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3834. {
  3835. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3836. }
  3837. }// END OF GB_QUANTITY
  3838. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3839. }
  3840. else if(gunType[gun_index] == GUN_TYPE_DO)
  3841. {
  3842. tempIndex = gun_index;
  3843. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3844. {
  3845. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3846. {
  3847. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3848. }
  3849. }
  3850. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3851. }
  3852. else
  3853. {
  3854. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3855. {
  3856. tempIndex = 2;
  3857. }
  3858. else
  3859. {
  3860. tempIndex = gun_index;
  3861. }
  3862. for (int index = 0; index < AC_QUANTITY; index++)
  3863. {
  3864. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3865. {
  3866. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3867. }
  3868. }// END OF AC_QUANTITY
  3869. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  3870. }
  3871. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3872. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  3873. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  3874. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  3875. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3876. }
  3877. //=================================== Power.Active.Import ==================================================
  3878. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  3879. {
  3880. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3881. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3882. {
  3883. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3884. {
  3885. tempIndex = ((gun_index==2) ? 1: 0);
  3886. }
  3887. else
  3888. {
  3889. tempIndex = gun_index;
  3890. }
  3891. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3892. {
  3893. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3894. {
  3895. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3896. }
  3897. } // End for CHAdeMO_QUANTITY
  3898. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3899. }
  3900. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3901. {
  3902. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3903. {
  3904. tempIndex = ((gun_index==2) ? 1: 0);
  3905. }
  3906. else
  3907. {
  3908. tempIndex = gun_index;
  3909. }
  3910. for (int index = 0; index < CCS_QUANTITY; index++)
  3911. {
  3912. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3913. {
  3914. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3915. }
  3916. } // END for CCS_QUANTITY
  3917. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3918. }
  3919. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3920. {
  3921. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3922. {
  3923. tempIndex = ((gun_index==2) ? 1: 0);
  3924. }
  3925. else
  3926. {
  3927. tempIndex = gun_index;
  3928. }
  3929. for (int index = 0; index < GB_QUANTITY; index++)
  3930. {
  3931. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3932. {
  3933. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3934. }
  3935. }// END for GB_QUANTITY
  3936. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3937. }
  3938. else if(gunType[gun_index] == GUN_TYPE_DO)
  3939. {
  3940. tempIndex = gun_index;
  3941. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3942. {
  3943. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3944. {
  3945. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3946. }
  3947. }
  3948. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3949. }
  3950. else
  3951. {
  3952. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3953. {
  3954. tempIndex = 2;
  3955. }
  3956. else
  3957. {
  3958. tempIndex = gun_index;
  3959. }
  3960. for (int index = 0; index < AC_QUANTITY; index++)
  3961. {
  3962. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3963. {
  3964. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3965. }
  3966. } // END for AC_QUANTITY
  3967. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  3968. }
  3969. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3970. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  3971. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  3972. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  3973. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  3974. }
  3975. //============================ Voltage L1 ====================================
  3976. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  3977. {
  3978. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3979. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3980. {
  3981. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3982. {
  3983. tempIndex = ((gun_index==2) ? 1: 0);
  3984. }
  3985. else
  3986. {
  3987. tempIndex = gun_index;
  3988. }
  3989. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3990. {
  3991. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3992. {
  3993. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3994. }
  3995. } // END OF FOR CHAdeMO_QUANTITY
  3996. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3997. }
  3998. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3999. {
  4000. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4001. {
  4002. tempIndex = ((gun_index==2) ? 1: 0);
  4003. }
  4004. else
  4005. {
  4006. tempIndex = gun_index;
  4007. }
  4008. for (int index = 0; index < CCS_QUANTITY; index++)
  4009. {
  4010. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4011. {
  4012. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4013. }
  4014. } // END OF FOR CCS_QUANTITY
  4015. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4016. }
  4017. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4018. {
  4019. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4020. {
  4021. tempIndex = ((gun_index==2) ? 1: 0);
  4022. }
  4023. else
  4024. {
  4025. tempIndex = gun_index;
  4026. }
  4027. for (int index = 0; index < GB_QUANTITY; index++)
  4028. {
  4029. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4030. {
  4031. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4032. }
  4033. } // END OF FOR GB_QUANTITY
  4034. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4035. }
  4036. else if(gunType[gun_index] == GUN_TYPE_DO)
  4037. {
  4038. tempIndex = gun_index;
  4039. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4040. {
  4041. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4042. {
  4043. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4044. }
  4045. }
  4046. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4047. }
  4048. else
  4049. {
  4050. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4051. {
  4052. tempIndex = 2;
  4053. }
  4054. else
  4055. {
  4056. tempIndex = gun_index;
  4057. }
  4058. for (int index = 0; index < AC_QUANTITY; index++)
  4059. {
  4060. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4061. {
  4062. 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
  4063. }
  4064. } // END OF FOR AC_QUANTITY
  4065. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  4066. }
  4067. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4068. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  4069. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  4070. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  4071. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4072. }
  4073. //====================== End SoC ================================
  4074. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4075. {
  4076. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4077. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  4078. {
  4079. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4080. {
  4081. tempIndex = ((gun_index==2) ? 1: 0);
  4082. }
  4083. else
  4084. {
  4085. tempIndex = gun_index;
  4086. }
  4087. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4088. {
  4089. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4090. {
  4091. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4092. {
  4093. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  4094. }
  4095. }
  4096. }
  4097. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4098. {
  4099. for (int index = 0; index < CCS_QUANTITY; index++)
  4100. {
  4101. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4102. {
  4103. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  4104. }
  4105. }
  4106. }
  4107. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4108. {
  4109. for (int index = 0; index < GB_QUANTITY; index++)
  4110. {
  4111. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4112. {
  4113. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  4114. }
  4115. }
  4116. }
  4117. else if(gunType[gun_index] == GUN_TYPE_DO)
  4118. {
  4119. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4120. {
  4121. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4122. {
  4123. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  4124. }
  4125. }
  4126. }
  4127. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4128. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  4129. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4130. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  4131. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  4132. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4133. } // END FOR DC CASE
  4134. }
  4135. // ================================= Current.Import L2 ===============================================
  4136. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4137. {
  4138. // AC 3 phse L2 current
  4139. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4140. {
  4141. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4142. {
  4143. tempIndex = 2;
  4144. }
  4145. else
  4146. {
  4147. tempIndex = gun_index;
  4148. }
  4149. for (int index = 0; index < AC_QUANTITY; index++)
  4150. {
  4151. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4152. {
  4153. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  4154. }
  4155. }// End of for AC_QUANTITY
  4156. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  4157. }
  4158. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4159. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  4160. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  4161. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  4162. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4163. }
  4164. // ================================= Current.Import L3 ===============================================
  4165. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4166. {
  4167. // AC 3 phse L3 current
  4168. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4169. {
  4170. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4171. {
  4172. tempIndex = 2;
  4173. }
  4174. else
  4175. {
  4176. tempIndex = gun_index;
  4177. }
  4178. for (int index = 0; index < AC_QUANTITY; index++)
  4179. {
  4180. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4181. {
  4182. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  4183. }
  4184. }// End of for AC_QUANTITY
  4185. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  4186. }
  4187. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4188. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  4189. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  4190. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  4191. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4192. }
  4193. //============================ Voltage L2 ====================================
  4194. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4195. {
  4196. // AC 3 phse L2 voltage
  4197. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4198. {
  4199. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4200. {
  4201. tempIndex = 2;
  4202. }
  4203. else
  4204. {
  4205. tempIndex = gun_index;
  4206. }
  4207. for (int index = 0; index < AC_QUANTITY; index++)
  4208. {
  4209. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4210. {
  4211. 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
  4212. }
  4213. } // END OF FOR AC_QUANTITY
  4214. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  4215. }
  4216. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4217. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  4218. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  4219. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  4220. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4221. }
  4222. //============================ Voltage L3 ====================================
  4223. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4224. {
  4225. // AC 3 phse L3 voltage
  4226. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4227. {
  4228. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4229. {
  4230. tempIndex = 2;
  4231. }
  4232. else
  4233. {
  4234. tempIndex = gun_index;
  4235. }
  4236. for (int index = 0; index < AC_QUANTITY; index++)
  4237. {
  4238. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4239. {
  4240. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  4241. }
  4242. } // END OF FOR AC_QUANTITY
  4243. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  4244. }
  4245. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4246. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  4247. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  4248. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  4249. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4250. }
  4251. //====================== Start SoC ================================
  4252. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4253. {
  4254. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4255. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  4256. {
  4257. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4258. {
  4259. tempIndex = ((gun_index==2) ? 1: 0);
  4260. }
  4261. else
  4262. {
  4263. tempIndex = gun_index;
  4264. }
  4265. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4266. {
  4267. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4268. {
  4269. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4270. {
  4271. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  4272. }
  4273. }
  4274. }
  4275. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4276. {
  4277. for (int index = 0; index < CCS_QUANTITY; index++)
  4278. {
  4279. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4280. {
  4281. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  4282. }
  4283. }
  4284. }
  4285. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4286. {
  4287. for (int index = 0; index < GB_QUANTITY; index++)
  4288. {
  4289. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4290. {
  4291. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  4292. }
  4293. }
  4294. }
  4295. else if(gunType[gun_index] == GUN_TYPE_DO)
  4296. {
  4297. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4298. {
  4299. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4300. {
  4301. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  4302. }
  4303. }
  4304. }
  4305. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4306. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  4307. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4308. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  4309. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  4310. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4311. } // END FOR DC CASE
  4312. }
  4313. //================================================ Message create ====================================================
  4314. json_object *StopTransaction = json_object_new_object();
  4315. json_object *transactionDatas = json_object_new_array();
  4316. json_object *sampledValues = json_object_new_array();
  4317. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  4318. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  4319. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  4320. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  4321. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  4322. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  4323. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  4324. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  4325. {
  4326. json_object *transactionData = json_object_new_object();
  4327. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  4328. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  4329. {
  4330. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  4331. {
  4332. json_object *sampledValue = json_object_new_object();
  4333. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  4334. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  4335. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  4336. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  4337. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  4338. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  4339. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  4340. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  4341. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  4342. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  4343. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  4344. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  4345. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  4346. json_object_array_add(sampledValues, sampledValue);
  4347. }
  4348. }
  4349. json_object_object_add(transactionData, "sampledValue", sampledValues);
  4350. json_object_array_add(transactionDatas, transactionData);
  4351. }
  4352. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  4353. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  4354. ,MESSAGE_TYPE_CALL
  4355. ,guid
  4356. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  4357. json_object_put(StopTransaction);
  4358. #if 1 // for TempStopTransaction
  4359. //Delete TempStopTransaction
  4360. if((access(TempStopTransaction,F_OK))!=-1)
  4361. {
  4362. remove(TempStopTransaction); // remove file "TempStopTransaction"
  4363. }
  4364. #endif
  4365. #if 1
  4366. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4367. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4368. {
  4369. result = PASS;
  4370. //DEBUG_INFO("StopTransaction mapitem pass\n");
  4371. }
  4372. #endif
  4373. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4374. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4375. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  4376. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  4377. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4378. {
  4379. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  4380. }
  4381. //for test
  4382. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4383. return result;
  4384. }
  4385. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  4386. {
  4387. mtrace();
  4388. int result = FAIL;
  4389. char guid[37]={0};
  4390. char tempdata[65]={0};
  4391. int tempIndex = 0;
  4392. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4393. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4394. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  4395. //set value
  4396. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4397. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (((strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging") != NULL) || (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "SuspendedEV") != NULL) || (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "SuspendedEVSE") != NULL) )?
  4398. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  4399. -1);
  4400. random_uuid(guid);
  4401. //UTC Date time
  4402. struct timeval tmnow;
  4403. struct tm *tm;
  4404. char buf[28];//, usec_buf[6];
  4405. gettimeofday(&tmnow, NULL);
  4406. time_t t;
  4407. t = time(NULL);
  4408. /*UTC time and date*/
  4409. tm = gmtime(&t);
  4410. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4411. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4412. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4413. //********************************(1)Current.Import L1************************************************/
  4414. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  4415. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  4416. (dataType == ReadingContext_Trigger))
  4417. {
  4418. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4419. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4420. {
  4421. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4422. {
  4423. tempIndex = ((gun_index==2) ? 1: 0);
  4424. }
  4425. else
  4426. {
  4427. tempIndex = gun_index;
  4428. }
  4429. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4430. {
  4431. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4432. {
  4433. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4434. }
  4435. }
  4436. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4437. }
  4438. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4439. {
  4440. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4441. {
  4442. tempIndex = ((gun_index==2) ? 1: 0);
  4443. }
  4444. else
  4445. {
  4446. tempIndex = gun_index;
  4447. }
  4448. for (int index = 0; index < CCS_QUANTITY; index++)
  4449. {
  4450. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4451. {
  4452. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4453. }
  4454. }
  4455. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4456. }
  4457. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4458. {
  4459. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4460. {
  4461. tempIndex = ((gun_index==2) ? 1: 0);
  4462. }
  4463. else
  4464. {
  4465. tempIndex = gun_index;
  4466. }
  4467. for (int index = 0; index < GB_QUANTITY; index++)
  4468. {
  4469. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4470. {
  4471. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4472. }
  4473. }
  4474. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4475. }
  4476. else if(gunType[gun_index] == GUN_TYPE_DO)
  4477. {
  4478. tempIndex = gun_index;
  4479. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4480. {
  4481. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4482. {
  4483. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  4484. }
  4485. }
  4486. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4487. }
  4488. else
  4489. {
  4490. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4491. {
  4492. tempIndex = 2;
  4493. }
  4494. else
  4495. {
  4496. tempIndex = gun_index;
  4497. }
  4498. for (int index = 0; index < AC_QUANTITY; index++)
  4499. {
  4500. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4501. {
  4502. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4503. }
  4504. }
  4505. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4506. }
  4507. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4508. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4509. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4510. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4511. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4512. }
  4513. //********************************(2)Energy.Active.Import.Register ************************************************/
  4514. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4515. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4516. (dataType == ReadingContext_Trigger))
  4517. {
  4518. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4519. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4520. {
  4521. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4522. {
  4523. tempIndex = ((gun_index==2) ? 1: 0);
  4524. }
  4525. else
  4526. {
  4527. tempIndex = gun_index;
  4528. }
  4529. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4530. {
  4531. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4532. {
  4533. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4534. }
  4535. }
  4536. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4537. }
  4538. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4539. {
  4540. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4541. {
  4542. tempIndex = ((gun_index==2) ? 1: 0);
  4543. }
  4544. else
  4545. {
  4546. tempIndex = gun_index;
  4547. }
  4548. for (int index = 0; index < CCS_QUANTITY; index++)
  4549. {
  4550. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4551. {
  4552. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4553. }
  4554. }
  4555. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4556. }
  4557. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4558. {
  4559. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4560. {
  4561. tempIndex = ((gun_index==2) ? 1: 0);
  4562. }
  4563. else
  4564. {
  4565. tempIndex = gun_index;
  4566. }
  4567. for (int index = 0; index < GB_QUANTITY; index++)
  4568. {
  4569. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4570. {
  4571. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4572. }
  4573. }
  4574. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4575. }
  4576. else if(gunType[gun_index] == GUN_TYPE_DO)
  4577. {
  4578. tempIndex = gun_index;
  4579. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4580. {
  4581. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4582. {
  4583. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  4584. }
  4585. }
  4586. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4587. }
  4588. else
  4589. {
  4590. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4591. {
  4592. tempIndex = 2;
  4593. }
  4594. else
  4595. {
  4596. tempIndex = gun_index;
  4597. }
  4598. for (int index = 0; index < AC_QUANTITY; index++)
  4599. {
  4600. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4601. {
  4602. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  4603. }
  4604. }
  4605. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4606. }
  4607. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  4608. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  4609. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  4610. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  4611. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4612. }
  4613. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  4614. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  4615. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  4616. (dataType == ReadingContext_Trigger))
  4617. {
  4618. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4619. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4620. {
  4621. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4622. {
  4623. tempIndex = ((gun_index==2) ? 1: 0);
  4624. }
  4625. else
  4626. {
  4627. tempIndex = gun_index;
  4628. }
  4629. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4630. {
  4631. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4632. {
  4633. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  4634. }
  4635. } // END OF FOR CHAdeMO_QUANTITY
  4636. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4637. }
  4638. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4639. {
  4640. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4641. {
  4642. tempIndex = ((gun_index==2) ? 1: 0);
  4643. }
  4644. else
  4645. {
  4646. tempIndex = gun_index;
  4647. }
  4648. for (int index = 0; index < CCS_QUANTITY; index++)
  4649. {
  4650. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4651. {
  4652. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  4653. }
  4654. } // END OF CCS_QUANTITY
  4655. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4656. }
  4657. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4658. {
  4659. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4660. {
  4661. tempIndex = ((gun_index==2) ? 1: 0);
  4662. }
  4663. else
  4664. {
  4665. tempIndex = gun_index;
  4666. }
  4667. for (int index = 0; index < GB_QUANTITY; index++)
  4668. {
  4669. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4670. {
  4671. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  4672. }
  4673. } // END OF GB_QUANTITY
  4674. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4675. }
  4676. else if(gunType[gun_index] == GUN_TYPE_DO)
  4677. {
  4678. tempIndex = gun_index;
  4679. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4680. {
  4681. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4682. {
  4683. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  4684. }
  4685. }
  4686. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4687. }
  4688. else
  4689. {
  4690. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4691. {
  4692. tempIndex = 2;
  4693. }
  4694. else
  4695. {
  4696. tempIndex = gun_index;
  4697. }
  4698. for (int index = 0; index < AC_QUANTITY; index++)
  4699. {
  4700. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4701. {
  4702. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  4703. }
  4704. }
  4705. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  4706. }
  4707. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  4708. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  4709. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  4710. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  4711. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4712. }
  4713. //********************************(4)Power.Active.Import************************************************/
  4714. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Power.Active.Import") != NULL)) ||
  4715. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Power.Active.Import") != NULL)) ||
  4716. (dataType == ReadingContext_Trigger))
  4717. {
  4718. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4719. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4720. {
  4721. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4722. {
  4723. tempIndex = ((gun_index==2) ? 1: 0);
  4724. }
  4725. else
  4726. {
  4727. tempIndex = gun_index;
  4728. }
  4729. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4730. {
  4731. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4732. {
  4733. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  4734. }
  4735. } // END OF FOR
  4736. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4737. }
  4738. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4739. {
  4740. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4741. {
  4742. tempIndex = ((gun_index==2) ? 1: 0);
  4743. }
  4744. else
  4745. {
  4746. tempIndex = gun_index;
  4747. }
  4748. for (int index = 0; index < CCS_QUANTITY; index++)
  4749. {
  4750. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4751. {
  4752. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  4753. }
  4754. }
  4755. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4756. }
  4757. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4758. {
  4759. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4760. {
  4761. tempIndex = ((gun_index==2) ? 1: 0);
  4762. }
  4763. else
  4764. {
  4765. tempIndex = gun_index;
  4766. }
  4767. for (int index = 0; index < GB_QUANTITY; index++)
  4768. {
  4769. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4770. {
  4771. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4772. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  4773. }
  4774. }
  4775. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4776. }
  4777. else if(gunType[gun_index] == GUN_TYPE_DO)
  4778. {
  4779. tempIndex = gun_index;
  4780. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4781. {
  4782. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4783. {
  4784. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4785. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  4786. }
  4787. }
  4788. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4789. }
  4790. else
  4791. {
  4792. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4793. {
  4794. tempIndex = 2;
  4795. }
  4796. else
  4797. {
  4798. tempIndex = gun_index;
  4799. }
  4800. for (int index = 0; index < AC_QUANTITY; index++)
  4801. {
  4802. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4803. {
  4804. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  4805. }
  4806. }
  4807. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  4808. }
  4809. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  4810. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  4811. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  4812. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  4813. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  4814. }
  4815. //***********************************************(5)VOLTAGE L1******************************************************/
  4816. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  4817. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  4818. (dataType == ReadingContext_Trigger))
  4819. {
  4820. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4821. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4822. {
  4823. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4824. {
  4825. tempIndex = ((gun_index==2) ? 1: 0);
  4826. }
  4827. else
  4828. {
  4829. tempIndex = gun_index;
  4830. }
  4831. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4832. {
  4833. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4834. {
  4835. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  4836. }
  4837. }
  4838. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4839. }
  4840. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4841. {
  4842. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4843. {
  4844. tempIndex = ((gun_index==2) ? 1: 0);
  4845. }
  4846. else
  4847. {
  4848. tempIndex = gun_index;
  4849. }
  4850. for (int index = 0; index < CCS_QUANTITY; index++)
  4851. {
  4852. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4853. {
  4854. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  4855. }
  4856. }
  4857. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4858. }
  4859. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4860. {
  4861. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4862. {
  4863. tempIndex = ((gun_index==2) ? 1: 0);
  4864. }
  4865. else
  4866. {
  4867. tempIndex = gun_index;
  4868. }
  4869. for (int index = 0; index < GB_QUANTITY; index++)
  4870. {
  4871. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4872. {
  4873. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  4874. }
  4875. }
  4876. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4877. }
  4878. else if(gunType[gun_index] == GUN_TYPE_DO)
  4879. {
  4880. tempIndex = gun_index;
  4881. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4882. {
  4883. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4884. {
  4885. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  4886. }
  4887. }
  4888. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4889. }
  4890. else
  4891. {
  4892. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4893. {
  4894. tempIndex = 2;
  4895. }
  4896. else
  4897. {
  4898. tempIndex = gun_index;
  4899. }
  4900. for (int index = 0; index < AC_QUANTITY; index++)
  4901. {
  4902. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4903. {
  4904. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  4905. }
  4906. }
  4907. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  4908. }
  4909. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  4910. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  4911. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  4912. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  4913. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4914. }
  4915. //***********************************************(6)SOC******************************************************/
  4916. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "SOC") != NULL)) ||
  4917. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "SOC") != NULL)) ||
  4918. (dataType == ReadingContext_Trigger))
  4919. {
  4920. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  4921. {
  4922. //idx_sample=5;
  4923. //sampledValue = NULL;
  4924. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4925. {
  4926. tempIndex = ((gun_index==2) ? 1: 0);
  4927. }
  4928. else
  4929. {
  4930. tempIndex = gun_index;
  4931. }
  4932. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4933. {
  4934. //tempIndex = ((gun_index==2) ? 1: 0);
  4935. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4936. {
  4937. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4938. {
  4939. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  4940. }
  4941. }
  4942. }
  4943. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4944. {
  4945. //tempIndex = ((gun_index==2) ? 1: 0);
  4946. for (int index = 0; index < CCS_QUANTITY; index++)
  4947. {
  4948. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4949. {
  4950. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  4951. }
  4952. }
  4953. }
  4954. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4955. {
  4956. //tempIndex = ((gun_index==2) ? 1: 0);
  4957. for (int index = 0; index < GB_QUANTITY; index++)
  4958. {
  4959. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4960. {
  4961. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  4962. }
  4963. }
  4964. }
  4965. else if(gunType[gun_index] == GUN_TYPE_DO)
  4966. {
  4967. //tempIndex = ((gun_index==2) ? 1: 0);
  4968. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4969. {
  4970. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4971. {
  4972. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  4973. }
  4974. }
  4975. }
  4976. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  4977. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  4978. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  4979. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  4980. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  4981. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  4982. }
  4983. }
  4984. //********************************(7)Current.Import L2************************************************/
  4985. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  4986. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  4987. (dataType == ReadingContext_Trigger))
  4988. {
  4989. // Only for AC 3 phase
  4990. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4991. {
  4992. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4993. {
  4994. tempIndex = 2;
  4995. }
  4996. else
  4997. {
  4998. tempIndex = gun_index;
  4999. }
  5000. for (int index = 0; index < AC_QUANTITY; index++)
  5001. {
  5002. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5003. {
  5004. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  5005. }
  5006. }
  5007. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  5008. }
  5009. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  5010. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  5011. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  5012. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  5013. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5014. }
  5015. //********************************(8)Current.Import L3************************************************/
  5016. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5017. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5018. (dataType == ReadingContext_Trigger))
  5019. {
  5020. // Only for AC 3 phase
  5021. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5022. {
  5023. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5024. {
  5025. tempIndex = 2;
  5026. }
  5027. else
  5028. {
  5029. tempIndex = gun_index;
  5030. }
  5031. for (int index = 0; index < AC_QUANTITY; index++)
  5032. {
  5033. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5034. {
  5035. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  5036. }
  5037. }
  5038. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  5039. }
  5040. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  5041. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  5042. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  5043. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  5044. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5045. }
  5046. //***********************************************(9)VOLTAGE L2******************************************************/
  5047. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5048. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5049. (dataType == ReadingContext_Trigger))
  5050. {
  5051. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5052. {
  5053. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5054. {
  5055. tempIndex = 2;
  5056. }
  5057. else
  5058. {
  5059. tempIndex = gun_index;
  5060. }
  5061. for (int index = 0; index < AC_QUANTITY; index++)
  5062. {
  5063. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5064. {
  5065. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  5066. }
  5067. }
  5068. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  5069. }
  5070. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  5071. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  5072. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  5073. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  5074. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5075. }
  5076. //***********************************************(10)VOLTAGE L3******************************************************/
  5077. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5078. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5079. (dataType == ReadingContext_Trigger))
  5080. {
  5081. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5082. {
  5083. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5084. {
  5085. tempIndex = 2;
  5086. }
  5087. else
  5088. {
  5089. tempIndex = gun_index;
  5090. }
  5091. for (int index = 0; index < AC_QUANTITY; index++)
  5092. {
  5093. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5094. {
  5095. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  5096. }
  5097. }
  5098. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  5099. }
  5100. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  5101. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  5102. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  5103. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  5104. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5105. }
  5106. // Message create ====================================================================================================
  5107. if(TRUE)
  5108. {
  5109. json_object *MeterValueReq = json_object_new_object();
  5110. json_object *MeterValues = json_object_new_array();
  5111. json_object *sampledValues = json_object_new_array();
  5112. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  5113. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  5114. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  5115. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  5116. {
  5117. json_object *MeterValue = json_object_new_object();
  5118. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  5119. {
  5120. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  5121. {
  5122. json_object *sampledValue = json_object_new_object();
  5123. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  5124. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  5125. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  5126. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  5127. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  5128. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  5129. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  5130. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  5131. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  5132. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  5133. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  5134. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  5135. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  5136. json_object_array_add(sampledValues, sampledValue);
  5137. }
  5138. }
  5139. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  5140. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  5141. json_object_array_add(MeterValues, MeterValue);
  5142. }
  5143. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  5144. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  5145. ,gun_index + 1
  5146. ,MESSAGE_TYPE_CALL
  5147. ,guid
  5148. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  5149. json_object_put(MeterValueReq);
  5150. }
  5151. // Put request guid to hash map
  5152. sprintf(tempdata, "MeterValues,%d", (gun_index));
  5153. 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*/)
  5154. {
  5155. result = PASS;
  5156. //DEBUG_INFO("MeterValues mapitem pass\n");
  5157. }
  5158. if((dataType != ReadingContext_Trigger) &&
  5159. (dataType != ReadingContext_Sample_Clock) &&
  5160. (ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1))
  5161. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  5162. else
  5163. {
  5164. if(FirstHeartBeat)
  5165. LWS_Send(queuedata +2);
  5166. }
  5167. return result;
  5168. }
  5169. //==========================================
  5170. // send confirm routine
  5171. //==========================================
  5172. int sendCancelReservationConfirmation(char *uuid,char *payload)
  5173. {
  5174. mtrace();
  5175. int result = FAIL;
  5176. char message[100]={0};
  5177. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  5178. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5179. LWS_Send(message);
  5180. result = TRUE;
  5181. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  5182. return result;
  5183. }
  5184. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  5185. {
  5186. mtrace();
  5187. int result = FAIL;
  5188. char message[100]={0};
  5189. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  5190. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5191. LWS_Send(message);
  5192. result = TRUE;
  5193. return result;
  5194. }
  5195. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  5196. {
  5197. mtrace();
  5198. int result = FAIL;
  5199. char message[100]={0};
  5200. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  5201. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5202. LWS_Send(message);
  5203. result = TRUE;
  5204. return result;
  5205. }
  5206. int sendClearCacheConfirmation(char *uuid,char *payload)
  5207. {
  5208. mtrace();
  5209. int result = FAIL;
  5210. char message[500]={0};
  5211. DEBUG_INFO("sendClearCacheConfirmation...\n");
  5212. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5213. LWS_Send(message);
  5214. return result;
  5215. }
  5216. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  5217. {
  5218. mtrace();
  5219. int result = FAIL;
  5220. char message[500]={0};
  5221. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  5222. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5223. LWS_Send(message);
  5224. return result;
  5225. }
  5226. int sendDataTransferConfirmation(char *uuid,char *payload)
  5227. {
  5228. mtrace();
  5229. char statusStr[20]={0};
  5230. char dataStr[10]={0};
  5231. char sstr[20]={0};
  5232. int c = 0;
  5233. char *loc;
  5234. int result = FAIL;
  5235. DEBUG_INFO("sendDataTransferConfirmation...\n");
  5236. /**********************status**************************/
  5237. loc = strstr(payload, "status");
  5238. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5239. c = 0;
  5240. while (loc[3+strlen("status")+c] != '\"')
  5241. {
  5242. sstr[c] = loc[3+strlen("status")+c];
  5243. c++;
  5244. }
  5245. sstr[c] = '\0';
  5246. strcpy(statusStr, sstr);
  5247. /**********************data**************************/
  5248. loc = strstr(payload, "data");
  5249. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5250. c = 0;
  5251. while (loc[3+strlen("data")+c] != '\"')
  5252. {
  5253. sstr[c] = loc[3+strlen("data")+c];
  5254. c++;
  5255. }
  5256. sstr[c] = '\0';
  5257. strcpy(dataStr, sstr);
  5258. return result;
  5259. }
  5260. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  5261. {
  5262. mtrace();
  5263. int result = FAIL;
  5264. char message[1000]={0};
  5265. int CompositeScheduleIndex = 0;
  5266. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  5267. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  5268. if(nPeriod == 0)
  5269. {
  5270. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  5271. {
  5272. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  5273. ,MESSAGE_TYPE_CALLRESULT
  5274. ,uuid
  5275. ,payload
  5276. ,connectorIdInt);
  5277. }
  5278. else
  5279. {
  5280. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  5281. ,MESSAGE_TYPE_CALLRESULT
  5282. ,uuid
  5283. ,payload
  5284. ,connectorIdInt
  5285. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5286. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5287. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5288. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  5289. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  5290. }
  5291. }
  5292. else
  5293. {
  5294. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  5295. ,MESSAGE_TYPE_CALLRESULT
  5296. ,uuid
  5297. ,payload
  5298. ,connectorIdInt
  5299. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5300. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5301. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5302. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  5303. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  5304. {
  5305. if (idx_sample == 0)
  5306. {
  5307. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5308. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5309. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5310. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5311. }
  5312. else
  5313. {
  5314. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5315. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5316. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5317. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5318. }
  5319. }
  5320. sprintf(message + strlen(message), "]}}]");
  5321. }
  5322. LWS_Send(message);
  5323. result = TRUE;
  5324. return result;
  5325. }
  5326. int sendGetConfigurationConfirmation(char *uuid)
  5327. {
  5328. mtrace();
  5329. int result = FAIL;
  5330. int MaxKeySupported = 0;
  5331. int sentConfigurationNumber= 0;
  5332. int sentunConfigurationNumber= 0;
  5333. char message[4000]={0};
  5334. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  5335. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  5336. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  5337. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  5338. ,MESSAGE_TYPE_CALLRESULT
  5339. ,uuid );
  5340. //configuration key
  5341. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  5342. {
  5343. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  5344. {
  5345. if (sentConfigurationNumber == 0)
  5346. {
  5347. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5348. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5349. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5350. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5351. }
  5352. else
  5353. {
  5354. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5355. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5356. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5357. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5358. }
  5359. sentConfigurationNumber = sentConfigurationNumber + 1;
  5360. }
  5361. }
  5362. sprintf(message + strlen(message), "]");
  5363. if(UnknownKeynum != 0)
  5364. {
  5365. sprintf(message + strlen(message), ",\"unknownKey\":[");
  5366. //unkown key
  5367. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  5368. {
  5369. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  5370. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  5371. if(sentunConfigurationNumber == 0)
  5372. {
  5373. sprintf(message + strlen(message), "\"%s\""
  5374. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5375. }
  5376. else
  5377. {
  5378. sprintf(message + strlen(message), ",\"%s\""
  5379. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5380. }
  5381. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  5382. }
  5383. sprintf(message + strlen(message), "]");
  5384. }
  5385. sprintf(message + strlen(message), "}]");
  5386. LWS_Send(message);
  5387. return result;
  5388. }
  5389. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  5390. {
  5391. mtrace();
  5392. int result = FAIL;
  5393. char message[400]={0};
  5394. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  5395. if(strcmp(payload,"")==0)
  5396. {
  5397. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5398. }
  5399. else
  5400. {
  5401. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5402. }
  5403. LWS_Send(message);
  5404. result = TRUE;
  5405. return result;
  5406. }
  5407. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  5408. {
  5409. mtrace();
  5410. int result = FAIL;
  5411. char message[80]={0};
  5412. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  5413. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  5414. LWS_Send(message);
  5415. result = TRUE;
  5416. return result;
  5417. }
  5418. int sendRemoteStartConfirmation(char *uuid,char *payload)
  5419. {
  5420. mtrace();
  5421. int result = FAIL;
  5422. char message[80]={0};
  5423. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  5424. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5425. LWS_Send(message);
  5426. result = TRUE;
  5427. return result;
  5428. }
  5429. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5430. {
  5431. mtrace();
  5432. int result = FAIL;
  5433. char message[80]={0};
  5434. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5435. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5436. LWS_Send(message);
  5437. result = TRUE;
  5438. return result;
  5439. }
  5440. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5441. {
  5442. mtrace();
  5443. int result = FAIL;
  5444. char message[80]={0};
  5445. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5446. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  5447. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5448. LWS_Send(message);
  5449. result = TRUE;
  5450. return result;
  5451. }
  5452. int sendResetConfirmation(char *uuid,char *payload)
  5453. {
  5454. mtrace();
  5455. int result = FAIL;
  5456. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  5457. char message[80]={0};
  5458. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  5459. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5460. LWS_Send(message);
  5461. result = TRUE;
  5462. return result;
  5463. }
  5464. int sendSendLocalListConfirmation(char *uuid,char *payload)
  5465. {
  5466. mtrace();
  5467. int result = FAIL;
  5468. char message[500]={0};
  5469. // [ 3, "1571284266109", { "status": "Accepted" } ]
  5470. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5471. LWS_Send(message);
  5472. result = TRUE;
  5473. return result;
  5474. }
  5475. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  5476. {
  5477. mtrace();
  5478. int result = FAIL;
  5479. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  5480. char message[80]={0};
  5481. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  5482. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5483. LWS_Send(message);
  5484. result = TRUE;
  5485. return result;
  5486. }
  5487. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  5488. {
  5489. mtrace();
  5490. int result = FAIL;
  5491. char message[80]={0};
  5492. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  5493. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5494. LWS_Send(message);
  5495. result = TRUE;
  5496. return result;
  5497. }
  5498. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  5499. {
  5500. mtrace();
  5501. int result = FAIL;
  5502. char message[80]={0};
  5503. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5504. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  5505. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5506. LWS_Send(message);
  5507. result = TRUE;
  5508. return result;
  5509. }
  5510. int sendUpdateFirmwareConfirmation(char *uuid)
  5511. {
  5512. mtrace();
  5513. int result = FAIL;
  5514. char message[60]={0};
  5515. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5516. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  5517. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5518. LWS_Send(message);
  5519. result = TRUE;
  5520. return result;
  5521. }
  5522. //==========================================
  5523. // send CallError routine
  5524. //==========================================
  5525. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  5526. {
  5527. mtrace();
  5528. char message[220]={0};
  5529. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  5530. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  5531. LWS_Send(message);
  5532. }
  5533. //==========================================
  5534. // Handle server request routine Start
  5535. //==========================================
  5536. int handleCancelReservationRequest(char *uuid, char *payload)
  5537. {
  5538. mtrace();
  5539. int result = FAIL;
  5540. int gunNO = 0;
  5541. int reservationIdInt = -1;
  5542. char comfirmstr[20];
  5543. DEBUG_INFO("handleCancelReservationRequest...\n");
  5544. json_object *CancelReservation;
  5545. CancelReservation = json_tokener_parse(payload);
  5546. if(!is_error(CancelReservation))
  5547. {
  5548. // Required data
  5549. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  5550. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  5551. }
  5552. json_object_put(CancelReservation);
  5553. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  5554. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5555. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  5556. if(reservationIdInt != -1)
  5557. {
  5558. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  5559. //check Transaction active
  5560. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5561. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5562. {
  5563. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  5564. {
  5565. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5566. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5567. if(gunType[2] == GUN_TYPE_CHAdeMO)
  5568. {
  5569. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  5570. }
  5571. else
  5572. {
  5573. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  5574. }
  5575. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5576. goto end;
  5577. }
  5578. }
  5579. for (int index = 0; index < CCS_QUANTITY; index++)
  5580. {
  5581. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  5582. {
  5583. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5584. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5585. if(gunType[2] == GUN_TYPE_CCS)
  5586. {
  5587. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  5588. }
  5589. else
  5590. {
  5591. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  5592. }
  5593. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5594. goto end;
  5595. }
  5596. }
  5597. for (int index = 0; index < GB_QUANTITY; index++)
  5598. {
  5599. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  5600. {
  5601. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5602. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5603. if(gunType[2] == GUN_TYPE_GBT)
  5604. {
  5605. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  5606. }
  5607. else
  5608. {
  5609. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  5610. }
  5611. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5612. goto end;
  5613. }
  5614. }
  5615. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5616. {
  5617. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  5618. {
  5619. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5620. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5621. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  5622. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5623. goto end;
  5624. }
  5625. }
  5626. for (int index = 0; index < AC_QUANTITY; index++)
  5627. {
  5628. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  5629. {
  5630. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5631. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5632. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5633. {
  5634. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  5635. }
  5636. else
  5637. {
  5638. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  5639. }
  5640. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5641. goto end;
  5642. }
  5643. }
  5644. }
  5645. //The reservationId does NOT match the reservationId
  5646. sendCancelReservationConfirmation(uuid, comfirmstr);
  5647. end:
  5648. // Fill in ocpp packet uuid
  5649. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  5650. return result;
  5651. }
  5652. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  5653. {
  5654. mtrace();
  5655. int result = FAIL;
  5656. int gunIndex = 0;
  5657. char typeStr[16]={0};
  5658. char comfirmstr[20];
  5659. int specificId = FALSE;
  5660. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  5661. json_object *ChangeAvailability;
  5662. ChangeAvailability = json_tokener_parse(payload);
  5663. if(!is_error(ChangeAvailability))
  5664. {
  5665. // Required data
  5666. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  5667. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  5668. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  5669. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  5670. }
  5671. json_object_put(ChangeAvailability);
  5672. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5673. {
  5674. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  5675. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  5676. }
  5677. else if(gunIndex == 0)
  5678. {
  5679. for(int i=0; i < gunTotalNumber; i++)
  5680. {
  5681. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  5682. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  5683. }
  5684. }
  5685. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5686. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5687. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  5688. {
  5689. specificId = TRUE;
  5690. }
  5691. if(specificId == FALSE)
  5692. goto end;
  5693. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  5694. {
  5695. //----------------------gunIndex is 0 ------------------------------------------------//
  5696. if(gunIndex == 0)
  5697. {
  5698. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5699. {
  5700. for(int i=0; i < gunTotalNumber; i++)
  5701. {
  5702. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5703. {
  5704. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  5705. {
  5706. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5707. {
  5708. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5709. goto end;
  5710. }
  5711. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5712. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5713. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5714. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5715. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5716. {
  5717. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5718. goto end;
  5719. }
  5720. }
  5721. }//END FOR CHAdeMO_QUANTITY
  5722. for (int index = 0; index < CCS_QUANTITY; index++)
  5723. {
  5724. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  5725. {
  5726. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  5727. {
  5728. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5729. goto end;
  5730. }
  5731. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5732. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5733. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5734. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5735. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5736. {
  5737. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5738. goto end;
  5739. }
  5740. }
  5741. }//END FOR CCS_QUANTITY
  5742. for (int index = 0; index < GB_QUANTITY; index++)
  5743. {
  5744. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  5745. {
  5746. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5747. {
  5748. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5749. goto end;
  5750. }
  5751. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5752. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5753. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5754. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5755. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5756. {
  5757. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5758. goto end;
  5759. }
  5760. }
  5761. }// END FOR GB_QUANTITY
  5762. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5763. {
  5764. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  5765. {
  5766. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5767. {
  5768. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5769. goto end;
  5770. }
  5771. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  5772. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  5773. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  5774. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  5775. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5776. {
  5777. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5778. goto end;
  5779. }
  5780. }
  5781. }// END FOR GENERAL_GUN_QUANTITY
  5782. for (int index = 0; index < AC_QUANTITY; index++)
  5783. {
  5784. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  5785. {
  5786. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5787. {
  5788. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5789. goto end;
  5790. }
  5791. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5792. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5793. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5794. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5795. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5796. {
  5797. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5798. goto end;
  5799. }
  5800. }
  5801. }//END FOR AC_QUANTITY
  5802. }// END FOR gunTotalNumber
  5803. }
  5804. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5805. {
  5806. for(int i=0; i < gunTotalNumber; i++)
  5807. {
  5808. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5809. {
  5810. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5811. goto end;
  5812. }
  5813. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5814. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  5815. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  5816. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  5817. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5818. {
  5819. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5820. goto end;
  5821. }
  5822. }
  5823. }
  5824. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5825. goto end;
  5826. }
  5827. //----------------------gunIndex is not 0 ------------------------------------------------//
  5828. //check Transaction active
  5829. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5830. {
  5831. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  5832. {
  5833. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  5834. {
  5835. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5836. goto end;
  5837. }
  5838. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5839. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5840. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5841. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5842. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5843. {
  5844. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5845. goto end;
  5846. }
  5847. else
  5848. {
  5849. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  5850. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5851. goto end;
  5852. }
  5853. }
  5854. }//END FOR CHAdeMO_QUANTITY
  5855. for (int index = 0; index < CCS_QUANTITY; index++)
  5856. {
  5857. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  5858. {
  5859. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  5860. {
  5861. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5862. goto end;
  5863. }
  5864. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5865. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5866. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5867. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5868. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5869. {
  5870. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5871. goto end;
  5872. }
  5873. else
  5874. {
  5875. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  5876. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5877. goto end;
  5878. }
  5879. }
  5880. }//END FOR CCS_QUANTITY
  5881. for (int index = 0; index < GB_QUANTITY; index++)
  5882. {
  5883. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  5884. {
  5885. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5886. {
  5887. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5888. goto end;
  5889. }
  5890. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5891. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5892. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5893. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5894. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5895. {
  5896. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5897. goto end;
  5898. }
  5899. else
  5900. {
  5901. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  5902. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5903. goto end;
  5904. }
  5905. }
  5906. }// END FOR GB_QUANTITY
  5907. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5908. {
  5909. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  5910. {
  5911. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5912. {
  5913. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5914. goto end;
  5915. }
  5916. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  5917. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  5918. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  5919. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  5920. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5921. {
  5922. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5923. goto end;
  5924. }
  5925. else
  5926. {
  5927. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  5928. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5929. goto end;
  5930. }
  5931. }
  5932. }// END FOR GENERAL_GUN_QUANTITY
  5933. for (int index = 0; index < AC_QUANTITY; index++)
  5934. {
  5935. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  5936. {
  5937. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5938. {
  5939. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5940. goto end;
  5941. }
  5942. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5943. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5944. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5945. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5946. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5947. {
  5948. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5949. goto end;
  5950. }
  5951. else
  5952. {
  5953. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  5954. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5955. goto end;
  5956. }
  5957. }
  5958. }//END FOR AC_QUANTITY
  5959. }//END FOR AvailabilityTypeStr[Inoperative]
  5960. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  5961. {
  5962. //----------------------gunIndex is 0 ------------------------------------------------//
  5963. if(gunIndex == 0)
  5964. {
  5965. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5966. {
  5967. for(int i=0; i < gunTotalNumber; i++)
  5968. {
  5969. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5970. {
  5971. if ((gunType[i] == GUN_TYPE_CHAdeMO )&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO)) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5972. {
  5973. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5974. goto end;
  5975. }
  5976. }//END FOR CHAdeMO_QUANTITY
  5977. for (int index = 0; index < CCS_QUANTITY; index++)
  5978. {
  5979. if ((gunType[i] == GUN_TYPE_CCS)&&(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
  5980. {
  5981. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5982. goto end;
  5983. }
  5984. }//END FOR CCS_QUANTITY
  5985. for (int index = 0; index < GB_QUANTITY; index++)
  5986. {
  5987. if ((gunType[i] == GUN_TYPE_GBT)&&(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
  5988. {
  5989. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5990. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5991. goto end;
  5992. }
  5993. }// END FOR GB_QUANTITY
  5994. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5995. {
  5996. if ((gunType[i] == GUN_TYPE_DO)&&(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
  5997. {
  5998. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5999. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6000. goto end;
  6001. }
  6002. }// END FOR GENERAL_GUN_QUANTITY
  6003. for (int index = 0; index < AC_QUANTITY; index++)
  6004. {
  6005. if ((gunType[i] == GUN_TYPE_AC) &&(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
  6006. {
  6007. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6008. goto end;
  6009. }
  6010. }//END FOR CHAdeMO_QUANTITY
  6011. }// END FOR gunTotalNumber
  6012. }
  6013. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6014. {
  6015. for(int i=0; i < gunTotalNumber; i++)
  6016. {
  6017. for (int index = 0; index < AC_QUANTITY; index++)
  6018. {
  6019. if ((gunType[i] == GUN_TYPE_AC) &&(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
  6020. {
  6021. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6022. goto end;
  6023. }
  6024. }//END FOR CHAdeMO_QUANTITY
  6025. } // END FOR gunTotalNumber
  6026. }
  6027. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6028. goto end;
  6029. }
  6030. //----------------------gunIndex is not 0 ------------------------------------------------//
  6031. //check Transaction active
  6032. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6033. {
  6034. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6035. {
  6036. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6037. goto end;
  6038. }
  6039. }//END FOR CHAdeMO_QUANTITY
  6040. for (int index = 0; index < CCS_QUANTITY; index++)
  6041. {
  6042. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6043. {
  6044. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6045. goto end;
  6046. }
  6047. }//END FOR CCS_QUANTITY
  6048. for (int index = 0; index < GB_QUANTITY; index++)
  6049. {
  6050. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6051. {
  6052. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6053. goto end;
  6054. }
  6055. }// END FOR GB_QUANTITY
  6056. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6057. {
  6058. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6059. {
  6060. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6061. goto end;
  6062. }
  6063. }// END FOR GENERAL_GUN_QUANTITY
  6064. for (int index = 0; index < AC_QUANTITY; index++)
  6065. {
  6066. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6067. {
  6068. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6069. goto end;
  6070. }
  6071. }//END FOR AC_QUANTITY
  6072. }//END FOR AvailabilityTypeStr[Operative]
  6073. end:
  6074. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6075. {
  6076. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  6077. }
  6078. else
  6079. {
  6080. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  6081. }
  6082. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6083. {
  6084. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6085. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6086. }
  6087. else if(gunIndex == 0)
  6088. {
  6089. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6090. {
  6091. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  6092. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  6093. }
  6094. }
  6095. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  6096. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6097. return result;
  6098. }
  6099. int handleChangeConfigurationRequest(char *uuid, char *payload)
  6100. {
  6101. mtrace();
  6102. int result = FAIL;
  6103. char keystr[40]={0};
  6104. char valuestr[256]={0};
  6105. char comfirmstr[20]={0};
  6106. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  6107. json_object *ChangeConfiguration;
  6108. ChangeConfiguration = json_tokener_parse(payload);
  6109. if(!is_error(ChangeConfiguration))
  6110. {
  6111. // Required data
  6112. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  6113. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  6114. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  6115. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  6116. }
  6117. json_object_put(ChangeConfiguration);
  6118. if((uuid==NULL) || (payload ==NULL) )
  6119. {
  6120. DEBUG_ERROR("Payload is null\n");
  6121. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6122. }
  6123. else
  6124. {
  6125. int status = setKeyValue(keystr, valuestr);
  6126. switch(status)
  6127. {
  6128. case ConfigurationStatus_Accepted:
  6129. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  6130. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  6131. StoreConfigurationTable();
  6132. break;
  6133. case RebootRequired:
  6134. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  6135. StoreConfigurationTable();
  6136. break;
  6137. case NotSupported:
  6138. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  6139. break;
  6140. case ConfigurationStatus_Rejected:
  6141. default:
  6142. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6143. break;
  6144. }
  6145. }
  6146. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  6147. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  6148. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6149. {
  6150. ChageWebSocketPingInterval(atoi(valuestr));
  6151. }
  6152. if((strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6153. {
  6154. SetOcppConnStatus(FALSE);
  6155. }
  6156. return result;
  6157. }
  6158. int handleClearCacheRequest(char *uuid, char *payload)
  6159. {
  6160. mtrace();
  6161. int result = FAIL;
  6162. char comfirmstr[20];
  6163. char rmFileCmd[100]={0};
  6164. struct stat stats;
  6165. DEBUG_INFO("handleClearCacheRequest...\n");
  6166. stat("/Storage/OCPP", &stats);
  6167. // Check for directory existence
  6168. if (S_ISDIR(stats.st_mode) == 1)
  6169. {}
  6170. else
  6171. {
  6172. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  6173. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  6174. system(rmFileCmd);
  6175. }
  6176. if(OCPP_cleanLocalCache())
  6177. {
  6178. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  6179. }
  6180. else
  6181. {
  6182. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  6183. }
  6184. sendClearCacheConfirmation(uuid, comfirmstr);
  6185. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6186. return result;
  6187. }
  6188. int handleClearChargingProfileRequest(char *uuid, char *payload)
  6189. {
  6190. mtrace();
  6191. int result = FAIL;
  6192. int resultRename;
  6193. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  6194. char chargingProfilePurposeStr[26]={0};
  6195. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  6196. char tempchargingProfilePurposeStr[26]={0};
  6197. char str[100]={0};
  6198. char fname[200]={0};
  6199. char comfirmstr[20]={0};
  6200. char word[1600]={0};
  6201. int clearflag = FALSE;
  6202. int chargingProfileIdIsNULL = FALSE;
  6203. int connectorIsNULL = FALSE;
  6204. int chargingProfilePurposeIsNULL = FALSE;
  6205. int stackLevelIsNULL = FALSE;
  6206. //int GotoEnd = FALSE;
  6207. FILE *fptr1, *fptr2;
  6208. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  6209. int n_chargingProfile=0;
  6210. int isEmptyFile = FALSE;
  6211. char sLineWord[1600]={0};
  6212. char chargingProfiles[10][100]={0};
  6213. int ChargeProfileCount = 0;
  6214. int ch;
  6215. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  6216. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  6217. json_object *ClearChargingProfile;
  6218. ClearChargingProfile = json_tokener_parse(payload);
  6219. if(!is_error(ClearChargingProfile))
  6220. {
  6221. // Optional data
  6222. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  6223. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  6224. else
  6225. chargingProfileIdIsNULL = TRUE;
  6226. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  6227. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  6228. else
  6229. connectorIsNULL = TRUE;
  6230. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  6231. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  6232. else
  6233. chargingProfilePurposeIsNULL = TRUE;
  6234. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  6235. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  6236. else
  6237. stackLevelIsNULL = TRUE;
  6238. }
  6239. json_object_put(ClearChargingProfile);
  6240. if(connectorIsNULL == FALSE)
  6241. {
  6242. switch(connectorIdInt)
  6243. {
  6244. case 0:
  6245. if(chargingProfilePurposeIsNULL == TRUE)
  6246. {
  6247. int l = 0;
  6248. strcpy(fname, ChargePointMaxProfile_JSON);
  6249. if((access(fname,F_OK))!=-1)
  6250. {
  6251. strcpy(chargingProfiles[l], fname);
  6252. l = l + 1;
  6253. }
  6254. strcpy(fname, TxDefaultProfile_0_JSON);
  6255. if((access(fname,F_OK))!=-1)
  6256. {
  6257. strcpy(chargingProfiles[l], fname);
  6258. l = l + 1;
  6259. }
  6260. ChargeProfileCount = l;
  6261. }
  6262. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  6263. {
  6264. strcpy(fname, ChargePointMaxProfile_JSON);
  6265. if((access(fname,F_OK))!=-1)
  6266. {
  6267. strcpy(chargingProfiles[0], fname);
  6268. ChargeProfileCount = 1;
  6269. }
  6270. }
  6271. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6272. {
  6273. strcpy(fname, TxDefaultProfile_0_JSON);
  6274. if((access(fname,F_OK))!=-1)
  6275. {
  6276. strcpy(chargingProfiles[0], fname);
  6277. ChargeProfileCount = 1;
  6278. }
  6279. }
  6280. break;
  6281. default:
  6282. if(chargingProfilePurposeIsNULL == TRUE)
  6283. {
  6284. int m = 0;
  6285. memset(fname, 0, ARRAY_SIZE(fname));
  6286. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6287. if((access(fname,F_OK))!=-1)
  6288. {
  6289. strcpy(chargingProfiles[m], fname);
  6290. m = m + 1;
  6291. }
  6292. memset(fname, 0, ARRAY_SIZE(fname));
  6293. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6294. if((access(fname,F_OK))!=-1)
  6295. {
  6296. strcpy(chargingProfiles[m], fname);
  6297. m = m + 1;
  6298. }
  6299. ChargeProfileCount = m;
  6300. }
  6301. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6302. {
  6303. //strcpy(fname, TxDefaultProfile_1_JSON);
  6304. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6305. if((access(fname,F_OK))!=-1)
  6306. {
  6307. strcpy(chargingProfiles[0], fname);
  6308. ChargeProfileCount = 1;
  6309. }
  6310. }
  6311. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  6312. {
  6313. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6314. if((access(fname,F_OK))!=-1)
  6315. {
  6316. strcpy(chargingProfiles[0], fname);
  6317. ChargeProfileCount = 1;
  6318. }
  6319. //strcpy(fname, TxProfile_1_JSON);
  6320. }
  6321. //strcpy(fname, ChargePointMaxProfile_JSON );
  6322. break;
  6323. }
  6324. }
  6325. else // Check all Charging Profiles
  6326. {
  6327. int i = 0;
  6328. char fnametemp[200]={0};
  6329. ChargeProfileCount = 0;
  6330. //Check ChargePointMaxProfile.json exit
  6331. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  6332. {
  6333. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  6334. i = i + 1;
  6335. }
  6336. //Check TxDefaultProfile_0.json exit
  6337. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  6338. {
  6339. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  6340. i = i + 1;
  6341. }
  6342. //Check TxDefaultProfile_%d.json
  6343. for(int j=1; j <= gunTotalNumber; j++)
  6344. {
  6345. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6346. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  6347. if((access(fnametemp,F_OK))!=-1)
  6348. {
  6349. strcpy(chargingProfiles[i], fnametemp);
  6350. i = i + 1;
  6351. }
  6352. }
  6353. //Check TxProfile_%d.json
  6354. for(int j=1; j <= gunTotalNumber; j++)
  6355. {
  6356. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6357. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  6358. if((access(fnametemp,F_OK))!=-1)
  6359. {
  6360. strcpy(chargingProfiles[i], fnametemp);
  6361. i = i + 1;
  6362. }
  6363. }
  6364. ChargeProfileCount = i;
  6365. }// End connectorIsNULL is TRUE
  6366. if(ChargeProfileCount == 0)
  6367. {
  6368. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6369. goto end;
  6370. }
  6371. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  6372. {
  6373. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6374. goto end;
  6375. }
  6376. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  6377. {
  6378. memset(str, 0, ARRAY_SIZE(str));
  6379. // clear temp file
  6380. sprintf(str,"rm -f %s",temp);
  6381. system(str);
  6382. for(int k=0; k < ChargeProfileCount; k++)
  6383. {
  6384. memset(str, 0, ARRAY_SIZE(str));
  6385. //clear file in C
  6386. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6387. system(str);
  6388. }
  6389. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6390. goto end;
  6391. }
  6392. else if(connectorIsNULL == TRUE)
  6393. {
  6394. for(int k=0; k < ChargeProfileCount; k++)
  6395. {
  6396. fptr1 = fopen(chargingProfiles[k], "r");
  6397. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  6398. //Check Charging Profile Count
  6399. while(fscanf(fptr1, "%s", word) != EOF)
  6400. {
  6401. //DEBUG_INFO("word=%s\n",word);
  6402. if(strstr(word, "chargingProfileId")!= NULL)
  6403. {
  6404. //DEBUG_INFO("test chargingProfileId \n");
  6405. n_chargingProfile = n_chargingProfile + 1;
  6406. //DEBUG_INFO("chargingProfileId Found\n");
  6407. }
  6408. }
  6409. rewind(fptr1);
  6410. //search Charging Profile Element
  6411. //int i= 0;
  6412. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6413. {
  6414. json_object *tmpProfilee;
  6415. tmpProfilee = json_tokener_parse(sLineWord);
  6416. if(!is_error(tmpProfilee))
  6417. {
  6418. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  6419. {
  6420. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  6421. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  6422. }
  6423. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  6424. {
  6425. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  6426. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  6427. }
  6428. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  6429. {
  6430. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  6431. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  6432. }
  6433. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  6434. {
  6435. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  6436. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  6437. }
  6438. }
  6439. json_object_put(tmpProfilee);
  6440. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6441. {
  6442. //------- not write to fptr2-------//
  6443. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6444. //clearflag = TRUE;
  6445. }
  6446. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  6447. {
  6448. //------- not write to fptr2-------//
  6449. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  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(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  6457. {
  6458. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6459. }
  6460. else
  6461. {
  6462. fprintf(fptr2, sLineWord);//writing data into file
  6463. }
  6464. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6465. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6466. if(clearflag == TRUE)
  6467. {
  6468. fclose(fptr1);
  6469. fclose(fptr2);
  6470. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6471. system(str);
  6472. // clear temp file
  6473. sprintf(str,"rm -f %s",temp);
  6474. system(str);
  6475. }
  6476. else
  6477. {
  6478. fclose(fptr1);
  6479. fclose(fptr2);
  6480. memset(str, 0, ARRAY_SIZE(str));
  6481. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6482. system(str);
  6483. resultRename = rename(temp, chargingProfiles[k]);
  6484. if(resultRename == 0)
  6485. {
  6486. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  6487. }
  6488. else
  6489. {
  6490. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  6491. }
  6492. if(comfirmstr[0]== 0)
  6493. {
  6494. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6495. }
  6496. //Check chargingProfile is empty file
  6497. /*------ Read the file ----------------*/
  6498. fptr1=fopen(chargingProfiles[k],"r");
  6499. ch=fgetc(fptr1);
  6500. rewind(fptr1);
  6501. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6502. if(ch!=EOF)
  6503. {
  6504. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6505. {
  6506. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6507. if(sLineWord[0]=='\0')
  6508. {
  6509. isEmptyFile = TRUE;
  6510. break;
  6511. }
  6512. else
  6513. {
  6514. isEmptyFile = FALSE;
  6515. break;
  6516. }
  6517. }
  6518. }
  6519. else
  6520. isEmptyFile = TRUE;
  6521. fclose(fptr1);
  6522. if(isEmptyFile == TRUE)
  6523. {
  6524. memset(str, 0, ARRAY_SIZE(str));
  6525. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6526. system(str);
  6527. }
  6528. }
  6529. }// End of while(int k=0; k < ChargePointCount; k++)
  6530. }
  6531. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  6532. {
  6533. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  6534. for(int k=0; k < ChargeProfileCount; k++)
  6535. {
  6536. fptr1 = fopen(chargingProfiles[k], "r");
  6537. fptr2 = fopen(temp, "w+");
  6538. //Check Charging Profile Count
  6539. while(fscanf(fptr1, "%s", word) != EOF)
  6540. {
  6541. //DEBUG_INFO("word=%s\n",word);
  6542. if(strstr(word, "chargingProfileId")!= NULL)
  6543. {
  6544. n_chargingProfile = n_chargingProfile + 1;
  6545. }
  6546. }
  6547. rewind(fptr1);
  6548. //search Charging Profile Element
  6549. //int i= 0;
  6550. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6551. {
  6552. json_object *tmpProfilee;
  6553. tmpProfilee = json_tokener_parse(sLineWord);
  6554. if(!is_error(tmpProfilee))
  6555. {
  6556. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  6557. {
  6558. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  6559. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  6560. }
  6561. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  6562. {
  6563. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  6564. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  6565. }
  6566. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  6567. {
  6568. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  6569. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  6570. }
  6571. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  6572. {
  6573. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  6574. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  6575. }
  6576. }
  6577. json_object_put(tmpProfilee);
  6578. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6579. {
  6580. //------- not write to fptr2-------//
  6581. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6582. //clearflag = TRUE;
  6583. }
  6584. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6585. {
  6586. //------- not write to fptr2-------//
  6587. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6588. }
  6589. else if(stackLevelIsNULL == TRUE)
  6590. {
  6591. //Clear Whole File
  6592. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6593. clearflag = TRUE;
  6594. break;
  6595. }
  6596. else
  6597. {
  6598. fprintf(fptr2, sLineWord);//writing data into file
  6599. }
  6600. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6601. }
  6602. if(clearflag == TRUE)
  6603. {
  6604. fclose(fptr1);
  6605. fclose(fptr2);
  6606. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6607. system(str);
  6608. // clear temp file
  6609. sprintf(str,"rm -f %s",temp);
  6610. system(str);
  6611. }
  6612. else
  6613. {
  6614. fclose(fptr1);
  6615. fclose(fptr2);
  6616. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6617. system(str);
  6618. resultRename = rename(temp, chargingProfiles[k]);
  6619. if(resultRename == 0)
  6620. {
  6621. DEBUG_INFO("File ChargingProfile renamed successfully");
  6622. }
  6623. else
  6624. {
  6625. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6626. }
  6627. if(comfirmstr[0]== 0)
  6628. {
  6629. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6630. }
  6631. //Check chargingProfile is empty file
  6632. /*------ Read the file ----------------*/
  6633. fptr1=fopen(chargingProfiles[k],"r");
  6634. ch=fgetc(fptr1);
  6635. rewind(fptr1);
  6636. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6637. if(ch!=EOF)
  6638. {
  6639. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6640. {
  6641. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6642. if(sLineWord[0]=='\0')
  6643. {
  6644. isEmptyFile = TRUE;
  6645. break;
  6646. }
  6647. else
  6648. {
  6649. isEmptyFile = FALSE;
  6650. break;
  6651. }
  6652. }
  6653. }
  6654. else
  6655. isEmptyFile = TRUE;
  6656. fclose(fptr1);
  6657. if(isEmptyFile == TRUE)
  6658. {
  6659. memset(str, 0, ARRAY_SIZE(str));
  6660. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6661. system(str);
  6662. }
  6663. /*------- End of reading ---------------*/
  6664. }
  6665. } // while(int k=0; k < ChargeProfileCount; k++)
  6666. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  6667. end:
  6668. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  6669. {
  6670. if(connectorIdInt == 0)
  6671. {
  6672. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  6673. {
  6674. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  6675. }
  6676. }
  6677. else
  6678. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  6679. }
  6680. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  6681. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6682. return result;
  6683. }
  6684. void createFirmwareVersionByDataTransfer(void)
  6685. {
  6686. json_object *FirmwareDataTransfer = json_object_new_object();
  6687. // AC & DC model
  6688. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  6689. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  6690. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  6691. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  6692. // DC model
  6693. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O')
  6694. {
  6695. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  6696. {
  6697. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  6698. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  6699. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  6700. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  6701. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  6702. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  6703. }
  6704. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  6705. ((gunType[1] != GUN_TYPE_UNKNOWN) || (gunType[2] != GUN_TYPE_UNKNOWN) || (gunType[3] != GUN_TYPE_UNKNOWN)))
  6706. {
  6707. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  6708. }
  6709. }
  6710. else
  6711. {
  6712. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  6713. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  6714. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  6715. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  6716. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  6717. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  6718. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  6719. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  6720. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  6721. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  6722. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  6723. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  6724. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  6725. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  6726. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  6727. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  6728. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  6729. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  6730. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  6731. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  6732. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  6733. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  6734. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  6735. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  6736. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  6737. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  6738. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  6739. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  6740. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  6741. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  6742. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  6743. }
  6744. // 4G model
  6745. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  6746. {
  6747. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  6748. }
  6749. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  6750. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  6751. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  6752. json_object_put(FirmwareDataTransfer);
  6753. }
  6754. int handleDataTransferRequest(char *uuid, char *payload)
  6755. {
  6756. mtrace();
  6757. json_object *response = json_object_new_object();
  6758. int result = FAIL;
  6759. char tempvendorId[255]={0};
  6760. char tempmessageId[50]={0};
  6761. char tempdata[512]={0};
  6762. char message[2048]={0};
  6763. DEBUG_INFO("handleDataTransferRequest...\n");
  6764. if((uuid != NULL) && (payload != NULL))
  6765. {
  6766. json_object *DataTransfer;
  6767. DataTransfer = json_tokener_parse(payload);
  6768. if(!is_error(DataTransfer))
  6769. {
  6770. // Required data
  6771. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  6772. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  6773. // Optional data
  6774. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  6775. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  6776. if(json_object_object_get(DataTransfer, "data") != NULL)
  6777. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  6778. result = PASS;
  6779. }
  6780. json_object_put(DataTransfer);
  6781. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  6782. {
  6783. // Send all moudle firmware version on EVSE
  6784. createFirmwareVersionByDataTransfer();
  6785. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6786. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  6787. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6788. json_object_put(response);
  6789. }
  6790. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  6791. {
  6792. system("/usr/bin/run_tmate_restart.sh &");
  6793. }
  6794. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  6795. {
  6796. json_object *data;
  6797. data = json_tokener_parse(tempdata);
  6798. if(!is_error(data))
  6799. {
  6800. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  6801. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  6802. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  6803. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  6804. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  6805. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  6806. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  6807. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  6808. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  6809. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  6810. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6811. }
  6812. else
  6813. {
  6814. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6815. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6816. }
  6817. json_object_put(data);
  6818. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6819. json_object_put(response);
  6820. }
  6821. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  6822. {
  6823. json_object *data;
  6824. data = json_tokener_parse(tempdata);
  6825. if(!is_error(data))
  6826. {
  6827. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  6828. if(json_object_object_get(data, "idToken") != NULL)
  6829. {
  6830. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  6831. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  6832. }
  6833. if(json_object_object_get(data, "price") != NULL)
  6834. {
  6835. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  6836. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  6837. }
  6838. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6839. }
  6840. else
  6841. {
  6842. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6843. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6844. }
  6845. json_object_put(data);
  6846. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6847. json_object_put(response);
  6848. }
  6849. else if(strstr(tempmessageId, "RunningCost") != NULL)
  6850. {
  6851. json_object *data;
  6852. data = json_tokener_parse(tempdata);
  6853. if(!is_error(data))
  6854. {
  6855. if(json_object_object_get(data, "txId") != NULL)
  6856. {
  6857. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  6858. for(int idx = 0;idx<gunTotalNumber;idx++)
  6859. {
  6860. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  6861. {
  6862. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  6863. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  6864. if(json_object_object_get(data, "description") != NULL)
  6865. {
  6866. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  6867. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  6868. }
  6869. }
  6870. }
  6871. }
  6872. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6873. }
  6874. else
  6875. {
  6876. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6877. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6878. }
  6879. json_object_put(data);
  6880. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6881. json_object_put(response);
  6882. }
  6883. else if(strstr(tempmessageId, "FinalCost") != NULL)
  6884. {
  6885. json_object *data;
  6886. data = json_tokener_parse(tempdata);
  6887. if(!is_error(data))
  6888. {
  6889. if(json_object_object_get(data, "txId") != NULL)
  6890. {
  6891. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  6892. for(int idx = 0;idx<gunTotalNumber;idx++)
  6893. {
  6894. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  6895. {
  6896. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  6897. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  6898. if(json_object_object_get(data, "description") != NULL)
  6899. {
  6900. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  6901. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  6902. }
  6903. }
  6904. }
  6905. }
  6906. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6907. }
  6908. else
  6909. {
  6910. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6911. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6912. }
  6913. json_object_put(data);
  6914. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6915. json_object_put(response);
  6916. }
  6917. else
  6918. {
  6919. // Can not find valid message id
  6920. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  6921. }
  6922. }
  6923. else
  6924. {
  6925. // Payload is null
  6926. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  6927. }
  6928. LWS_Send(message);
  6929. return result;
  6930. }
  6931. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  6932. {
  6933. mtrace();
  6934. int result = FAIL;
  6935. int connectorIdInt, durationInt;
  6936. char chargingRateUnitStr[4]={0};
  6937. char comfirmstr[20];
  6938. int confirmPeriods = 0;
  6939. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  6940. json_object *GetCompositeSchedule;
  6941. GetCompositeSchedule = json_tokener_parse(payload);
  6942. if(!is_error(GetCompositeSchedule))
  6943. {
  6944. // Required data
  6945. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  6946. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  6947. else
  6948. connectorIdInt = -1;
  6949. if(json_object_object_get(GetCompositeSchedule, "duration"))
  6950. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  6951. else
  6952. durationInt = 86400;
  6953. // Optional data
  6954. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  6955. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  6956. }
  6957. json_object_put(GetCompositeSchedule);
  6958. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  6959. if((connectorIdInt == 0) ||
  6960. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  6961. {
  6962. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  6963. struct StructChargingProfile tmpProfile[1];
  6964. if(strstr(chargingRateUnitStr, "W") != NULL)
  6965. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  6966. else
  6967. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  6968. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6969. {
  6970. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6971. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6972. }
  6973. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  6974. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  6975. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  6976. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6977. {
  6978. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6979. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6980. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  6981. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0))
  6982. {
  6983. confirmPeriods = idx;
  6984. break;
  6985. }
  6986. }
  6987. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6988. }
  6989. else
  6990. {
  6991. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  6992. }
  6993. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  6994. return result;
  6995. }
  6996. int handleGetConfigurationRequest(char *uuid, char *payload)
  6997. {
  6998. mtrace();
  6999. int result = FAIL;
  7000. int MaxKeySupported = 0;
  7001. int n_keys = 0;
  7002. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  7003. DEBUG_INFO("handleGetConfigurationRequest...\n");
  7004. json_object *GetConfiguration;
  7005. GetConfiguration = json_tokener_parse(payload);
  7006. if(!is_error(GetConfiguration))
  7007. {
  7008. // Optional data
  7009. if(json_object_object_get(GetConfiguration, "key") != NULL)
  7010. {
  7011. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  7012. {
  7013. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  7014. n_keys = idx + 1;
  7015. }
  7016. }
  7017. }
  7018. json_object_put(GetConfiguration);
  7019. UnknownKeynum = 0;
  7020. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  7021. MaxKeySupported = GetConfigurationMaxKeysNUM;
  7022. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  7023. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  7024. if(n_keys != 0)
  7025. {
  7026. for(int i=0;i<n_keys;i++)
  7027. {
  7028. getKeyValue(requestKey[i]);
  7029. }
  7030. }
  7031. else
  7032. {
  7033. DEBUG_INFO("There is no key in Message, get all configuration\n");
  7034. getKeyValue("");
  7035. }
  7036. processUnkownKey();
  7037. sendGetConfigurationConfirmation(uuid);
  7038. return result;
  7039. }
  7040. static char fnamePlusPath[100]={0};
  7041. static char fnamePWithNoPath[60]={0};
  7042. void checkUploadLog(void)
  7043. {
  7044. FILE *fp;
  7045. /* Open the command for reading. */
  7046. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  7047. if (fp == NULL) {
  7048. printf("Failed to run command\n" );
  7049. exit(1);
  7050. }
  7051. int ftppathlen = 0;
  7052. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  7053. int i = 0;
  7054. /* Read the output a line at a time - output it. */
  7055. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  7056. if(i==0)
  7057. {
  7058. ftppathlen = strlen(fnamePlusPath);
  7059. printf("%s\n", fnamePlusPath);
  7060. fnamePlusPath[ftppathlen]='\0';
  7061. break;
  7062. }
  7063. i= i+1;
  7064. }
  7065. /* close */
  7066. pclose(fp);
  7067. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  7068. {
  7069. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  7070. {
  7071. fnamePlusPath[k]='\0';
  7072. }
  7073. }
  7074. i=1;
  7075. //char fname[60]={0};
  7076. while(i < ftppathlen)
  7077. {
  7078. int len=ftppathlen-i;
  7079. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  7080. {
  7081. printf("compare '/' all right\n");
  7082. break;
  7083. }
  7084. i=i+1;
  7085. }
  7086. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  7087. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  7088. fnamePWithNoPath[i+1] = '\0';
  7089. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  7090. {
  7091. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  7092. {
  7093. fnamePWithNoPath[j]='\0';
  7094. }
  7095. }
  7096. FILE* fp1 = fopen(fnamePlusPath, "r");
  7097. if (fp1)
  7098. {
  7099. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  7100. // file exists
  7101. fclose(fp1);
  7102. }
  7103. else
  7104. {
  7105. // file doesn't exist
  7106. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  7107. }
  7108. }
  7109. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  7110. {
  7111. mtrace();
  7112. int result = FAIL;
  7113. time_t CurrentTime;
  7114. struct tm *tm;
  7115. pthread_t th_Status;
  7116. CurrentTime = time(NULL);
  7117. tm = localtime(&CurrentTime);
  7118. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  7119. 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);
  7120. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  7121. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  7122. return result;
  7123. }
  7124. void* GetDiagnosticsProcess(void* data)
  7125. {
  7126. pthread_detach(pthread_self());
  7127. mtrace();
  7128. int retriesInt=0, retryIntervalInt=0;
  7129. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  7130. 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};
  7131. int port=0;
  7132. int isSuccess = FALSE;
  7133. char ftpbuf[200]={0};
  7134. char cmdBuf[2048];
  7135. struct tm *tmNow;
  7136. time_t CurrentTime;
  7137. struct tm tmStart;
  7138. struct tm tmStop;
  7139. CurrentTime = time(NULL);
  7140. tmNow=localtime(&CurrentTime);
  7141. uint16_t targetYear, targetMonth;
  7142. json_object *GetDiagnostics;
  7143. DEBUG_INFO("GetDiagnosticsProcess...\n");
  7144. GetDiagnostics = json_tokener_parse(data);
  7145. if(!is_error(GetDiagnostics))
  7146. {
  7147. // Required data
  7148. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  7149. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  7150. // Optional data
  7151. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  7152. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  7153. else
  7154. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  7155. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  7156. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  7157. else
  7158. retryIntervalInt = 30;
  7159. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  7160. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  7161. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  7162. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  7163. }
  7164. json_object_put(GetDiagnostics);
  7165. // Pack log to compress file
  7166. if((sscanf((char*)startTimestr, "%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) &&
  7167. (sscanf((char*)stopTimestr, "%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))
  7168. {
  7169. // Pack system log
  7170. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  7171. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  7172. targetYear = tmStart.tm_year;
  7173. targetMonth = tmStart.tm_mon;
  7174. do
  7175. {
  7176. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7177. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7178. if(targetMonth+1>=13)
  7179. {
  7180. targetYear += 1;
  7181. targetMonth = 1;
  7182. }
  7183. else
  7184. {
  7185. targetMonth += 1;
  7186. }
  7187. }while((targetYear < (tmNow->tm_year+1900)) ||
  7188. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  7189. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  7190. system(cmdBuf);
  7191. // Pack charging & event log
  7192. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  7193. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  7194. targetYear = tmStart.tm_year;
  7195. targetMonth = tmStart.tm_mon;
  7196. do
  7197. {
  7198. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7199. if(targetMonth+1>=13)
  7200. {
  7201. targetYear += 1;
  7202. targetMonth = 1;
  7203. }
  7204. else
  7205. {
  7206. targetMonth += 1;
  7207. }
  7208. }while((targetYear < (tmNow->tm_year+1900)) ||
  7209. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  7210. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  7211. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  7212. system(cmdBuf);
  7213. // Combine log file
  7214. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  7215. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  7216. }
  7217. else
  7218. {
  7219. system("exec /root/logPackTools 'log' 6");
  7220. }
  7221. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  7222. system(cmdBuf);
  7223. checkUploadLog();
  7224. //****************location*******************/
  7225. if(strcmp(locationstr,"")==0)
  7226. {
  7227. DEBUG_INFO("location is <Empty>!\n");
  7228. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7229. goto end;
  7230. }
  7231. memset(protocol, 0, ARRAY_SIZE(protocol));
  7232. memset(user, 0, ARRAY_SIZE(user) );
  7233. memset(password, 0, ARRAY_SIZE(password));
  7234. memset(host, 0, ARRAY_SIZE(host));
  7235. memset(path, 0, ARRAY_SIZE(path));
  7236. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  7237. memset(host1, 0, ARRAY_SIZE(host1));
  7238. memset(path1, 0, ARRAY_SIZE(path1));
  7239. /*location: ftp://user:password@host:port/path*/
  7240. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  7241. if((access(fnamePlusPath,F_OK))!=-1)
  7242. {
  7243. DEBUG_INFO("fnamePlusPath exist.\n");
  7244. }
  7245. else
  7246. {
  7247. DEBUG_INFO("fnamePlusPath not exist!\n");
  7248. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7249. goto end;
  7250. }
  7251. if(strchr(locationstr,'@')==NULL)
  7252. {
  7253. sscanf(locationstr,
  7254. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  7255. protocol, host, &port, path);
  7256. strcpy(user,"anonymous");
  7257. strcpy(password,"");
  7258. }
  7259. else
  7260. {
  7261. //DEBUG_INFO("pch=%s\n", pch);
  7262. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  7263. protocol, user, password, host, &port, path);
  7264. }
  7265. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  7266. {
  7267. DEBUG_INFO("protocol is not ftp/http ! \n");
  7268. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7269. goto end;
  7270. }
  7271. if(strncmp(locationstr,"http", 4) == 0)
  7272. {
  7273. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  7274. sprintf(ftppath,"/%s", path);
  7275. do
  7276. {
  7277. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  7278. sleep(3);
  7279. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  7280. if(!isSuccess)
  7281. {
  7282. DEBUG_INFO("Diagnostics fail.\n");
  7283. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7284. sleep(retryIntervalInt);
  7285. }
  7286. else
  7287. {
  7288. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  7289. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  7290. }
  7291. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  7292. }
  7293. else
  7294. {
  7295. sscanf(host,"%[^/]%s",host1, path1);
  7296. if(strlen(path) > 0)
  7297. sprintf(ftppath,"/%s", path);
  7298. else
  7299. sprintf(ftppath,"/%s", path1);
  7300. int ftppathlen=strlen(ftppath);
  7301. int i=1;
  7302. char filenametemp[50];
  7303. while(i < ftppathlen)
  7304. {
  7305. int len=ftppathlen-i;
  7306. if(ftppath[len]== 47) // '/' ascll code: 47
  7307. {
  7308. DEBUG_INFO("find '/' all right\n");
  7309. break;
  7310. }
  7311. i=i+1;
  7312. }
  7313. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  7314. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  7315. filenametemp[i+1] = 0;
  7316. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  7317. if(port == 0)
  7318. port = 21;
  7319. do
  7320. {
  7321. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  7322. sleep(3);
  7323. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  7324. if(!isSuccess)
  7325. {
  7326. DEBUG_INFO("Diagnostics fail.\n");
  7327. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7328. sleep(retryIntervalInt);
  7329. }
  7330. else
  7331. {
  7332. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  7333. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  7334. }
  7335. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  7336. }
  7337. end:
  7338. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  7339. system("rm -f /mnt/*");
  7340. pthread_exit(NULL);
  7341. }
  7342. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  7343. {
  7344. mtrace();
  7345. int result = FAIL;
  7346. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  7347. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  7348. {
  7349. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  7350. localversion = -1;
  7351. }
  7352. else
  7353. {
  7354. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  7355. OCPP_getListVerion();
  7356. }
  7357. //from db.OCPP_getListVerion
  7358. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  7359. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  7360. sendGetLocalListVersionConfirmation(uuid,"");
  7361. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  7362. return result;
  7363. }
  7364. int handleRemoteStartRequest(char *uuid, char *payload)
  7365. {
  7366. mtrace();
  7367. int result = FAIL;
  7368. int connectorIdInt=0;
  7369. int tempIndex = 0;
  7370. int connectorIdIsNULL, chargingProfileIsNULL;
  7371. char comfirmstr[20]={0};
  7372. char cmdBuf[512];
  7373. json_object *RemoteStartTransaction;
  7374. FILE *fp;
  7375. DEBUG_INFO("handleRemoteStartRequest ...\n");
  7376. if(server_pending == TRUE)
  7377. {
  7378. return 0;
  7379. }
  7380. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  7381. RemoteStartTransaction = json_tokener_parse(payload);
  7382. if(!is_error(RemoteStartTransaction))
  7383. {
  7384. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  7385. {
  7386. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  7387. if(connectorIdInt <= gunTotalNumber)
  7388. {
  7389. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  7390. // Required data
  7391. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  7392. // Optional data
  7393. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  7394. {
  7395. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  7396. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  7397. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  7398. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  7399. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  7400. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  7401. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  7402. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  7403. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  7404. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  7405. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  7406. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  7407. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  7408. {
  7409. 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")));
  7410. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  7411. 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"));
  7412. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  7413. 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"));
  7414. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  7415. 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")));
  7416. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  7417. {
  7418. 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++)
  7419. {
  7420. 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"));
  7421. 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"));
  7422. 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)
  7423. 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"));
  7424. }
  7425. }
  7426. }
  7427. }
  7428. else
  7429. chargingProfileIsNULL = TRUE;
  7430. }
  7431. }
  7432. else
  7433. connectorIdIsNULL = TRUE;
  7434. }
  7435. else
  7436. connectorIdIsNULL = TRUE;
  7437. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  7438. {
  7439. DEBUG_WARN("Connector id is NULL\n.");
  7440. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7441. goto end;
  7442. }
  7443. /*
  7444. enum _SYSTEM_STATUS
  7445. {
  7446. S_BOOTING = 0,
  7447. S_IDLE, = 1
  7448. S_AUTHORIZING, = 2
  7449. S_REASSIGN_CHECK, = 3
  7450. S_REASSIGN, = 4
  7451. S_PRECHARGE, = 5
  7452. S_PREPARING_FOR_EV, = 6
  7453. S_PREPARING_FOR_EVSE, = 7
  7454. S_CHARGING, = 8
  7455. S_TERMINATING, = 9
  7456. S_COMPLETE, = 10
  7457. S_ALARM, = 11
  7458. S_FAULT = 12
  7459. }
  7460. */
  7461. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  7462. {
  7463. //check Transaction active
  7464. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  7465. {
  7466. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7467. {
  7468. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7469. }
  7470. else
  7471. {
  7472. tempIndex = connectorIdInt -1;
  7473. }
  7474. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7475. {
  7476. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  7477. {
  7478. 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))
  7479. {
  7480. //Reserved
  7481. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7482. }
  7483. 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))
  7484. {
  7485. //Reserved
  7486. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7487. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7488. goto end;
  7489. }
  7490. else
  7491. {
  7492. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7493. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  7494. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  7495. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  7496. {
  7497. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  7498. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7499. goto end;
  7500. }
  7501. }//END FOR ELSE
  7502. }
  7503. }// END FOR CHAdeMO_QUANTITY
  7504. }
  7505. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  7506. {
  7507. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7508. {
  7509. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7510. }
  7511. else
  7512. {
  7513. tempIndex = connectorIdInt -1;
  7514. }
  7515. for (int index = 0; index < CCS_QUANTITY; index++)
  7516. {
  7517. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7518. {
  7519. 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))
  7520. {
  7521. //Reserved
  7522. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7523. }
  7524. 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))
  7525. {
  7526. //Reserved
  7527. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7528. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7529. goto end;
  7530. }
  7531. else
  7532. {
  7533. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7534. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7535. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7536. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7537. {
  7538. DEBUG_WARN("CCS connector not allow start\n.");
  7539. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7540. goto end;
  7541. }
  7542. }// END FOR ELSE
  7543. }
  7544. }// END FOR CCS_QUANTITY
  7545. }
  7546. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  7547. {
  7548. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7549. {
  7550. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7551. }
  7552. else
  7553. {
  7554. tempIndex = connectorIdInt -1;
  7555. }
  7556. for (int index = 0; index < GB_QUANTITY; index++)
  7557. {
  7558. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  7559. {
  7560. 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))
  7561. {
  7562. //Reserved
  7563. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7564. }
  7565. 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))
  7566. {
  7567. //Reserved
  7568. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7569. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7570. goto end;
  7571. }
  7572. else
  7573. {
  7574. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7575. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7576. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7577. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7578. {
  7579. DEBUG_WARN("GB connector not allow start\n.");
  7580. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7581. goto end;
  7582. }
  7583. }// END FOR ELSE
  7584. }
  7585. } // END FOR GB_QUANTITY
  7586. }
  7587. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  7588. {
  7589. tempIndex = connectorIdInt -1;
  7590. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7591. {
  7592. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  7593. {
  7594. 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))
  7595. {
  7596. //Reserved
  7597. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7598. }
  7599. 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))
  7600. {
  7601. //Reserved
  7602. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7603. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7604. goto end;
  7605. }
  7606. else
  7607. {
  7608. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7609. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7610. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7611. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7612. {
  7613. DEBUG_WARN("GB connector not allow start\n.");
  7614. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7615. goto end;
  7616. }
  7617. }// END FOR ELSE
  7618. }
  7619. } // END FOR GB_QUANTITY
  7620. }
  7621. else
  7622. {
  7623. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7624. {
  7625. tempIndex = 2;
  7626. }
  7627. else
  7628. {
  7629. tempIndex = connectorIdInt -1;
  7630. }
  7631. for (int index = 0; index < AC_QUANTITY; index++)
  7632. {
  7633. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  7634. {
  7635. 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))
  7636. {
  7637. //Reserved
  7638. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7639. }
  7640. 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))
  7641. {
  7642. //Reserved
  7643. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7644. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7645. goto end;
  7646. }
  7647. else
  7648. {
  7649. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7650. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7651. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7652. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7653. {
  7654. DEBUG_WARN("AC connector not allow start\n.");
  7655. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7656. goto end;
  7657. }
  7658. }//END FOR ELSE
  7659. }
  7660. }// END FOR AC_QUANTITY
  7661. }
  7662. if(chargingProfileIsNULL == FALSE)
  7663. {
  7664. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7665. {
  7666. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7667. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7668. //memset idTag
  7669. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7670. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7671. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7672. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7673. // Save profile to file
  7674. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7675. system(cmdBuf);
  7676. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7677. fp = fopen(cmdBuf, "w");
  7678. 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));
  7679. fclose(fp);
  7680. }
  7681. else
  7682. {
  7683. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  7684. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7685. }
  7686. }
  7687. else
  7688. {
  7689. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7690. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7691. //memset idTag
  7692. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7693. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7694. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7695. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7696. }
  7697. }
  7698. else
  7699. {
  7700. DEBUG_WARN("Connector id over\n.");
  7701. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7702. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7703. }
  7704. end:
  7705. json_object_put(RemoteStartTransaction);
  7706. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  7707. {
  7708. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  7709. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7710. }
  7711. //OCPP send RemoteStartConfirmation by first.
  7712. sendRemoteStartConfirmation(uuid, comfirmstr);
  7713. return result;
  7714. }
  7715. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  7716. {
  7717. mtrace();
  7718. int result = FAIL;
  7719. int match = FALSE;
  7720. int GunNO = 0;
  7721. int tempIndex = 0;
  7722. int transactionIdInt=0;
  7723. int transactionIdIsNULL= TRUE;
  7724. char comfirmstr[20];
  7725. json_object *RemoteStopTransaction;
  7726. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  7727. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  7728. if(server_pending == TRUE)
  7729. {
  7730. return 0;
  7731. }
  7732. RemoteStopTransaction = json_tokener_parse(payload);
  7733. if(!is_error(RemoteStopTransaction))
  7734. {
  7735. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  7736. {
  7737. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  7738. transactionIdIsNULL = FALSE;
  7739. }
  7740. }
  7741. json_object_put(RemoteStopTransaction);
  7742. if(transactionIdIsNULL == FALSE)
  7743. {
  7744. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  7745. {
  7746. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  7747. {
  7748. //check Transaction active
  7749. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7750. {
  7751. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7752. {
  7753. tempIndex = ((gun_index==2) ? 1: 0);
  7754. }
  7755. else
  7756. {
  7757. tempIndex = gun_index;
  7758. }
  7759. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7760. {
  7761. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7762. {
  7763. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7764. {
  7765. match = TRUE;
  7766. GunNO = gun_index;
  7767. }
  7768. }
  7769. }// END FOR CHAdeMO_QUANTITY
  7770. }
  7771. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7772. {
  7773. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7774. {
  7775. tempIndex = ((gun_index==2) ? 1: 0);
  7776. }
  7777. else
  7778. {
  7779. tempIndex = gun_index;
  7780. }
  7781. for (int index = 0; index < CCS_QUANTITY; index++)
  7782. {
  7783. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7784. {
  7785. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7786. {
  7787. match = TRUE;
  7788. GunNO = gun_index;
  7789. }
  7790. }
  7791. }// END FOR CCS_QUANTITY
  7792. }
  7793. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7794. {
  7795. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7796. {
  7797. tempIndex = ((gun_index==2) ? 1: 0);
  7798. }
  7799. else
  7800. {
  7801. tempIndex = gun_index;
  7802. }
  7803. for (int index = 0; index < GB_QUANTITY; index++)
  7804. {
  7805. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7806. {
  7807. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7808. {
  7809. match = TRUE;
  7810. GunNO = gun_index;
  7811. }
  7812. }
  7813. }// END FOR GB_QUANTITY
  7814. }
  7815. else if(gunType[gun_index] == GUN_TYPE_DO)
  7816. {
  7817. tempIndex = gun_index;
  7818. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7819. {
  7820. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7821. {
  7822. 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
  7823. {
  7824. match = TRUE;
  7825. GunNO = gun_index;
  7826. }
  7827. }
  7828. }// END FOR GB_QUANTITY
  7829. }
  7830. else
  7831. {
  7832. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7833. {
  7834. tempIndex = 2;
  7835. }
  7836. else
  7837. {
  7838. tempIndex = gun_index;
  7839. }
  7840. for (int index = 0; index < AC_QUANTITY; index++)
  7841. {
  7842. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7843. {
  7844. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7845. {
  7846. match = TRUE;
  7847. GunNO = gun_index;
  7848. }
  7849. }
  7850. }// END FOR CHAdeMO_QUANTITY
  7851. } // END FOR AC ELSE
  7852. }// CHECK IF ResponseTransactionId == transactionIdInt
  7853. }//END FOR
  7854. if( match == TRUE)
  7855. {
  7856. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  7857. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7858. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  7859. }
  7860. else
  7861. {
  7862. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7863. }
  7864. }
  7865. else
  7866. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7867. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  7868. return result;
  7869. }
  7870. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  7871. {
  7872. mtrace();
  7873. int result = FAIL;
  7874. int connectorIdInt=0, reservationIdInt=0;
  7875. int tempIndex = 0;
  7876. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  7877. char comfirmstr[20]={0};
  7878. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  7879. int c = 0;
  7880. char *loc;
  7881. //char *ptr;
  7882. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  7883. strcpy(sstrtemp, stringtrimspace(payload));
  7884. //***(1)connectorId ****/
  7885. c=0;
  7886. loc = strstr(sstrtemp, "connectorId");
  7887. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7888. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  7889. {
  7890. sstr[c] = loc[strlen("connectorId")+2+c];
  7891. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7892. c++;
  7893. }
  7894. sstr[c] = '\0';
  7895. connectorIdInt = atoi(sstr);
  7896. //***(2)expiryDate ****/
  7897. loc = strstr(sstrtemp, "expiryDate");
  7898. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7899. c = 0;
  7900. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  7901. {
  7902. sstr[c] = loc[3+strlen("expiryDate")+c];
  7903. c++;
  7904. }
  7905. sstr[c] = '\0';
  7906. strcpy(expiryDatestr, sstr);
  7907. //***(3)idTag ****/
  7908. loc = strstr(sstrtemp, "idTag");
  7909. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7910. c = 0;
  7911. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  7912. {
  7913. sstr[c] = loc[3+strlen("idTag")+c];
  7914. c++;
  7915. }
  7916. sstr[c] = '\0';
  7917. strcpy(idTagstr, sstr);
  7918. //***(4)parentIdTag ****/
  7919. loc = strstr(sstrtemp, "parentIdTag");
  7920. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7921. c = 0;
  7922. if(loc == NULL)
  7923. {
  7924. strcpy(parentIdTagstr, "");
  7925. }
  7926. else
  7927. {
  7928. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  7929. {
  7930. sstr[c] = loc[3+strlen("parentIdTag")+c];
  7931. c++;
  7932. }
  7933. sstr[c] = '\0';
  7934. strcpy(parentIdTagstr, sstr);
  7935. }
  7936. //***(5)reservationId ****/
  7937. c=0;
  7938. loc = strstr(sstrtemp, "reservationId");
  7939. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7940. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  7941. {
  7942. sstr[c] = loc[strlen("reservationId")+2+c];
  7943. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7944. c++;
  7945. }
  7946. sstr[c] = '\0';
  7947. reservationIdInt = atoi(sstr);
  7948. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7949. /*
  7950. enum SYSTEM_STATUS
  7951. {
  7952. SYS_MODE_BOOTING = 0,
  7953. SYS_MODE_IDLE = 1,
  7954. SYS_MODE_AUTHORIZING = 2,
  7955. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  7956. SYS_MODE_REASSIGN = 4,
  7957. SYS_MODE_PREPARING = 5,
  7958. SYS_MODE_PREPARE_FOR_EV = 6,
  7959. SYS_MODE_PREPARE_FOR_EVSE = 7,
  7960. SYS_MODE_CHARGING = 8,
  7961. SYS_MODE_TERMINATING = 9,
  7962. SYS_MODE_COMPLETE = 10,
  7963. SYS_MODE_ALARM = 11,
  7964. SYS_MODE_FAULT = 12,
  7965. SYS_MODE_RESERVATION = 13,
  7966. SYS_MODE_BOOKING = 14,
  7967. SYS_MODE_MAINTAIN = 15,
  7968. SYS_MODE_DEBUG = 16,
  7969. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  7970. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  7971. SYS_MODE_UPDATE = 19
  7972. };
  7973. */
  7974. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  7975. {
  7976. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7977. goto end;
  7978. }
  7979. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  7980. {
  7981. //check Transaction active
  7982. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  7983. {
  7984. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7985. {
  7986. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7987. }
  7988. else
  7989. {
  7990. tempIndex = connectorIdInt -1;
  7991. }
  7992. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7993. {
  7994. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7995. {
  7996. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7997. {
  7998. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7999. {
  8000. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8001. {
  8002. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8003. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8004. }
  8005. 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'))
  8006. {
  8007. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8008. }
  8009. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8010. {
  8011. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8012. }
  8013. else
  8014. {
  8015. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8016. }
  8017. }
  8018. 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
  8019. {
  8020. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8021. }
  8022. }
  8023. else
  8024. {
  8025. //replace reservation
  8026. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8027. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8028. }
  8029. }
  8030. } // END FOR CHAdeMO_QUANTITY
  8031. }
  8032. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8033. {
  8034. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8035. {
  8036. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8037. }
  8038. else
  8039. {
  8040. tempIndex = connectorIdInt -1;
  8041. }
  8042. for (int index = 0; index < CCS_QUANTITY; index++)
  8043. {
  8044. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8045. {
  8046. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8047. {
  8048. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8049. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8050. {
  8051. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8052. {
  8053. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8054. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8055. }
  8056. 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'))
  8057. {
  8058. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8059. }
  8060. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  8061. {
  8062. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8063. }
  8064. else
  8065. {
  8066. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8067. }
  8068. }
  8069. 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
  8070. {
  8071. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8072. }
  8073. }
  8074. else
  8075. {
  8076. //replace reservation
  8077. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8078. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8079. }
  8080. }
  8081. } // END FOR CCS_QUANTITY
  8082. }
  8083. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8084. {
  8085. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8086. {
  8087. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8088. }
  8089. else
  8090. {
  8091. tempIndex = connectorIdInt -1;
  8092. }
  8093. for (int index = 0; index < GB_QUANTITY; index++)
  8094. {
  8095. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8096. {
  8097. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8098. {
  8099. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8100. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  8101. {
  8102. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8103. {
  8104. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8105. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8106. }
  8107. 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'))
  8108. {
  8109. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8110. }
  8111. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8112. {
  8113. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8114. }
  8115. else
  8116. {
  8117. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8118. }
  8119. }
  8120. 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
  8121. {
  8122. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8123. }
  8124. }
  8125. else
  8126. {
  8127. //replace reservation
  8128. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8129. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8130. }
  8131. }
  8132. }// END FOR GB_QUANTITY
  8133. }
  8134. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8135. {
  8136. tempIndex = connectorIdInt -1;
  8137. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8138. {
  8139. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8140. {
  8141. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  8142. {
  8143. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8144. 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
  8145. {
  8146. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8147. {
  8148. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8149. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8150. }
  8151. 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'))
  8152. {
  8153. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8154. }
  8155. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8156. {
  8157. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8158. }
  8159. else
  8160. {
  8161. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8162. }
  8163. }
  8164. 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
  8165. {
  8166. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8167. }
  8168. }
  8169. else
  8170. {
  8171. //replace reservation
  8172. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8173. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8174. }
  8175. }
  8176. }// END FOR GB_QUANTITY
  8177. }
  8178. else
  8179. {
  8180. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8181. {
  8182. tempIndex = 2;
  8183. }
  8184. else
  8185. {
  8186. tempIndex = (connectorIdInt -1);
  8187. }
  8188. for (int index = 0; index < AC_QUANTITY; index++)
  8189. {
  8190. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8191. {
  8192. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  8193. {
  8194. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  8195. {
  8196. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8197. {
  8198. 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))
  8199. {
  8200. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8201. }
  8202. else
  8203. {
  8204. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8205. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8206. }
  8207. }
  8208. 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'))
  8209. {
  8210. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8211. }
  8212. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8213. {
  8214. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8215. }
  8216. else
  8217. {
  8218. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8219. }
  8220. }
  8221. 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
  8222. {
  8223. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8224. }
  8225. }
  8226. else
  8227. {
  8228. //replace reservation
  8229. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8230. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8231. }
  8232. }
  8233. } // END FOR AC_QUANTITY
  8234. }
  8235. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8236. }
  8237. else if(connectorIdInt == 0)
  8238. {
  8239. //check Transaction active
  8240. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8241. {
  8242. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  8243. {
  8244. 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'))
  8245. {
  8246. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8247. goto end;
  8248. }
  8249. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8250. {
  8251. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8252. goto end;
  8253. }
  8254. 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
  8255. {
  8256. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8257. goto end;
  8258. }
  8259. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8260. {
  8261. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8262. goto end;
  8263. }
  8264. }
  8265. }// END FOR CHAdeMO_QUANTITY
  8266. for (int index = 0; index < CCS_QUANTITY; index++)
  8267. {
  8268. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8269. {
  8270. 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'))
  8271. {
  8272. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8273. goto end;
  8274. }
  8275. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  8276. {
  8277. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8278. goto end;
  8279. }
  8280. 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
  8281. {
  8282. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8283. goto end;
  8284. }
  8285. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8286. {
  8287. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8288. goto end;
  8289. }
  8290. }
  8291. } // END FOR CCS_QUANTITY
  8292. for (int index = 0; index < GB_QUANTITY; index++)
  8293. {
  8294. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8295. {
  8296. 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'))
  8297. {
  8298. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8299. goto end;
  8300. }
  8301. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8302. {
  8303. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8304. goto end;
  8305. }
  8306. 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
  8307. {
  8308. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8309. goto end;
  8310. }
  8311. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8312. {
  8313. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8314. goto end;
  8315. }
  8316. }
  8317. } // END FOR GB_QUANTITY
  8318. for (int index = 0; index < AC_QUANTITY; index++)
  8319. {
  8320. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  8321. {
  8322. 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'))
  8323. {
  8324. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8325. goto end;
  8326. }
  8327. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8328. {
  8329. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8330. goto end;
  8331. }
  8332. 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
  8333. {
  8334. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8335. goto end;
  8336. }
  8337. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8338. {
  8339. 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))
  8340. {
  8341. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8342. goto end;
  8343. }
  8344. }
  8345. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8346. {
  8347. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8348. goto end;
  8349. }
  8350. }
  8351. }// END FOR AC_QUANTITY
  8352. //The connectorId is 0
  8353. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  8354. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8355. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  8356. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  8357. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  8358. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  8359. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  8360. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  8361. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  8362. result = TRUE;
  8363. return result;
  8364. }
  8365. else
  8366. {
  8367. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8368. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8369. }
  8370. if(strcmp(comfirmstr,"Accepted") == 0)
  8371. {
  8372. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  8373. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  8374. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  8375. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  8376. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  8377. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  8378. result = TRUE;
  8379. return result;
  8380. }
  8381. end:
  8382. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  8383. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  8384. return result;
  8385. }
  8386. int handleResetRequest(char *uuid, char *payload)
  8387. {
  8388. mtrace();
  8389. int result = FAIL;
  8390. char sstr[10]={0},sstrtemp[30]={ 0 };
  8391. char typestr[10]={0};
  8392. char comfirmstr[20]={0};
  8393. int c = 0;
  8394. char *loc;
  8395. DEBUG_INFO("handleResetRequest...\n");
  8396. strcpy(sstrtemp, stringtrimspace(payload));
  8397. loc = strstr(sstrtemp, "type");
  8398. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8399. c = 0;
  8400. while (loc[3+strlen("type")+c] != '\"')
  8401. {
  8402. sstr[c] = loc[3+strlen("type")+c];
  8403. c++;
  8404. }
  8405. sstr[c] = '\0';
  8406. strcpy(typestr,sstr);
  8407. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  8408. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  8409. {
  8410. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  8411. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  8412. result = TRUE;
  8413. return result;
  8414. }
  8415. else
  8416. {
  8417. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  8418. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  8419. goto errorend;
  8420. }
  8421. errorend:
  8422. sendResetConfirmation(uuid, comfirmstr);
  8423. return result;
  8424. }
  8425. int handleSendLocalListRequest(char *uuid, char *payload)
  8426. {
  8427. mtrace();
  8428. int result = FAIL;
  8429. int listVersionInt;
  8430. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  8431. char listsearch[]="listVersion";
  8432. char updateTypesearch[]="updateType";
  8433. char localAuthorizationListsearch[]="localAuthorizationList";
  8434. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  8435. char CardList[500][160]={0};
  8436. char updateTypestr[15]={0};
  8437. char idTagstr[20]={0};
  8438. char parentIdTag[20]={0};
  8439. char expiryDate[30]={0};
  8440. char idTagstatus[16]={0};
  8441. int c = 0;
  8442. int i = 0;
  8443. char *delim1 = "}";
  8444. char * pch;
  8445. char *loc;
  8446. //char *ptr;
  8447. char comfirmstr[20];
  8448. //int n_localAuthorizations = 0;
  8449. int checkState_Faulted = FALSE;
  8450. DEBUG_INFO("handleSendLocalListRequest...\n");
  8451. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  8452. {
  8453. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8454. goto end;
  8455. }
  8456. //check Charge Point state
  8457. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8458. {
  8459. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8460. {
  8461. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8462. }
  8463. }
  8464. for (int index = 0; index < CCS_QUANTITY; index++)
  8465. {
  8466. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8467. {
  8468. checkState_Faulted = TRUE; //OCPP Status
  8469. }
  8470. }
  8471. for (int index = 0; index < GB_QUANTITY; index++)
  8472. {
  8473. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8474. {
  8475. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8476. }
  8477. }
  8478. //check Charge Point state
  8479. for (int index = 0; index < AC_QUANTITY; index++)
  8480. {
  8481. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8482. {
  8483. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8484. }
  8485. }
  8486. if(checkState_Faulted == TRUE)
  8487. {
  8488. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8489. goto end;
  8490. }
  8491. //Filter payload space
  8492. strcpy(sstrtemp, stringtrimspace(payload));
  8493. //listVersion
  8494. c = 0;
  8495. loc = strstr(sstrtemp, listsearch);
  8496. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  8497. {
  8498. sstr[c] = loc[strlen("listVersion")+2+c];
  8499. c++;
  8500. }
  8501. sstr[c] = '\0';
  8502. listVersionInt = atoi(sstr);
  8503. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8504. //updateType
  8505. loc = strstr(sstrtemp, updateTypesearch);
  8506. c = 0;
  8507. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  8508. {
  8509. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  8510. c++;
  8511. }
  8512. sstr[c] = '\0';
  8513. strcpy(updateTypestr, sstr);
  8514. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  8515. //localAuthorizationList
  8516. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8517. loc = strstr(sstrtemp, localAuthorizationListsearch);
  8518. if(loc != NULL) // localAuthorizationList is not NULL
  8519. {
  8520. //Check UpdateType
  8521. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8522. {
  8523. //Local list full update
  8524. printf("Local list full update.\n");
  8525. OCPP_getListVerion();
  8526. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8527. {
  8528. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8529. goto end;
  8530. }
  8531. OCPP_cleanLocalList();
  8532. }
  8533. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8534. {
  8535. //Local list different update
  8536. printf("Local list different update.\n");
  8537. OCPP_getListVerion();
  8538. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8539. {
  8540. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  8541. goto end;
  8542. }
  8543. }
  8544. else
  8545. {
  8546. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8547. goto end;
  8548. }
  8549. c = 0;
  8550. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  8551. {
  8552. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  8553. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8554. c++;
  8555. }
  8556. sstr[c] = '\0';
  8557. //DEBUG_INFO("sstr=%s\n", sstr);
  8558. //parsing strings to words
  8559. i = 0;
  8560. pch = strtok(sstr,delim1);
  8561. while (pch != NULL)
  8562. {
  8563. strcpy(CardList[i], pch);
  8564. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  8565. pch = strtok (NULL, delim1);
  8566. i = i + 1;
  8567. }
  8568. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  8569. //local Authorizations List Numbers
  8570. //n_localAuthorizations = i;
  8571. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8572. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  8573. c= 0;
  8574. while(c < i) // i is CardList Number
  8575. {
  8576. //Search "IdToken"
  8577. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8578. loc = strstr(CardList[c], "idTag");
  8579. int j = 0;
  8580. while (loc[3+strlen("idTag")+j] != '\"')
  8581. {
  8582. sstr[j] = loc[3+strlen("idTag")+j];
  8583. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8584. j++;
  8585. }
  8586. sstr[j] = '\0';
  8587. strcpy(idTagstr, sstr);
  8588. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  8589. //Search "expiryDate"
  8590. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8591. loc = strstr(CardList[c], "expiryDate");
  8592. j = 0;
  8593. if(loc != NULL)
  8594. {
  8595. while (loc[3+strlen("expiryDate")+j] != '\"')
  8596. {
  8597. sstr[j] = loc[3+strlen("expiryDate")+j];
  8598. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8599. j++;
  8600. }
  8601. sstr[j] = '\0';
  8602. strcpy(expiryDate, sstr);
  8603. }
  8604. else
  8605. {
  8606. strcpy(expiryDate, "");
  8607. }
  8608. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  8609. //Search "parentIdTag"
  8610. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8611. loc = strstr(CardList[c], "parentIdTag");
  8612. j = 0;
  8613. if(loc != NULL)
  8614. {
  8615. while (loc[3+strlen("parentIdTag")+j] != '\"')
  8616. {
  8617. sstr[j] = loc[3+strlen("parentIdTag")+j];
  8618. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8619. j++;
  8620. }
  8621. sstr[j] = '\0';
  8622. strcpy(parentIdTag, sstr);
  8623. }
  8624. else
  8625. {
  8626. strcpy(parentIdTag, "");
  8627. }
  8628. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  8629. //Search "status"
  8630. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8631. loc = strstr(CardList[c], "status");
  8632. j = 0;
  8633. while (loc[3+strlen("status")+j] != '\"')
  8634. {
  8635. sstr[j] = loc[3+strlen("status")+j];
  8636. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8637. j++;
  8638. }
  8639. sstr[j] = '\0';
  8640. strcpy(idTagstatus, sstr);
  8641. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  8642. OCPP_getIdTagFromLocalList(idTagstr);
  8643. //OCPP_getIdTagFromLocalList("test"); For Test
  8644. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  8645. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  8646. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8647. {
  8648. //Local list full update
  8649. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8650. // update list
  8651. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8652. //DEBUG_INFO("Local list full update. 1\n");
  8653. //OCPP_get_TableAuthlocalAllData();
  8654. //DEBUG_INFO("Local list full update. 2\n");
  8655. }
  8656. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8657. {
  8658. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8659. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  8660. }
  8661. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  8662. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  8663. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  8664. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  8665. c++;
  8666. }
  8667. }
  8668. else
  8669. {
  8670. //Check UpdateType
  8671. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8672. {
  8673. //Local list full update
  8674. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  8675. OCPP_cleanLocalList();
  8676. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8677. goto end;
  8678. }
  8679. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8680. {
  8681. //Local list different update
  8682. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  8683. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8684. goto end;
  8685. }
  8686. }
  8687. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8688. end:
  8689. sendSendLocalListConfirmation(uuid, comfirmstr);
  8690. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  8691. return result;
  8692. }
  8693. #define MAX 200
  8694. int handleSetChargingProfileRequest(char *uuid, char *payload)
  8695. {
  8696. mtrace();
  8697. int result = FAIL;
  8698. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  8699. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  8700. char chargingProfilePurposeStr[30]={0};
  8701. char chargingProfileKindStr[16]={0};
  8702. char recurrencyKindStr[10]={0};
  8703. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  8704. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  8705. int chargingSchedulePeriodCount = 0;
  8706. char comfirmstr[20]={0};
  8707. int meet= FALSE;
  8708. FILE *fptr1;
  8709. char filename[MAX]={0};
  8710. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  8711. char rmFileCmd[50]={0};
  8712. char tempchargingProfilePurposeStr[30]={0};
  8713. char word[1600]={0};
  8714. int n_chargingProfile = 0;
  8715. json_object *SetChargingProfile;
  8716. DEBUG_INFO("handleSetChargingProfileRequest\n");
  8717. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  8718. SetChargingProfile = json_tokener_parse(payload);
  8719. if(!is_error(SetChargingProfile))
  8720. {
  8721. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  8722. {
  8723. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  8724. if(connectorIdInt == 0)
  8725. {
  8726. memset(&ShmOCPP16Data->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  8727. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  8728. }
  8729. else
  8730. {
  8731. memset(&ShmOCPP16Data->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  8732. ShmOCPP16Data->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  8733. }
  8734. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  8735. }
  8736. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  8737. {
  8738. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  8739. {
  8740. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  8741. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8742. {
  8743. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8744. }
  8745. else
  8746. {
  8747. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8748. }
  8749. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  8750. }
  8751. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  8752. {
  8753. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  8754. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8755. {
  8756. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  8757. }
  8758. else
  8759. {
  8760. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  8761. }
  8762. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  8763. }
  8764. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8765. {
  8766. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  8767. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8768. {
  8769. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8770. }
  8771. else
  8772. {
  8773. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8774. }
  8775. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  8776. }
  8777. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  8778. {
  8779. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  8780. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8781. {
  8782. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8783. }
  8784. else
  8785. {
  8786. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8787. }
  8788. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  8789. }
  8790. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  8791. {
  8792. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  8793. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8794. {
  8795. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  8796. }
  8797. else
  8798. {
  8799. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  8800. }
  8801. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  8802. }
  8803. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  8804. {
  8805. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  8806. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8807. {
  8808. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8809. }
  8810. else
  8811. {
  8812. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8813. }
  8814. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  8815. }
  8816. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  8817. {
  8818. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  8819. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8820. {
  8821. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  8822. }
  8823. else
  8824. {
  8825. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  8826. }
  8827. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  8828. }
  8829. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  8830. {
  8831. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  8832. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8833. {
  8834. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  8835. }
  8836. else
  8837. {
  8838. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  8839. }
  8840. //DEBUG_INFO("validToStr: %s\n", validToStr);
  8841. }
  8842. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  8843. {
  8844. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  8845. {
  8846. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  8847. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8848. {
  8849. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8850. }
  8851. else
  8852. {
  8853. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8854. }
  8855. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  8856. }
  8857. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  8858. {
  8859. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  8860. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8861. {
  8862. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8863. }
  8864. else
  8865. {
  8866. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8867. }
  8868. //DEBUG_INFO("durationInt: %d\n", durationInt);
  8869. }
  8870. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  8871. {
  8872. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  8873. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8874. {
  8875. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8876. }
  8877. else
  8878. {
  8879. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8880. }
  8881. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  8882. }
  8883. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  8884. {
  8885. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  8886. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8887. {
  8888. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8889. }
  8890. else
  8891. {
  8892. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8893. }
  8894. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  8895. }
  8896. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  8897. {
  8898. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  8899. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  8900. if(chargingSchedulePeriodCount <= 10)
  8901. {
  8902. 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++)
  8903. {
  8904. 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)
  8905. {
  8906. 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"));
  8907. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8908. {
  8909. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  8910. }
  8911. else
  8912. {
  8913. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  8914. }
  8915. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  8916. }
  8917. 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)
  8918. {
  8919. 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"));
  8920. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8921. {
  8922. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  8923. }
  8924. else
  8925. {
  8926. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  8927. }
  8928. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  8929. }
  8930. 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)
  8931. {
  8932. 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"));
  8933. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8934. {
  8935. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  8936. }
  8937. else
  8938. {
  8939. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  8940. }
  8941. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  8942. }
  8943. }
  8944. }
  8945. }
  8946. }
  8947. }
  8948. }
  8949. json_object_put(SetChargingProfile);
  8950. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8951. {
  8952. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8953. goto end;
  8954. }
  8955. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8956. {
  8957. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8958. if(connectorIdInt != 0)
  8959. {
  8960. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8961. goto end;
  8962. }
  8963. strcpy(filename, ChargePointMaxProfile_JSON );
  8964. fptr1 = fopen(filename, "r");
  8965. if (!fptr1)
  8966. {
  8967. //file not exist
  8968. DEBUG_INFO("Unable to open the input file!!\n");
  8969. fptr1 = fopen(filename, "w+");
  8970. }
  8971. else
  8972. {
  8973. //Check Charging Profile Count
  8974. while(fscanf(fptr1, "%s", word) != EOF)
  8975. {
  8976. //DEBUG_INFO("word=%s\n",word);
  8977. if(strstr(word, "chargingProfileId")!= NULL)
  8978. {
  8979. //DEBUG_INFO("test chargingProfileId \n");
  8980. n_chargingProfile = n_chargingProfile + 1;
  8981. //DEBUG_INFO("chargingProfileId Found\n");
  8982. }
  8983. }
  8984. }
  8985. fclose(fptr1);
  8986. }
  8987. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8988. {
  8989. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8990. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8991. {
  8992. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8993. goto end;
  8994. }
  8995. memset(filename, 0, ARRAY_SIZE(filename));
  8996. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8997. fptr1 = fopen(filename, "r");
  8998. if (!fptr1)
  8999. {
  9000. //file not exist
  9001. //DEBUG_INFO("Unable to open the input file!!\n");
  9002. fptr1 = fopen(filename, "w+");
  9003. }
  9004. else
  9005. {
  9006. //Check Charging Profile Count
  9007. while(fscanf(fptr1, "%s", word) != EOF)
  9008. {
  9009. //DEBUG_INFO("word=%s\n",word);
  9010. if(strstr(word, "chargingProfileId")!= NULL)
  9011. {
  9012. //DEBUG_INFO("test chargingProfileId \n");
  9013. n_chargingProfile = n_chargingProfile + 1;
  9014. //DEBUG_INFO("chargingProfileId Found\n");
  9015. }
  9016. }
  9017. }
  9018. fclose(fptr1);
  9019. }
  9020. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9021. {
  9022. //printf("set chargingProfile 1-4\n");
  9023. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  9024. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  9025. if(connectorIdInt == 0)
  9026. {
  9027. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9028. goto end;
  9029. }
  9030. int tempIndex = 0;
  9031. //check Transaction active
  9032. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9033. {
  9034. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9035. {
  9036. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9037. }
  9038. else
  9039. {
  9040. tempIndex = connectorIdInt -1;
  9041. }
  9042. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9043. {
  9044. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9045. {
  9046. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9047. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9048. {
  9049. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9050. {
  9051. meet = TRUE;
  9052. break;
  9053. }
  9054. }
  9055. }
  9056. }
  9057. }
  9058. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9059. {
  9060. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9061. {
  9062. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9063. }
  9064. else
  9065. {
  9066. tempIndex = connectorIdInt -1;
  9067. }
  9068. for (int index = 0; index < CCS_QUANTITY; index++)
  9069. {
  9070. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9071. {
  9072. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9073. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9074. {
  9075. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9076. {
  9077. meet = TRUE;
  9078. break;
  9079. }
  9080. }
  9081. }
  9082. }
  9083. }
  9084. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9085. {
  9086. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9087. {
  9088. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9089. }
  9090. else
  9091. {
  9092. tempIndex = connectorIdInt -1;
  9093. }
  9094. for (int index = 0; index < GB_QUANTITY; index++)
  9095. {
  9096. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9097. {
  9098. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9099. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9100. {
  9101. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9102. {
  9103. meet = TRUE;
  9104. break;
  9105. }
  9106. }
  9107. }
  9108. }
  9109. }
  9110. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9111. {
  9112. tempIndex = connectorIdInt -1;
  9113. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9114. {
  9115. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9116. {
  9117. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  9118. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9119. {
  9120. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9121. {
  9122. meet = TRUE;
  9123. break;
  9124. }
  9125. }
  9126. }
  9127. }
  9128. }
  9129. else
  9130. {
  9131. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9132. {
  9133. tempIndex = 2;
  9134. }
  9135. else
  9136. {
  9137. tempIndex = (connectorIdInt -1);
  9138. }
  9139. for (int index = 0; index < AC_QUANTITY; index++)
  9140. {
  9141. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9142. {
  9143. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9144. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9145. {
  9146. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9147. {
  9148. meet = TRUE;
  9149. break;
  9150. }
  9151. }
  9152. }
  9153. }
  9154. }
  9155. //check Transaction active
  9156. if(meet == FALSE)
  9157. {
  9158. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9159. goto end;
  9160. }
  9161. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9162. {
  9163. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9164. goto end;
  9165. }
  9166. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9167. fptr1 = fopen(filename, "r");
  9168. if (!fptr1)
  9169. {
  9170. //file not exist
  9171. DEBUG_INFO("Unable to open the input file!!\n");
  9172. fptr1 = fopen(filename, "w+");
  9173. }
  9174. else
  9175. {
  9176. //Check Charging Profile Count
  9177. while(fscanf(fptr1, "%s", word) != EOF)
  9178. {
  9179. //DEBUG_INFO("word=%s\n",word);
  9180. if(strstr(word, "chargingProfileId")!= NULL)
  9181. {
  9182. //DEBUG_INFO("test chargingProfileId \n");
  9183. n_chargingProfile = n_chargingProfile + 1;
  9184. //DEBUG_INFO("chargingProfileId Found\n");
  9185. }
  9186. }
  9187. }
  9188. fclose(fptr1);
  9189. }
  9190. // Check ChargeProfileMaxStackLevel
  9191. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  9192. {
  9193. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9194. goto end;
  9195. }
  9196. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9197. {
  9198. int i = 0;
  9199. char fnametemp[200]={0};
  9200. n_chargingProfile = 0;
  9201. //Check ChargePointMaxProfile.json exit
  9202. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9203. {
  9204. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  9205. //Check Charging Profile Count
  9206. while(fscanf(fptr1, "%s", word) != EOF)
  9207. {
  9208. //DEBUG_INFO("word=%s\n",word);
  9209. if(strstr(word, "chargingProfileId")!= NULL)
  9210. {
  9211. //DEBUG_INFO("test chargingProfileId \n");
  9212. n_chargingProfile = n_chargingProfile + 1;
  9213. i = i + 1;
  9214. //DEBUG_INFO("chargingProfileId Found\n");
  9215. }
  9216. memset(word, 0, ARRAY_SIZE(word));
  9217. }
  9218. fclose(fptr1);
  9219. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  9220. }
  9221. //Check TxDefaultProfile_0.json exit
  9222. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9223. {
  9224. i = 0;
  9225. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  9226. //Check Charging Profile Count
  9227. while(fscanf(fptr1, "%s", word) != EOF)
  9228. {
  9229. //DEBUG_INFO("word=%s\n",word);
  9230. if(strstr(word, "chargingProfileId")!= NULL)
  9231. {
  9232. //DEBUG_INFO("test chargingProfileId \n");
  9233. n_chargingProfile = n_chargingProfile + 1;
  9234. i = i + 1;
  9235. //DEBUG_INFO("chargingProfileId Found\n");
  9236. }
  9237. memset(word, 0, ARRAY_SIZE(word));
  9238. }
  9239. fclose(fptr1);
  9240. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  9241. }
  9242. //Check TxDefaultProfile_%d.json
  9243. for(int j=1; j <= gunTotalNumber; j++)
  9244. {
  9245. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9246. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9247. if((access(fnametemp,F_OK))!=-1)
  9248. {
  9249. i = 0;
  9250. fptr1 = fopen(fnametemp, "r");
  9251. //Check Charging Profile Count
  9252. while(fscanf(fptr1, "%s", word) != EOF)
  9253. {
  9254. //DEBUG_INFO("word=%s\n",word);
  9255. if(strstr(word, "chargingProfileId")!= NULL)
  9256. {
  9257. //DEBUG_INFO("test chargingProfileId \n");
  9258. n_chargingProfile = n_chargingProfile + 1;
  9259. i = i + 1;
  9260. //DEBUG_INFO("chargingProfileId Found\n");
  9261. }
  9262. memset(word, 0, ARRAY_SIZE(word));
  9263. }
  9264. fclose(fptr1);
  9265. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9266. }
  9267. }
  9268. //Check TxProfile_%d.json
  9269. for(int j=1; j <= gunTotalNumber; j++)
  9270. {
  9271. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9272. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9273. if((access(fnametemp,F_OK))!=-1)
  9274. {
  9275. i = 0;
  9276. fptr1 = fopen(fnametemp, "r");
  9277. //Check Charging Profile Count
  9278. while(fscanf(fptr1, "%s", word) != EOF)
  9279. {
  9280. //DEBUG_INFO("word=%s\n",word);
  9281. if(strstr(word, "chargingProfileId")!= NULL)
  9282. {
  9283. //DEBUG_INFO("test chargingProfileId \n");
  9284. n_chargingProfile = n_chargingProfile + 1;
  9285. i = i + 1;
  9286. //DEBUG_INFO("chargingProfileId Found\n");
  9287. }
  9288. memset(word, 0, ARRAY_SIZE(word));
  9289. }
  9290. fclose(fptr1);
  9291. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9292. }
  9293. }
  9294. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  9295. {
  9296. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9297. goto end;
  9298. }
  9299. }
  9300. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9301. //**********************************Write to File********************************************************/
  9302. FILE *infile;
  9303. FILE *outfile;
  9304. infile = fopen (filename, "r");
  9305. outfile = fopen (tempfile, "w");
  9306. int d =0;
  9307. d = fgetc(infile);
  9308. rewind(infile);
  9309. if(d == EOF)
  9310. {
  9311. // Profile is empty
  9312. fprintf(outfile,"%s\n",payload);
  9313. fclose(infile);
  9314. fclose(outfile);
  9315. sprintf(rmFileCmd,"rm -f %s",filename);
  9316. system(rmFileCmd);
  9317. rename(tempfile, filename);
  9318. }
  9319. else
  9320. {
  9321. // Profile is not empty
  9322. char buf[2048]={0};
  9323. int ChargingProfileAdded = FALSE;
  9324. while (fgets(buf, sizeof(buf), infile) != NULL)
  9325. {
  9326. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9327. json_object *tmpChargingProfile;
  9328. tmpChargingProfile = json_tokener_parse(buf);
  9329. if(!is_error(SetChargingProfile))
  9330. {
  9331. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  9332. {
  9333. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  9334. }
  9335. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  9336. {
  9337. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  9338. {
  9339. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  9340. }
  9341. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  9342. {
  9343. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  9344. }
  9345. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9346. {
  9347. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  9348. }
  9349. }
  9350. }
  9351. json_object_put(tmpChargingProfile);
  9352. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  9353. {
  9354. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9355. {
  9356. //DEBUG_INFO("update set chargingProfile to file -0\n");
  9357. if(ChargingProfileAdded == FALSE)
  9358. {
  9359. fprintf(outfile,"%s\n",payload);
  9360. ChargingProfileAdded = TRUE;
  9361. }
  9362. }
  9363. else
  9364. {
  9365. if(tempstackLevelInt < stackLevelInt)
  9366. {
  9367. if(ChargingProfileAdded == FALSE)
  9368. {
  9369. fprintf(outfile,"%s\n",buf);
  9370. fprintf(outfile,"%s\n",payload);
  9371. ChargingProfileAdded = TRUE;
  9372. }
  9373. else
  9374. {
  9375. fprintf(outfile,"%s\n",buf);
  9376. }
  9377. }
  9378. else
  9379. {
  9380. if(ChargingProfileAdded == FALSE)
  9381. {
  9382. fprintf(outfile,"%s\n",buf);
  9383. fprintf(outfile,"%s\n",payload);
  9384. ChargingProfileAdded = TRUE;
  9385. }
  9386. else
  9387. {
  9388. fprintf(outfile,"%s\n",buf);
  9389. }
  9390. }
  9391. }
  9392. }
  9393. else
  9394. {
  9395. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9396. {
  9397. if(ChargingProfileAdded == FALSE)
  9398. {
  9399. fprintf(outfile,"%s\n",buf);
  9400. fprintf(outfile,"%s\n",payload);
  9401. ChargingProfileAdded = TRUE;
  9402. }
  9403. else
  9404. {
  9405. fprintf(outfile,"%s\n",buf);
  9406. }
  9407. }
  9408. else if(tempstackLevelInt < stackLevelInt)
  9409. {
  9410. if(ChargingProfileAdded == FALSE)
  9411. {
  9412. fprintf(outfile,"%s\n",buf);
  9413. fprintf(outfile,"%s\n",payload);
  9414. ChargingProfileAdded = TRUE;
  9415. }
  9416. else
  9417. {
  9418. fprintf(outfile,"%s\n",buf);
  9419. }
  9420. }
  9421. else
  9422. {
  9423. if(ChargingProfileAdded == FALSE)
  9424. {
  9425. fprintf(outfile,"%s\n",buf);
  9426. fprintf(outfile,"%s\n",payload);
  9427. ChargingProfileAdded = TRUE;
  9428. }
  9429. else
  9430. {
  9431. fprintf(outfile,"%s\n",buf);
  9432. }
  9433. }
  9434. }
  9435. } // end of while loop
  9436. fclose(infile);
  9437. fclose(outfile);
  9438. sprintf(rmFileCmd,"rm -f %s",filename);
  9439. system(rmFileCmd);
  9440. rename(tempfile, filename);
  9441. }
  9442. sleep(1);
  9443. result = TRUE;
  9444. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9445. end:
  9446. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  9447. {
  9448. if(connectorIdInt == 0)
  9449. {
  9450. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9451. {
  9452. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  9453. }
  9454. }
  9455. else
  9456. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  9457. }
  9458. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  9459. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9460. return result;
  9461. }
  9462. int handleTriggerMessageRequest(char *uuid, char *payload)
  9463. {
  9464. mtrace();
  9465. int result = FAIL;
  9466. int connectorIdIsNULL = FALSE;
  9467. int connectorIdInt =0;
  9468. char sstr[40]={0},sstrtemp[100]={ 0 };
  9469. char requestedMessagestr[40]={0};
  9470. char comfirmstr[20]={0};
  9471. int c = 0;
  9472. char *loc;
  9473. DEBUG_INFO("handleTriggerMessageRequest\n");
  9474. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  9475. strcpy(sstrtemp, stringtrimspace(payload));
  9476. c = 0;
  9477. loc = strstr(sstrtemp, "requestedMessage");
  9478. while (loc[3+strlen("requestedMessage")+c] != '\"')
  9479. {
  9480. sstr[c] = loc[3+strlen("requestedMessage")+c];
  9481. c++;
  9482. }
  9483. sstr[c] = '\0';
  9484. strcpy(requestedMessagestr, sstr);
  9485. c = 0;
  9486. loc = strstr(sstrtemp, "connectorId");
  9487. if(loc == NULL)
  9488. {
  9489. connectorIdIsNULL = TRUE;
  9490. }
  9491. else
  9492. {
  9493. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9494. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  9495. {
  9496. sstr[c] = loc[strlen("connectorId")+2+c];
  9497. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9498. c++;
  9499. }
  9500. sstr[c] = '\0';
  9501. connectorIdInt = atoi(sstr);
  9502. }
  9503. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  9504. {
  9505. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  9506. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  9507. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  9508. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  9509. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  9510. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  9511. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  9512. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  9513. {
  9514. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  9515. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9516. return TRUE;
  9517. }
  9518. else
  9519. {
  9520. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9521. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9522. }
  9523. }
  9524. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  9525. {
  9526. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  9527. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9528. return TRUE;
  9529. }
  9530. //==========================
  9531. // Trigger message
  9532. //==========================
  9533. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  9534. {
  9535. if((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) &&
  9536. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) &&
  9537. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) &&
  9538. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING) )
  9539. {
  9540. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  9541. }
  9542. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  9543. }
  9544. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  9545. {
  9546. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  9547. }
  9548. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  9549. {
  9550. //sendBootNotificationRequest();
  9551. server_sign = FALSE;
  9552. }
  9553. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  9554. {
  9555. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  9556. }
  9557. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  9558. {
  9559. if(connectorIdIsNULL == FALSE)
  9560. {
  9561. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9562. {
  9563. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  9564. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  9565. }
  9566. }
  9567. else
  9568. {
  9569. for(int idx=0;idx< gunTotalNumber;idx++)
  9570. {
  9571. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  9572. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  9573. }
  9574. }
  9575. }
  9576. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  9577. {
  9578. if(connectorIdIsNULL == FALSE)
  9579. {
  9580. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9581. {
  9582. cpinitateMsg.bits[connectorIdInt -1].StatusNotificationReq = 1;
  9583. }
  9584. }
  9585. else
  9586. {
  9587. for(int idx=0;idx< gunTotalNumber;idx++)
  9588. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  9589. }
  9590. }
  9591. return result;
  9592. }
  9593. int handleUnlockConnectorRequest(char *uuid, char *payload)
  9594. {
  9595. mtrace();
  9596. int result = FAIL;
  9597. int connectorIdInt =0;
  9598. char comfirmstr[20]={0};
  9599. int tempIndex = 0;
  9600. json_object *UnlockConnector;
  9601. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  9602. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  9603. UnlockConnector = json_tokener_parse(payload);
  9604. if(!is_error(UnlockConnector))
  9605. {
  9606. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  9607. {
  9608. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  9609. }
  9610. }
  9611. json_object_put(UnlockConnector);
  9612. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  9613. if(gunTotalNumber == 0)
  9614. {
  9615. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9616. goto end;
  9617. }
  9618. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  9619. {
  9620. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9621. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9622. goto end;
  9623. }
  9624. else
  9625. {
  9626. //check Transaction active
  9627. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  9628. {
  9629. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9630. {
  9631. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9632. }
  9633. else
  9634. {
  9635. tempIndex = connectorIdInt -1;
  9636. }
  9637. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9638. {
  9639. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9640. {
  9641. //stop Transaction
  9642. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9643. }
  9644. }
  9645. }
  9646. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  9647. {
  9648. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9649. {
  9650. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9651. }
  9652. else
  9653. {
  9654. tempIndex = connectorIdInt -1;
  9655. }
  9656. for (int index = 0; index < CCS_QUANTITY; index++)
  9657. {
  9658. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9659. {
  9660. //stop Transaction
  9661. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9662. }
  9663. }
  9664. }
  9665. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  9666. {
  9667. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9668. {
  9669. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9670. }
  9671. else
  9672. {
  9673. tempIndex = connectorIdInt -1;
  9674. }
  9675. for (int index = 0; index < GB_QUANTITY; index++)
  9676. {
  9677. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  9678. {
  9679. //stop Transaction
  9680. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9681. }
  9682. }
  9683. }
  9684. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  9685. {
  9686. tempIndex = connectorIdInt -1;
  9687. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9688. {
  9689. 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)))
  9690. {
  9691. //stop Transaction
  9692. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9693. }
  9694. }
  9695. }
  9696. else
  9697. {
  9698. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9699. {
  9700. tempIndex = 2;
  9701. }
  9702. else
  9703. {
  9704. tempIndex = connectorIdInt-1;
  9705. }
  9706. for (int index = 0; index < AC_QUANTITY; index++)
  9707. {
  9708. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9709. {
  9710. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9711. }
  9712. }
  9713. }
  9714. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  9715. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  9716. result = TRUE;
  9717. return result;
  9718. }
  9719. end:
  9720. //json_object_put(obj); --- remove temporally
  9721. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  9722. return result;
  9723. }
  9724. static char UpdateFirmwarepayloadData[300]={0};
  9725. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  9726. {
  9727. mtrace();
  9728. int result = FAIL;
  9729. pthread_t t;
  9730. sendUpdateFirmwareConfirmation(uuid);
  9731. memset(UpdateFirmwarepayloadData, 0, 300);
  9732. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  9733. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  9734. ////pthread_join(t, NULL); //
  9735. //pthread_detach(t);
  9736. //sendUpdateFirmwareConfirmation(uuid);
  9737. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  9738. return result;
  9739. }
  9740. void *UpdateFirmwareProcess(void *data)
  9741. {
  9742. pthread_detach(pthread_self());
  9743. mtrace();
  9744. int retriesInt =0, retryIntervalInt=0;
  9745. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  9746. int port=0;
  9747. char locationstr[160]={0}, retrieveDatestr[30]={0};
  9748. int isSuccess = 0;
  9749. char ftpbuf[200];
  9750. char temp[100];
  9751. char * pch;
  9752. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  9753. json_object *UpdateFirmware;
  9754. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  9755. if(!is_error(UpdateFirmware))
  9756. {
  9757. // Required data
  9758. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  9759. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  9760. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  9761. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  9762. // Optional data
  9763. if(json_object_object_get(UpdateFirmware, "retries"))
  9764. {
  9765. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  9766. }
  9767. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  9768. {
  9769. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  9770. }
  9771. }
  9772. json_object_put(UpdateFirmware);
  9773. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9774. memset(path, 0, ARRAY_SIZE(path));
  9775. system("rm -f /mnt/*");
  9776. if(strncmp(locationstr,"http", 4) == 0)
  9777. {
  9778. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9779. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  9780. // protocol, user, password, host, path);
  9781. sprintf(ftppath,"/%s", path);
  9782. DEBUG_INFO("locationstr: %s\n", locationstr);
  9783. DEBUG_INFO("protocol: %s\n",protocol);
  9784. DEBUG_INFO("host: %s\n",host);
  9785. DEBUG_INFO("path: %s\n",path);
  9786. DEBUG_INFO("ftppath: %s\n",ftppath);
  9787. int ftppathlen=strlen(ftppath);
  9788. int i=1;
  9789. char filenametemp[50];
  9790. while(i < ftppathlen)
  9791. {
  9792. int len=ftppathlen-i;
  9793. if(ftppath[len]== 47) // '/' ascll code: 47
  9794. {
  9795. DEBUG_INFO("compare '/' all right\n");
  9796. break;
  9797. }
  9798. i=i+1;
  9799. }
  9800. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9801. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9802. filenametemp[i+1] = 0;
  9803. do
  9804. {
  9805. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9806. sleep(3);
  9807. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9808. if(!isSuccess)
  9809. {
  9810. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9811. sleep(retryIntervalInt);
  9812. }
  9813. else
  9814. {
  9815. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9816. }
  9817. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  9818. }
  9819. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  9820. {
  9821. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9822. memset(temp, 0, ARRAY_SIZE(temp));
  9823. //DEBUG_INFO("locationstr=%s\n",locationstr);
  9824. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  9825. int ftppathlen=strlen(ftpbuf);
  9826. int i=1;
  9827. char filenametemp[50];
  9828. while(i < ftppathlen)
  9829. {
  9830. int len=ftppathlen-i;
  9831. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9832. {
  9833. DEBUG_INFO(" compare '/' all right\n");
  9834. break;
  9835. }
  9836. i=i+1;
  9837. }
  9838. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9839. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9840. filenametemp[i+1] = 0;
  9841. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9842. pch=strchr(temp,'@');
  9843. if(pch==NULL)
  9844. {
  9845. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9846. protocol, host, &port, path);
  9847. strcpy(user,"anonymous");
  9848. strcpy(password,"");
  9849. }
  9850. else
  9851. {
  9852. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9853. protocol, user, password, host, &port, path);
  9854. }
  9855. sscanf(host,"%[^/]%s",host1, path1);
  9856. sprintf(ftppath,"%s", path1);
  9857. //DEBUG_INFO("protocol =%s\n",protocol);
  9858. //DEBUG_INFO("user =%s\n",user);
  9859. //DEBUG_INFO("password =%s\n",password);
  9860. //DEBUG_INFO("host1 =%s\n",host1);
  9861. //DEBUG_INFO("port =%d\n",port);
  9862. //DEBUG_INFO("path1 =%s\n",path1);
  9863. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9864. //ftpFile(host, user, password, port, ftppath, fname);
  9865. //download firmware pthred
  9866. if(port == 0)
  9867. {
  9868. port = 21;
  9869. }
  9870. do
  9871. {
  9872. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9873. sleep(3);
  9874. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9875. if(!isSuccess)
  9876. {
  9877. //BulldogUtil.sleepMs(interval*1000);
  9878. DEBUG_INFO("Update firmware request and download file fail.\n");
  9879. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9880. sleep(retryIntervalInt);
  9881. }
  9882. else
  9883. {
  9884. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9885. }
  9886. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9887. }
  9888. else
  9889. {
  9890. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9891. }
  9892. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9893. pthread_exit(NULL);
  9894. }
  9895. //==========================================
  9896. // Handle server response routine
  9897. //==========================================
  9898. void handleAuthorizeResponse(char *payload, int gun_index)
  9899. {
  9900. mtrace();
  9901. char expiryDatestr[30]={0};
  9902. char parentIdTagstr[20]={0};
  9903. char statusstr[20]={0};
  9904. int expiryDateISNULL=FALSE;
  9905. int parentIdTagISNULL=FALSE;
  9906. DEBUG_INFO("handleAuthorizeResponse...\n");
  9907. json_object *Authorize;
  9908. Authorize = json_tokener_parse(payload);
  9909. if(!is_error(Authorize))
  9910. {
  9911. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  9912. {
  9913. // Required data
  9914. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  9915. // Optional data
  9916. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  9917. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  9918. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  9919. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  9920. }
  9921. }
  9922. json_object_put(Authorize);
  9923. if(expiryDateISNULL == FALSE)
  9924. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9925. if(parentIdTagISNULL == FALSE)
  9926. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9927. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9928. //Update idTag information to authorization cache if supproted
  9929. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9930. {
  9931. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  9932. }
  9933. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9934. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9935. authorizeRetryTimes = 0;
  9936. }
  9937. void handleBootNotificationResponse(char *payload, int gun_index)
  9938. {
  9939. mtrace();
  9940. char statusStr[12]={0};
  9941. char currentTimeStr[30]={0};
  9942. int intervalInt = 0;
  9943. struct tm tp;
  9944. char buf[28]={0};
  9945. char timebuf[50]={0};
  9946. DEBUG_INFO("handleBootNotificationResponse...\n");
  9947. json_object *BootNotification;
  9948. BootNotification = json_tokener_parse(payload);
  9949. if(!is_error(BootNotification))
  9950. {
  9951. // Required data
  9952. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  9953. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  9954. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  9955. }
  9956. json_object_put(BootNotification);
  9957. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9958. BootNotificationInterval = intervalInt;
  9959. HeartBeatWaitTime = intervalInt;
  9960. //write back to ShmOCPP16Data->BootNotification
  9961. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  9962. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9963. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  9964. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  9965. {
  9966. server_sign = TRUE;
  9967. server_pending =FALSE;
  9968. }
  9969. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  9970. {
  9971. server_pending = TRUE;
  9972. }
  9973. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9974. tp.tm_isdst = -1;
  9975. //time_t utc = mktime(&tp);
  9976. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9977. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9978. sprintf(timebuf,"date -s '%s'",buf);
  9979. system(timebuf);
  9980. srand(time(NULL));
  9981. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  9982. //==============================================
  9983. // RTC sync
  9984. //==============================================
  9985. system("/sbin/hwclock -w --systohc");
  9986. SetOcppConnStatus(TRUE);
  9987. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  9988. }
  9989. void handleDataTransferResponse(char *payload, int gun_index)
  9990. {
  9991. char sstr[160]={0};//sstr[200]={ 0 };
  9992. int c = 0;
  9993. char *loc;
  9994. DEBUG_INFO("handleDataTransferResponse ...\n");
  9995. loc = strstr(payload, "status");
  9996. printf("loc=%s\n",loc);
  9997. c = 0;
  9998. while (loc[3+strlen("status")+c] != '\"')
  9999. {
  10000. sstr[c] = loc[3+strlen("status")+c];
  10001. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10002. c++;
  10003. }
  10004. sstr[c] = '\0';
  10005. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  10006. }
  10007. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  10008. {
  10009. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  10010. //struct json_object *obj;
  10011. // obj = json_tokener_parse(payload);
  10012. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  10013. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  10014. //No fields are defined.
  10015. }
  10016. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  10017. {
  10018. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  10019. //struct json_object *obj;
  10020. // obj = json_tokener_parse(payload);
  10021. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  10022. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  10023. //No fields are defined.
  10024. }
  10025. void handleHeartbeatResponse(char *payload, int gun_index)
  10026. {
  10027. mtrace();
  10028. struct tm tp;
  10029. char buf[28]={0};
  10030. char timebuf[50]={0};
  10031. DEBUG_INFO("handleHeartbeatResponse...\n");
  10032. json_object *Heartbeat;
  10033. Heartbeat = json_tokener_parse(payload);
  10034. if(!is_error(Heartbeat))
  10035. {
  10036. // Required data
  10037. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  10038. }
  10039. json_object_put(Heartbeat);
  10040. if(FirstHeartBeat == 0)
  10041. {
  10042. FirstHeartBeat = 1;
  10043. DEBUG_INFO("FirstHeartBeat \n");
  10044. }
  10045. HeartBeatWithNOResponse = 0;
  10046. clientTime.Heartbeat=time((time_t*)NULL);
  10047. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10048. tp.tm_isdst = -1;
  10049. //time_t utc = mktime(&tp);
  10050. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  10051. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  10052. sprintf(timebuf,"date -s '%s'",buf);
  10053. system(timebuf);
  10054. //==============================================
  10055. // RTC sync
  10056. //==============================================
  10057. system("/sbin/hwclock -w --systohc");
  10058. }
  10059. void handleMeterValuesResponse(char *payload, int gun_index)
  10060. {
  10061. mtrace();
  10062. DEBUG_INFO("handleMeterValuesResponse...\n");
  10063. }
  10064. void handleStartTransactionResponse(char *payload, int gun_index)
  10065. {
  10066. mtrace();
  10067. //int transactionIdInt = 0;
  10068. FILE *outfile;
  10069. char data[100]={0};
  10070. DEBUG_INFO("handleStartTransactionResponse...\n");
  10071. json_object *StartTransaction;
  10072. StartTransaction = json_tokener_parse(payload);
  10073. if(!is_error(StartTransaction))
  10074. {
  10075. // Required data
  10076. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  10077. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  10078. // Optional data
  10079. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  10080. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  10081. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  10082. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  10083. }
  10084. json_object_put(StartTransaction);
  10085. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  10086. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  10087. //-----------Start : write to the Queue TransactionId file -----------------//
  10088. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  10089. {}
  10090. else
  10091. {
  10092. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  10093. if(log == NULL)
  10094. {
  10095. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  10096. return ;
  10097. }
  10098. else
  10099. {
  10100. fclose(log);
  10101. }
  10102. }
  10103. // open file for writing
  10104. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  10105. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  10106. {
  10107. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  10108. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  10109. fputs(data, outfile);
  10110. fclose (outfile);
  10111. }
  10112. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10113. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10114. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  10115. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  10116. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10117. }
  10118. void handleStatusNotificationResponse(char *payload, int gun_index)
  10119. {
  10120. mtrace();
  10121. DEBUG_INFO("handleStatusNotificationResponse...\n");
  10122. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  10123. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  10124. }
  10125. void handleStopTransactionnResponse(char *payload, int gun_index)
  10126. {
  10127. mtrace();
  10128. DEBUG_INFO("handleStopTransactionnResponse...\n");
  10129. json_object *StopTransaction;
  10130. StopTransaction = json_tokener_parse(payload);
  10131. if(!is_error(StopTransaction))
  10132. {
  10133. // Optional data
  10134. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  10135. {
  10136. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  10137. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  10138. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  10139. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  10140. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  10141. }
  10142. }
  10143. json_object_put(StopTransaction);
  10144. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  10145. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  10146. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10147. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10148. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  10149. }
  10150. //==========================================
  10151. // Handle Error routine
  10152. //==========================================
  10153. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  10154. {
  10155. mtrace();
  10156. #ifdef SystemLogMessage
  10157. DEBUG_INFO("errorCode: %s\n", errorCode);
  10158. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  10159. DEBUG_INFO("errorDetails: %s\n", payload);
  10160. #endif
  10161. }
  10162. //===============================================
  10163. // Common routine
  10164. //===============================================
  10165. int initialConfigurationTable(void)
  10166. {
  10167. //clock_t start_t, end_t, total_t;
  10168. FILE *fp;
  10169. FILE *outfile;
  10170. char str[512]={0};
  10171. char sstr[256]={0};
  10172. int c = 0;
  10173. char *loc;
  10174. int confVersion = 1;
  10175. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  10176. //start_t = clock();
  10177. //printf("Starting of the program, start_t = %ld\n", start_t);
  10178. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  10179. // Check configuration file size is correct
  10180. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  10181. {
  10182. struct stat st;
  10183. stat("/Storage/OCPP/OCPPConfiguration", &st);
  10184. if(st.st_size < 3100)
  10185. {
  10186. system("rm -f /Storage/OCPP/OCPPConfiguration");
  10187. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  10188. }
  10189. }
  10190. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  10191. {
  10192. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10193. if(outfile == NULL)
  10194. {
  10195. DEBUG_INFO("Error opening file\n");
  10196. return FALSE;
  10197. }
  10198. /*Core Profile*/
  10199. //AllowOfflineTxForUnknownId
  10200. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10201. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10202. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  10203. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10204. //AuthorizationCacheEnabled
  10205. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10206. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10207. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10208. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10209. //AuthorizeRemoteTxRequests
  10210. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10211. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10212. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  10213. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10214. //BlinkRepeat
  10215. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10216. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10217. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10218. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10219. //ClockAlignedDataInterval
  10220. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10221. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10222. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10223. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10224. //ConnectionTimeOut
  10225. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10226. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10227. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10228. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10229. //GetConfigurationMaxKeys
  10230. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10231. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10232. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  10233. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10234. // HeartbeatInterval
  10235. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10236. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10237. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  10238. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10239. // LightIntensity
  10240. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10241. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10242. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10243. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10244. // LocalAuthorizeOffline
  10245. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  10246. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10247. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10248. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10249. // LocalPreAuthorize
  10250. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10251. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10252. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10253. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10254. // MaxEnergyOnInvalidId
  10255. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10256. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10257. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10258. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10259. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10260. // MeterValuesAlignedData
  10261. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10262. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10263. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10264. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10265. else
  10266. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10267. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10268. // MeterValuesAlignedDataMaxLength
  10269. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10270. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10271. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10272. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  10273. else
  10274. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "9" );
  10275. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10276. // MeterValuesSampledData
  10277. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10278. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10279. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10280. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10281. else
  10282. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10283. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10284. // MeterValuesSampledDataMaxLength
  10285. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10286. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10287. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10288. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  10289. else
  10290. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "9" );
  10291. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10292. // MeterValueSampleInterval
  10293. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10294. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10295. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  10296. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10297. // MinimumStatusDuration
  10298. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10299. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10300. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  10301. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  10302. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10303. // NumberOfConnectors
  10304. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10305. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10306. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10307. {
  10308. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10309. }
  10310. else
  10311. {
  10312. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10313. }
  10314. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10315. // ResetRetries
  10316. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10317. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10318. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10319. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10320. // ConnectorPhaseRotation
  10321. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10322. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10323. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10324. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10325. // ConnectorPhaseRotationMaxLength
  10326. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10327. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10328. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10329. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10330. // StopTransactionOnEVSideDisconnect
  10331. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10332. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10333. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10334. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10335. // StopTransactionOnInvalidId
  10336. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  10337. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10338. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10339. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10340. // StopTxnAlignedData
  10341. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  10342. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10343. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10344. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10345. // StopTxnAlignedDataMaxLength
  10346. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10347. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10348. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10349. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10350. // StopTxnSampledData
  10351. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10352. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10353. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10354. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10355. else
  10356. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10357. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10358. // StopTxnSampledDataMaxLength
  10359. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10360. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10361. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10362. {
  10363. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  10364. }
  10365. else
  10366. {
  10367. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  10368. }
  10369. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10370. // SupportedFeatureProfiles
  10371. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10372. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10373. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10374. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10375. // SupportedFeatureProfilesMaxLength
  10376. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10377. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10378. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10379. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10380. // TransactionMessageAttempts
  10381. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10382. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10383. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10384. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10385. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10386. // TransactionMessageRetryInterval
  10387. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10388. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10389. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10390. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10391. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10392. // UnlockConnectorOnEVSideDisconnect
  10393. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10394. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10395. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10396. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10397. // WebSocketPingInterval
  10398. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10399. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10400. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10401. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10402. // QueueOffLineStartTransactionMessage
  10403. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  10404. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10405. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10406. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10407. // AuthorizationKey
  10408. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  10409. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  10410. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "" );
  10411. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  10412. // SecurityProfile
  10413. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  10414. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  10415. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "0" );
  10416. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  10417. // DefaultPrice
  10418. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  10419. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  10420. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  10421. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  10422. // CustomDisplayCostAndPrice
  10423. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  10424. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  10425. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  10426. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  10427. // CustomIdleFeeAfterStop
  10428. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  10429. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  10430. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  10431. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  10432. // Configuration Version
  10433. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  10434. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  10435. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  10436. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  10437. //* Local Auth List Management Profile*/
  10438. #if 0
  10439. //For OCTT Test Case
  10440. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10441. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  10442. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10443. #endif
  10444. #if 1
  10445. //LocalAuthListEnabled
  10446. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10447. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10448. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10449. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10450. #endif
  10451. //LocalAuthListMaxLength
  10452. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10453. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10454. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10455. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10456. //SendLocalListMaxLength
  10457. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10458. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10459. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  10460. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10461. //ReserveConnectorZeroSupported
  10462. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10463. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10464. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10465. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10466. //* Smart Charging Profile */
  10467. //ChargeProfileMaxStackLevel
  10468. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10469. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10470. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10471. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10472. // ChargingScheduleAllowedChargingRateUnit
  10473. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10474. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10475. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10476. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10477. // ChargingScheduleMaxPeriods
  10478. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10479. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10480. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10481. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10482. // ConnectorSwitch3to1PhaseSupported
  10483. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10484. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10485. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10486. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10487. // MaxChargingProfilesInstalled
  10488. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10489. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10490. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  10491. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10492. fclose(outfile);
  10493. }
  10494. else
  10495. {
  10496. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10497. char keystr[60]={0};
  10498. char readonlystr[10]={0};
  10499. char valuestr[256]={0};
  10500. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10501. if(fp == NULL) {
  10502. DEBUG_INFO("Error opening file");
  10503. return FALSE;
  10504. }
  10505. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  10506. {
  10507. //DEBUG_INFO("Get Configuration \n");
  10508. if(strlen(str) > 0)
  10509. {
  10510. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10511. //*************************key*********************************/
  10512. if(strstr(str, "key") != NULL)
  10513. {
  10514. loc = strstr(str, "key");
  10515. c = 0;
  10516. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10517. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  10518. {
  10519. sstr[c] = loc[strlen("key")+3+c];
  10520. c++;
  10521. }
  10522. sstr[c] = '\0';
  10523. strcpy(keystr,sstr);
  10524. }
  10525. //*************************readonly*********************************/
  10526. if(strstr(str, "readonly") != NULL)
  10527. {
  10528. loc = strstr(str, "readonly");
  10529. c = 0;
  10530. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10531. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  10532. {
  10533. sstr[c] = loc[strlen("readonly")+2+c];
  10534. c++;
  10535. }
  10536. sstr[c] = '\0';
  10537. strcpy(readonlystr,sstr);
  10538. }
  10539. //*************************value*********************************/
  10540. if(strstr(str, "value") != NULL)
  10541. {
  10542. loc = strstr(str, "value");
  10543. c = 0;
  10544. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10545. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  10546. {
  10547. sstr[c] = loc[strlen("value")+3+c];
  10548. c++;
  10549. }
  10550. sstr[c] = '\0';
  10551. strcpy(valuestr,sstr);
  10552. }
  10553. // DEBUG_INFO("keystr=%s\n",keystr);
  10554. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10555. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10556. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10557. {
  10558. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10559. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10560. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10561. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10562. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10563. }
  10564. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10565. {
  10566. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10567. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10568. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10569. }
  10570. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10571. {
  10572. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10573. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10574. }
  10575. if(strcmp(keystr, "BlinkRepeat") == 0)
  10576. {
  10577. //Charger.BlinkRepeat = Integer.parseInt(value);
  10578. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10579. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10580. }
  10581. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10582. {
  10583. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10584. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10585. }
  10586. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10587. {
  10588. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10589. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10590. }
  10591. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10592. {
  10593. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10594. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  10595. }
  10596. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10597. {
  10598. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10599. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10600. HeartBeatWaitTime = atoi(valuestr);
  10601. }
  10602. if(strcmp(keystr, "LightIntensity") == 0)
  10603. {
  10604. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10605. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10606. }
  10607. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10608. {
  10609. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10610. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10611. }
  10612. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10613. {
  10614. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10615. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10616. }
  10617. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10618. {
  10619. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10620. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10621. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10622. }
  10623. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10624. {
  10625. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10626. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10627. }
  10628. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10629. {
  10630. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10631. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10632. }
  10633. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10634. {
  10635. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10636. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10637. }
  10638. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10639. {
  10640. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10641. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10642. }
  10643. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10644. {
  10645. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10646. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10647. }
  10648. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10649. {
  10650. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10651. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10652. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10653. }
  10654. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10655. {
  10656. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10657. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10658. }
  10659. if(strcmp(keystr, "ResetRetries") == 0)
  10660. {
  10661. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10662. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10663. }
  10664. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10665. {
  10666. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10667. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10668. }
  10669. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10670. {
  10671. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10672. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10673. }
  10674. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10675. {
  10676. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10677. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10678. }
  10679. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10680. {
  10681. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10682. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10683. }
  10684. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10685. {
  10686. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10687. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10688. }
  10689. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10690. {
  10691. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10692. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10693. }
  10694. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10695. {
  10696. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10697. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10698. }
  10699. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10700. {
  10701. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10702. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10703. }
  10704. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10705. {
  10706. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10707. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10708. }
  10709. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10710. {
  10711. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10712. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10713. }
  10714. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10715. {
  10716. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10717. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10718. TransactionMessageAttemptsValue = atoi(valuestr);
  10719. }
  10720. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10721. {
  10722. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10723. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10724. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10725. }
  10726. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10727. {
  10728. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10729. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10730. }
  10731. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10732. {
  10733. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10734. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10735. }
  10736. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  10737. {
  10738. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10739. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  10740. }
  10741. if(strcmp(keystr, "AuthorizationKey") == 0)
  10742. {
  10743. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10744. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  10745. }
  10746. if(strcmp(keystr, "SecurityProfile") == 0)
  10747. {
  10748. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10749. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  10750. }
  10751. if(strcmp(keystr, "DefaultPrice") == 0)
  10752. {
  10753. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10754. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  10755. }
  10756. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  10757. {
  10758. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10759. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  10760. }
  10761. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  10762. {
  10763. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10764. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  10765. }
  10766. if(strcmp(keystr, "ConfigurationVersion") == 0)
  10767. {
  10768. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10769. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  10770. }
  10771. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10772. {
  10773. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10774. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10775. }
  10776. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10777. {
  10778. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10779. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10780. }
  10781. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10782. {
  10783. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10784. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10785. }
  10786. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10787. {
  10788. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10789. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10790. }
  10791. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10792. {
  10793. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10794. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10795. }
  10796. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10797. {
  10798. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10799. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10800. }
  10801. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10802. {
  10803. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10804. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10805. }
  10806. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10807. {
  10808. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10809. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10810. }
  10811. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10812. {
  10813. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10814. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10815. }
  10816. }
  10817. }
  10818. fclose(fp);
  10819. }
  10820. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  10821. {
  10822. return PASS;
  10823. }
  10824. else
  10825. {
  10826. return FAIL;
  10827. }
  10828. }
  10829. void StoreConfigurationTable(void)
  10830. {
  10831. FILE *outfile;
  10832. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10833. if(outfile == NULL)
  10834. {
  10835. DEBUG_INFO("Error opening file");
  10836. return ;
  10837. }
  10838. /*Core Profile*/
  10839. //AllowOfflineTxForUnknownId
  10840. /*
  10841. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10842. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10843. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10844. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10845. */
  10846. //DEBUG_INFO("data=%s\n",data);
  10847. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10848. //AuthorizationCacheEnabled
  10849. /*
  10850. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10851. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10852. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10853. */
  10854. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10855. //AuthorizeRemoteTxRequests
  10856. /*
  10857. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10858. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10859. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10860. */
  10861. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10862. //BlinkRepeat
  10863. /*
  10864. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10865. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10866. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10867. */
  10868. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10869. //ClockAlignedDataInterval
  10870. /*
  10871. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10872. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10874. */
  10875. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10876. //ConnectionTimeOut
  10877. /*
  10878. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10879. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10880. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10881. */
  10882. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10883. //GetConfigurationMaxKeys
  10884. /*
  10885. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10886. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10888. */
  10889. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10890. // HeartbeatInterval
  10891. /*
  10892. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10893. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10894. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10895. */
  10896. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10897. // LightIntensity
  10898. /*
  10899. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10900. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10901. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10902. */
  10903. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10904. // LocalAuthorizeOffline
  10905. /*
  10906. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10907. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10908. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10909. */
  10910. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10911. // LocalPreAuthorize
  10912. /*
  10913. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10914. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10915. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10916. */
  10917. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10918. // MaxEnergyOnInvalidId
  10919. /*
  10920. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10921. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10922. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10923. */
  10924. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10925. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10926. // MeterValuesAlignedData
  10927. /*
  10928. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10929. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10930. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10931. */
  10932. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10933. // MeterValuesAlignedDataMaxLength
  10934. /*
  10935. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10936. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10937. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10938. */
  10939. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10940. // MeterValuesSampledData
  10941. /*
  10942. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10943. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10944. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10945. */
  10946. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10947. // MeterValuesSampledDataMaxLength
  10948. /*
  10949. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10950. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10951. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10952. */
  10953. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10954. // MeterValueSampleInterval
  10955. /*
  10956. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10957. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10958. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10959. */
  10960. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10961. // MinimumStatusDuration
  10962. /*
  10963. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10964. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10965. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10966. */
  10967. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10968. // NumberOfConnectors
  10969. /*
  10970. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10971. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10972. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10973. {
  10974. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10975. }
  10976. else
  10977. {
  10978. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10979. }
  10980. */
  10981. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10982. // ResetRetries
  10983. /*
  10984. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10985. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10986. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10987. */
  10988. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10989. // ConnectorPhaseRotation
  10990. /*
  10991. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10992. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10993. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10994. */
  10995. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10996. // ConnectorPhaseRotationMaxLength
  10997. /*
  10998. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10999. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  11000. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  11001. */
  11002. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  11003. // StopTransactionOnEVSideDisconnect
  11004. /*
  11005. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  11006. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  11007. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  11008. */
  11009. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  11010. // StopTransactionOnInvalidId
  11011. /*
  11012. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  11013. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  11014. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  11015. */
  11016. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  11017. // StopTxnAlignedData
  11018. /*
  11019. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  11020. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  11021. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  11022. */
  11023. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  11024. // StopTxnAlignedDataMaxLength
  11025. /*
  11026. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  11027. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  11028. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  11029. */
  11030. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  11031. // StopTxnSampledData
  11032. /*
  11033. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  11034. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  11035. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  11036. */
  11037. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  11038. // StopTxnSampledDataMaxLength
  11039. /*
  11040. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  11041. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  11042. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  11043. */
  11044. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  11045. // SupportedFeatureProfiles
  11046. /*
  11047. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  11048. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  11049. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  11050. */
  11051. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  11052. // SupportedFeatureProfilesMaxLength
  11053. /*
  11054. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  11055. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  11056. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  11057. */
  11058. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  11059. // TransactionMessageAttempts
  11060. /*
  11061. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  11062. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  11063. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  11064. */
  11065. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11066. // TransactionMessageRetryInterval
  11067. /*
  11068. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  11069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  11070. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  11071. */
  11072. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11073. // UnlockConnectorOnEVSideDisconnect
  11074. /*
  11075. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  11076. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  11077. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  11078. */
  11079. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  11080. // WebSocketPingInterval
  11081. /*
  11082. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  11083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  11084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  11085. */
  11086. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  11087. // QueueOffLineStartTransactionMessage
  11088. /*
  11089. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  11090. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  11091. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  11092. */
  11093. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  11094. // AuthorizationKey
  11095. /*
  11096. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  11097. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  11098. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  11099. */
  11100. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  11101. // SecurityProfile
  11102. /*
  11103. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  11104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  11105. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  11106. */
  11107. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  11108. // DefaultPrice
  11109. /*
  11110. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  11111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  11112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  11113. */
  11114. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  11115. // CustomDisplayCostAndPrice
  11116. /*
  11117. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  11118. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  11119. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  11120. */
  11121. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  11122. // CustomIdleFeeAfterStop
  11123. /*
  11124. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  11125. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  11126. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  11127. */
  11128. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  11129. // ConfigurationVersion
  11130. /*
  11131. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  11132. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  11133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  11134. */
  11135. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  11136. //* Local Auth List Management Profile*/
  11137. //LocalAuthListEnabled
  11138. /*
  11139. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11140. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  11141. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11142. */
  11143. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11144. //LocalAuthListMaxLength
  11145. /*
  11146. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  11147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  11148. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  11149. */
  11150. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  11151. //SendLocalListMaxLength
  11152. /*
  11153. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  11154. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  11155. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  11156. */
  11157. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  11158. //ReserveConnectorZeroSupported
  11159. /*
  11160. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  11161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  11162. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  11163. */
  11164. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11165. //* Smart Charging Profile */
  11166. //ChargeProfileMaxStackLevel
  11167. /*
  11168. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  11169. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  11170. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  11171. */
  11172. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11173. // ChargingScheduleAllowedChargingRateUnit
  11174. /*
  11175. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  11176. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  11177. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  11178. */
  11179. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11180. // ChargingScheduleMaxPeriods
  11181. /*
  11182. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  11183. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  11184. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  11185. */
  11186. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11187. // ConnectorSwitch3to1PhaseSupported
  11188. /*
  11189. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11190. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11191. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  11192. */
  11193. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11194. // MaxChargingProfilesInstalled
  11195. /*
  11196. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11197. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11198. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  11199. */
  11200. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11201. fclose(outfile);
  11202. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11203. }
  11204. void getKeyValue(char *keyReq)
  11205. {
  11206. int isEmpty = FALSE;
  11207. int isKnowKey = FALSE;
  11208. DEBUG_INFO("keyReq = %s\n", keyReq);
  11209. if((keyReq == NULL) || (strlen(keyReq) == 0))
  11210. isEmpty = TRUE;
  11211. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  11212. {
  11213. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  11214. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  11215. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11216. {
  11217. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  11218. }
  11219. else
  11220. {
  11221. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  11222. }
  11223. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  11224. isKnowKey = TRUE;
  11225. }
  11226. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  11227. {
  11228. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  11229. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  11230. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11231. {
  11232. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  11233. }
  11234. else
  11235. {
  11236. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  11237. }
  11238. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  11239. isKnowKey = TRUE;
  11240. }
  11241. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  11242. {
  11243. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  11244. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  11245. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11246. {
  11247. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  11248. }
  11249. else
  11250. {
  11251. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  11252. }
  11253. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  11254. isKnowKey = TRUE;
  11255. }
  11256. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  11257. {
  11258. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  11259. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  11260. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11261. {
  11262. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  11263. }
  11264. else
  11265. {
  11266. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  11267. }
  11268. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  11269. isKnowKey = TRUE;
  11270. }
  11271. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  11272. {
  11273. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  11274. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  11275. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11276. {
  11277. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  11278. }
  11279. else
  11280. {
  11281. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  11282. }
  11283. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  11284. isKnowKey = TRUE;
  11285. }
  11286. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  11287. {
  11288. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  11289. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  11290. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11291. {
  11292. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  11293. }
  11294. else
  11295. {
  11296. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  11297. }
  11298. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  11299. isKnowKey = TRUE;
  11300. }
  11301. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  11302. {
  11303. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  11304. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  11305. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11306. {
  11307. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  11308. }
  11309. else
  11310. {
  11311. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  11312. }
  11313. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  11314. isKnowKey = TRUE;
  11315. }
  11316. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  11317. {
  11318. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  11319. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  11320. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11321. {
  11322. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  11323. }
  11324. else
  11325. {
  11326. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  11327. }
  11328. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  11329. isKnowKey = TRUE;
  11330. }
  11331. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  11332. {
  11333. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  11334. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  11335. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11336. {
  11337. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  11338. }
  11339. else
  11340. {
  11341. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  11342. }
  11343. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  11344. isKnowKey = TRUE;
  11345. }
  11346. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  11347. {
  11348. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  11349. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  11350. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11351. {
  11352. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  11353. }
  11354. else
  11355. {
  11356. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  11357. }
  11358. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  11359. isKnowKey = TRUE;
  11360. }
  11361. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  11362. {
  11363. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  11364. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  11365. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11366. {
  11367. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  11368. }
  11369. else
  11370. {
  11371. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  11372. }
  11373. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  11374. isKnowKey = TRUE;
  11375. }
  11376. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  11377. {
  11378. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  11379. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  11380. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11381. {
  11382. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11383. }
  11384. else
  11385. {
  11386. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11387. }
  11388. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  11389. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  11390. isKnowKey = TRUE;
  11391. }
  11392. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  11393. {
  11394. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  11395. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  11396. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11397. {
  11398. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11399. }
  11400. else
  11401. {
  11402. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11403. }
  11404. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  11405. isKnowKey = TRUE;
  11406. }
  11407. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  11408. {
  11409. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  11410. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  11411. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11412. {
  11413. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11414. }
  11415. else
  11416. {
  11417. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11418. }
  11419. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  11420. isKnowKey = TRUE;
  11421. }
  11422. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  11423. {
  11424. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  11425. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  11426. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11427. {
  11428. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  11429. }
  11430. else
  11431. {
  11432. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  11433. }
  11434. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  11435. isKnowKey = TRUE;
  11436. }
  11437. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  11438. {
  11439. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  11440. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  11441. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11442. {
  11443. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11444. }
  11445. else
  11446. {
  11447. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11448. }
  11449. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  11450. isKnowKey = TRUE;
  11451. }
  11452. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  11453. {
  11454. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  11455. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  11456. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11457. {
  11458. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  11459. }
  11460. else
  11461. {
  11462. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  11463. }
  11464. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  11465. isKnowKey = TRUE;
  11466. }
  11467. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  11468. {
  11469. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  11470. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  11471. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11472. {
  11473. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  11474. }
  11475. else
  11476. {
  11477. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  11478. }
  11479. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  11480. isKnowKey = TRUE;
  11481. }
  11482. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  11483. {
  11484. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  11485. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  11486. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11487. {
  11488. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  11489. }
  11490. else
  11491. {
  11492. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  11493. }
  11494. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  11495. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  11496. isKnowKey = TRUE;
  11497. }
  11498. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  11499. {
  11500. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  11501. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11502. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11503. {
  11504. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11505. }
  11506. else
  11507. {
  11508. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11509. }
  11510. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11511. isKnowKey = TRUE;
  11512. }
  11513. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11514. {
  11515. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11517. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11518. {
  11519. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11520. }
  11521. else
  11522. {
  11523. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11524. }
  11525. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11526. isKnowKey = TRUE;
  11527. }
  11528. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11529. {
  11530. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11531. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11532. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11533. {
  11534. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11535. }
  11536. else
  11537. {
  11538. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11539. }
  11540. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11541. isKnowKey = TRUE;
  11542. }
  11543. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11544. {
  11545. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11546. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11547. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11548. {
  11549. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11550. }
  11551. else
  11552. {
  11553. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11554. }
  11555. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11556. isKnowKey = TRUE;
  11557. }
  11558. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11559. {
  11560. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11561. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11562. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11563. {
  11564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11565. }
  11566. else
  11567. {
  11568. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11569. }
  11570. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11571. isKnowKey = TRUE;
  11572. }
  11573. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11574. {
  11575. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11576. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11577. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11578. {
  11579. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11580. }
  11581. else
  11582. {
  11583. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11584. }
  11585. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11586. isKnowKey = TRUE;
  11587. }
  11588. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11589. {
  11590. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11591. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11592. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11593. {
  11594. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11595. }
  11596. else
  11597. {
  11598. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11599. }
  11600. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11601. isKnowKey = TRUE;
  11602. }
  11603. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11604. {
  11605. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11606. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11607. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11608. {
  11609. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11610. }
  11611. else
  11612. {
  11613. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11614. }
  11615. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11616. isKnowKey = TRUE;
  11617. }
  11618. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11619. {
  11620. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11621. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11622. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11623. {
  11624. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11625. }
  11626. else
  11627. {
  11628. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11629. }
  11630. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11631. isKnowKey = TRUE;
  11632. }
  11633. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11634. {
  11635. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11636. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11637. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11638. {
  11639. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11640. }
  11641. else
  11642. {
  11643. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11644. }
  11645. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11646. isKnowKey = TRUE;
  11647. }
  11648. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11649. {
  11650. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11651. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11652. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11653. {
  11654. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11655. }
  11656. else
  11657. {
  11658. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11659. }
  11660. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11661. isKnowKey = TRUE;
  11662. }
  11663. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11664. {
  11665. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11666. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11667. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11668. {
  11669. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11670. }
  11671. else
  11672. {
  11673. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11674. }
  11675. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11676. isKnowKey = TRUE;
  11677. }
  11678. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11679. {
  11680. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11681. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11682. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11683. {
  11684. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11685. }
  11686. else
  11687. {
  11688. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11689. }
  11690. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11691. isKnowKey = TRUE;
  11692. }
  11693. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11694. {
  11695. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11696. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11697. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11698. {
  11699. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11700. }
  11701. else
  11702. {
  11703. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11704. }
  11705. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11706. isKnowKey = TRUE;
  11707. }
  11708. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11709. {
  11710. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11711. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11712. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11713. {
  11714. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11715. }
  11716. else
  11717. {
  11718. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11719. }
  11720. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11721. isKnowKey = TRUE;
  11722. }
  11723. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  11724. {
  11725. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  11726. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  11727. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  11728. {
  11729. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  11730. }
  11731. else
  11732. {
  11733. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  11734. }
  11735. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  11736. isKnowKey = TRUE;
  11737. }
  11738. /*
  11739. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  11740. {
  11741. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  11742. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  11743. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  11744. {
  11745. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  11746. }
  11747. else
  11748. {
  11749. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  11750. }
  11751. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  11752. isKnowKey = TRUE;
  11753. }*/
  11754. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  11755. {
  11756. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  11757. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  11758. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  11759. {
  11760. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  11761. }
  11762. else
  11763. {
  11764. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  11765. }
  11766. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  11767. isKnowKey = TRUE;
  11768. }
  11769. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  11770. {
  11771. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  11772. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  11773. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  11774. {
  11775. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  11776. }
  11777. else
  11778. {
  11779. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  11780. }
  11781. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  11782. isKnowKey = TRUE;
  11783. }
  11784. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  11785. {
  11786. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  11787. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  11788. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  11789. {
  11790. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  11791. }
  11792. else
  11793. {
  11794. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  11795. }
  11796. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  11797. isKnowKey = TRUE;
  11798. }
  11799. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  11800. {
  11801. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  11802. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  11803. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  11804. {
  11805. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  11806. }
  11807. else
  11808. {
  11809. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  11810. }
  11811. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  11812. isKnowKey = TRUE;
  11813. }
  11814. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  11815. {
  11816. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  11817. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  11818. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  11819. {
  11820. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  11821. }
  11822. else
  11823. {
  11824. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  11825. }
  11826. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  11827. isKnowKey = TRUE;
  11828. }
  11829. #if 1
  11830. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11831. {
  11832. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11833. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11834. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11835. {
  11836. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11837. }
  11838. else
  11839. {
  11840. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11841. }
  11842. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11843. isKnowKey = TRUE;
  11844. }
  11845. #endif
  11846. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11847. {
  11848. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11849. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11850. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11851. {
  11852. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11853. }
  11854. else
  11855. {
  11856. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11857. }
  11858. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11859. isKnowKey = TRUE;
  11860. }
  11861. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11862. {
  11863. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11864. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11865. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11866. {
  11867. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11868. }
  11869. else
  11870. {
  11871. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11872. }
  11873. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11874. isKnowKey = TRUE;
  11875. }
  11876. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11877. {
  11878. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11879. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11880. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11881. {
  11882. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11883. }
  11884. else
  11885. {
  11886. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11887. }
  11888. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11889. isKnowKey = TRUE;
  11890. }
  11891. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11892. {
  11893. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11894. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11895. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11896. {
  11897. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11898. }
  11899. else
  11900. {
  11901. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11902. }
  11903. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11904. isKnowKey = TRUE;
  11905. }
  11906. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11907. {
  11908. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11909. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11910. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11911. {
  11912. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11913. }
  11914. else
  11915. {
  11916. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11917. }
  11918. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11919. isKnowKey = TRUE;
  11920. }
  11921. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11922. {
  11923. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11924. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11925. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11926. {
  11927. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11928. }
  11929. else
  11930. {
  11931. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11932. }
  11933. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11934. isKnowKey = TRUE;
  11935. }
  11936. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11937. {
  11938. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11939. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11940. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11941. {
  11942. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11943. }
  11944. else
  11945. {
  11946. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11947. }
  11948. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11949. isKnowKey = TRUE;
  11950. }
  11951. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11952. {
  11953. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11954. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11955. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11956. {
  11957. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11958. }
  11959. else
  11960. {
  11961. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11962. }
  11963. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11964. isKnowKey = TRUE;
  11965. }
  11966. //=========================================================
  11967. if(!isEmpty && !isKnowKey)
  11968. {
  11969. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11970. strcpy(unknownkey[UnknownKeynum], keyReq);
  11971. UnknownKeynum = UnknownKeynum + 1;
  11972. }
  11973. }
  11974. void processUnkownKey(void)
  11975. {
  11976. DEBUG_INFO("processUnkownKey...\n");
  11977. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11978. for(int index=0; index < UnknownKeynum; index++)
  11979. {
  11980. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11981. {
  11982. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11983. }
  11984. }
  11985. }
  11986. int setKeyValue(char *key, char *value)
  11987. {
  11988. int isSuccess = NotSupported;
  11989. int check_ascii=0;
  11990. char str[256]={0};
  11991. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  11992. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11993. {
  11994. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11995. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11996. {
  11997. strcpy(str, (const char*)value);
  11998. for(int i = 0; str[i]; i++){
  11999. str[i] = tolower(str[i]);
  12000. }
  12001. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12002. isSuccess = ConfigurationStatus_Accepted;
  12003. }
  12004. else
  12005. {
  12006. isSuccess = ConfigurationStatus_Rejected;
  12007. }
  12008. }
  12009. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  12010. {
  12011. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  12012. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  12013. {
  12014. strcpy(str, (const char*)value);
  12015. for(int i = 0; str[i]; i++){
  12016. str[i] = tolower(str[i]);
  12017. }
  12018. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12019. isSuccess = ConfigurationStatus_Accepted;
  12020. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  12021. }
  12022. else
  12023. {
  12024. isSuccess = ConfigurationStatus_Rejected;
  12025. }
  12026. }
  12027. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  12028. {
  12029. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  12030. {
  12031. strcpy(str, (const char*)value);
  12032. for(int i = 0; str[i]; i++)
  12033. {
  12034. str[i] = tolower(str[i]);
  12035. }
  12036. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  12037. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12038. isSuccess = ConfigurationStatus_Accepted;
  12039. }
  12040. else
  12041. {
  12042. isSuccess = ConfigurationStatus_Rejected;
  12043. }
  12044. }
  12045. if(strcmp(key, "BlinkRepeat") == 0)
  12046. {
  12047. //Charger.BlinkRepeat = Integer.parseInt(value);
  12048. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  12049. {
  12050. check_ascii = value[0];
  12051. if( (check_ascii < 48) || (check_ascii > 57) )
  12052. {
  12053. isSuccess = ConfigurationStatus_Rejected;
  12054. }
  12055. else
  12056. {
  12057. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  12058. isSuccess = ConfigurationStatus_Accepted;
  12059. }
  12060. }
  12061. else
  12062. {
  12063. isSuccess = ConfigurationStatus_Rejected;
  12064. }
  12065. }
  12066. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  12067. {
  12068. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  12069. {
  12070. check_ascii = value[0];
  12071. if( (check_ascii < 48) || (check_ascii > 57) )
  12072. {
  12073. isSuccess = ConfigurationStatus_Rejected;
  12074. }
  12075. else
  12076. {
  12077. if((atoi(value) == 0) || (atoi(value) >= 10))
  12078. {
  12079. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  12080. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  12081. isSuccess = ConfigurationStatus_Accepted;
  12082. }
  12083. else
  12084. isSuccess = ConfigurationStatus_Rejected;
  12085. }
  12086. }
  12087. else
  12088. {
  12089. isSuccess = ConfigurationStatus_Rejected;
  12090. }
  12091. }
  12092. if(strcmp(key, "ConnectionTimeOut") == 0 )
  12093. {
  12094. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  12095. {
  12096. check_ascii = value[0];
  12097. if( (check_ascii < 48) || (check_ascii > 57) )
  12098. {
  12099. isSuccess = ConfigurationStatus_Rejected;
  12100. }
  12101. else
  12102. {
  12103. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  12104. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  12105. isSuccess = ConfigurationStatus_Accepted;
  12106. }
  12107. }
  12108. else
  12109. {
  12110. isSuccess = ConfigurationStatus_Rejected;
  12111. }
  12112. }
  12113. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  12114. {
  12115. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  12116. {
  12117. check_ascii = value[0];
  12118. if( (check_ascii < 48) || (check_ascii > 57) )
  12119. {
  12120. isSuccess = ConfigurationStatus_Rejected;
  12121. }
  12122. else
  12123. {
  12124. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  12125. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  12126. isSuccess = ConfigurationStatus_Accepted;
  12127. }
  12128. }
  12129. else
  12130. {
  12131. isSuccess = ConfigurationStatus_Rejected;
  12132. }
  12133. }
  12134. if(strcmp(key, "HeartbeatInterval") == 0)
  12135. {
  12136. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  12137. {
  12138. check_ascii = value[0];
  12139. if( (check_ascii < 48) || (check_ascii > 57) )
  12140. {
  12141. isSuccess = ConfigurationStatus_Rejected;
  12142. }
  12143. else
  12144. {
  12145. if((atoi(value) == 0) || (atoi(value) >= 10))
  12146. {
  12147. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  12148. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  12149. HeartBeatWaitTime = atoi(value);
  12150. isSuccess = ConfigurationStatus_Accepted;
  12151. }
  12152. else
  12153. {
  12154. isSuccess = ConfigurationStatus_Rejected;
  12155. }
  12156. }
  12157. }
  12158. else
  12159. {
  12160. isSuccess = ConfigurationStatus_Rejected;
  12161. }
  12162. }
  12163. if(strcmp(key, "LightIntensity") == 0)
  12164. {
  12165. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  12166. {
  12167. check_ascii = value[0];
  12168. if( (check_ascii < 48) || (check_ascii > 57) )
  12169. {
  12170. isSuccess = ConfigurationStatus_Rejected;
  12171. }
  12172. else
  12173. {
  12174. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  12175. isSuccess = ConfigurationStatus_Accepted;
  12176. }
  12177. }
  12178. else
  12179. {
  12180. isSuccess = ConfigurationStatus_Rejected;
  12181. }
  12182. }
  12183. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  12184. {
  12185. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  12186. {
  12187. strcpy(str, (const char*)value);
  12188. for(int i = 0; str[i]; i++)
  12189. {
  12190. str[i] = tolower(str[i]);
  12191. }
  12192. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12193. isSuccess = ConfigurationStatus_Accepted;
  12194. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12195. }
  12196. else
  12197. {
  12198. isSuccess = ConfigurationStatus_Rejected;
  12199. }
  12200. }
  12201. if(strcmp(key, "LocalPreAuthorize") == 0)
  12202. {
  12203. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  12204. {
  12205. strcpy(str, (const char*)value);
  12206. for(int i = 0; str[i]; i++)
  12207. {
  12208. str[i] = tolower(str[i]);
  12209. }
  12210. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12211. isSuccess = ConfigurationStatus_Accepted;
  12212. }
  12213. else
  12214. {
  12215. isSuccess = ConfigurationStatus_Rejected;
  12216. }
  12217. }
  12218. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  12219. {
  12220. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  12221. {
  12222. check_ascii = value[0];
  12223. if( (check_ascii < 48) || (check_ascii > 57) )
  12224. {
  12225. isSuccess = ConfigurationStatus_Rejected;
  12226. }
  12227. else
  12228. {
  12229. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  12230. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  12231. isSuccess = ConfigurationStatus_Accepted;
  12232. }
  12233. }
  12234. else
  12235. {
  12236. isSuccess = ConfigurationStatus_Rejected;
  12237. }
  12238. }
  12239. if(strcmp(key, "MeterValuesAlignedData") == 0)
  12240. {
  12241. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  12242. {
  12243. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  12244. isSuccess = ConfigurationStatus_Accepted;
  12245. }
  12246. else
  12247. {
  12248. isSuccess = ConfigurationStatus_Rejected;
  12249. }
  12250. }
  12251. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  12252. {
  12253. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  12254. {
  12255. check_ascii = value[0];
  12256. if( (check_ascii < 48) || (check_ascii > 57) )
  12257. {
  12258. isSuccess = ConfigurationStatus_Rejected;
  12259. }
  12260. else
  12261. {
  12262. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12263. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  12264. isSuccess = ConfigurationStatus_Accepted;
  12265. }
  12266. }
  12267. else
  12268. {
  12269. isSuccess = ConfigurationStatus_Rejected;
  12270. }
  12271. }
  12272. if(strcmp(key, "MeterValuesSampledData") == 0 )
  12273. {
  12274. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  12275. {
  12276. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  12277. isSuccess = ConfigurationStatus_Accepted;
  12278. }
  12279. else
  12280. {
  12281. isSuccess = ConfigurationStatus_Rejected;
  12282. }
  12283. }
  12284. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  12285. {
  12286. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  12287. {
  12288. check_ascii = value[0];
  12289. if( (check_ascii < 48) || (check_ascii > 57) )
  12290. {
  12291. isSuccess = ConfigurationStatus_Rejected;
  12292. }
  12293. else
  12294. {
  12295. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12296. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  12297. isSuccess = ConfigurationStatus_Accepted;
  12298. }
  12299. }
  12300. else
  12301. {
  12302. isSuccess = ConfigurationStatus_Rejected;
  12303. }
  12304. }
  12305. if(strcmp(key, "MeterValueSampleInterval") == 0)
  12306. {
  12307. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12308. {
  12309. check_ascii = value[0];
  12310. if( (check_ascii < 48) || (check_ascii > 57) )
  12311. {
  12312. isSuccess = ConfigurationStatus_Rejected;
  12313. }
  12314. else
  12315. {
  12316. if((atoi(value) == 0) || (atoi(value) >= 10))
  12317. {
  12318. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12319. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  12320. isSuccess = ConfigurationStatus_Accepted;
  12321. }
  12322. else
  12323. {
  12324. isSuccess = ConfigurationStatus_Rejected;
  12325. }
  12326. }
  12327. }
  12328. else
  12329. {
  12330. isSuccess = ConfigurationStatus_Rejected;
  12331. }
  12332. }
  12333. if(strcmp(key, "MinimumStatusDuration") == 0)
  12334. {
  12335. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12336. {
  12337. check_ascii = value[0];
  12338. if( (check_ascii < 48) || (check_ascii > 57) )
  12339. {
  12340. isSuccess = ConfigurationStatus_Rejected;
  12341. }
  12342. else
  12343. {
  12344. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  12345. {
  12346. isSuccess = ConfigurationStatus_Rejected;
  12347. }
  12348. else
  12349. {
  12350. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  12351. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  12352. server_cycle_Status = atoi(value); //StatusNotification Cycle
  12353. isSuccess = ConfigurationStatus_Accepted;
  12354. }
  12355. }
  12356. }
  12357. else
  12358. {
  12359. isSuccess = ConfigurationStatus_Rejected;
  12360. }
  12361. }
  12362. if(strcmp(key, "NumberOfConnectors") == 0)
  12363. {
  12364. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12365. {
  12366. check_ascii = value[0];
  12367. if( (check_ascii < 48) || (check_ascii > 57) )
  12368. {
  12369. isSuccess = ConfigurationStatus_Rejected;
  12370. }
  12371. else
  12372. {
  12373. //Charger.ResetRetries = Integer.parseInt(value);
  12374. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  12375. isSuccess = ConfigurationStatus_Accepted;
  12376. }
  12377. }
  12378. else
  12379. {
  12380. isSuccess = ConfigurationStatus_Rejected;
  12381. }
  12382. }
  12383. if(strcmp(key, "ResetRetries") == 0)
  12384. {
  12385. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12386. {
  12387. check_ascii = value[0];
  12388. if( (check_ascii < 48) || (check_ascii > 57) )
  12389. {
  12390. isSuccess = ConfigurationStatus_Rejected;
  12391. }
  12392. else
  12393. {
  12394. //Charger.ResetRetries = Integer.parseInt(value);
  12395. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  12396. isSuccess = ConfigurationStatus_Accepted;
  12397. }
  12398. }
  12399. else
  12400. {
  12401. isSuccess = ConfigurationStatus_Rejected;
  12402. }
  12403. }
  12404. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  12405. {
  12406. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12407. {
  12408. strcpy(str, (const char*)value);
  12409. for(int i = 0; str[i]; i++)
  12410. {
  12411. str[i] = tolower(str[i]);
  12412. }
  12413. if(strcmp(str, "notapplicable")== 0)
  12414. {
  12415. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  12416. isSuccess = ConfigurationStatus_Accepted;
  12417. }
  12418. else if(strcmp(str, "unknown")== 0)
  12419. {
  12420. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  12421. isSuccess = ConfigurationStatus_Accepted;
  12422. }
  12423. else if(strcmp(str, "rst")== 0)
  12424. {
  12425. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  12426. isSuccess = ConfigurationStatus_Accepted;
  12427. }
  12428. else if(strcmp(str, "rts")== 0)
  12429. {
  12430. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  12431. isSuccess = ConfigurationStatus_Accepted;
  12432. }
  12433. else if(strcmp(str, "srt")== 0)
  12434. {
  12435. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  12436. isSuccess = ConfigurationStatus_Accepted;
  12437. }
  12438. else if(strcmp(str, "str")== 0)
  12439. {
  12440. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  12441. isSuccess = ConfigurationStatus_Accepted;
  12442. }
  12443. else if(strcmp(str, "trs")== 0)
  12444. {
  12445. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  12446. isSuccess = ConfigurationStatus_Accepted;
  12447. }
  12448. else if(strcmp(str, "tsr")== 0)
  12449. {
  12450. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  12451. isSuccess = ConfigurationStatus_Accepted;
  12452. }
  12453. else
  12454. {
  12455. isSuccess = ConfigurationStatus_Rejected;
  12456. }
  12457. }
  12458. else
  12459. {
  12460. isSuccess = ConfigurationStatus_Rejected;
  12461. }
  12462. }
  12463. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  12464. {
  12465. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12466. {
  12467. check_ascii = value[0];
  12468. if( (check_ascii < 48) || (check_ascii > 57) )
  12469. {
  12470. isSuccess = ConfigurationStatus_Rejected;
  12471. }
  12472. else
  12473. {
  12474. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  12475. isSuccess = ConfigurationStatus_Accepted;
  12476. }
  12477. }
  12478. else
  12479. {
  12480. isSuccess = ConfigurationStatus_Rejected;
  12481. }
  12482. }
  12483. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  12484. {
  12485. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12486. {
  12487. strcpy(str, (const char*)value);
  12488. for(int i = 0; str[i]; i++)
  12489. {
  12490. str[i] = tolower(str[i]);
  12491. }
  12492. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12493. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12494. isSuccess = ConfigurationStatus_Accepted;
  12495. }
  12496. else
  12497. {
  12498. isSuccess = ConfigurationStatus_Rejected;
  12499. }
  12500. }
  12501. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  12502. {
  12503. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12504. {
  12505. strcpy(str, (const char*)value);
  12506. for(int i = 0; str[i]; i++)
  12507. {
  12508. str[i] = tolower(str[i]);
  12509. }
  12510. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  12511. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12512. isSuccess = ConfigurationStatus_Accepted;
  12513. }
  12514. else
  12515. {
  12516. isSuccess = ConfigurationStatus_Rejected;
  12517. }
  12518. }
  12519. if(strcmp(key, "StopTxnAlignedData") == 0)
  12520. {
  12521. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12522. {
  12523. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  12524. isSuccess = ConfigurationStatus_Accepted;
  12525. }
  12526. else
  12527. {
  12528. isSuccess = ConfigurationStatus_Rejected;
  12529. }
  12530. }
  12531. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  12532. {
  12533. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12534. {
  12535. check_ascii = value[0];
  12536. if( (check_ascii < 48) || (check_ascii > 57) )
  12537. {
  12538. isSuccess = ConfigurationStatus_Rejected;
  12539. }
  12540. else
  12541. {
  12542. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  12543. isSuccess = ConfigurationStatus_Accepted;
  12544. }
  12545. }
  12546. else
  12547. {
  12548. isSuccess = ConfigurationStatus_Rejected;
  12549. }
  12550. }
  12551. if(strcmp(key, "StopTxnSampledData") == 0)
  12552. {
  12553. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12554. {
  12555. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  12556. isSuccess = ConfigurationStatus_Accepted;
  12557. }
  12558. else
  12559. {
  12560. isSuccess = ConfigurationStatus_Rejected;
  12561. }
  12562. }
  12563. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  12564. {
  12565. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12566. {
  12567. check_ascii = value[0];
  12568. if( (check_ascii < 48) || (check_ascii > 57) )
  12569. {
  12570. isSuccess = ConfigurationStatus_Rejected;
  12571. }
  12572. else
  12573. {
  12574. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  12575. isSuccess = ConfigurationStatus_Accepted;
  12576. }
  12577. }
  12578. else
  12579. {
  12580. isSuccess = ConfigurationStatus_Rejected;
  12581. }
  12582. }
  12583. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  12584. {
  12585. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12586. {
  12587. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  12588. isSuccess = ConfigurationStatus_Accepted;
  12589. }
  12590. else
  12591. {
  12592. isSuccess = ConfigurationStatus_Rejected;
  12593. }
  12594. }
  12595. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  12596. {
  12597. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12598. {
  12599. check_ascii = value[0];
  12600. if( (check_ascii < 48) || (check_ascii > 57) )
  12601. {
  12602. isSuccess = ConfigurationStatus_Rejected;
  12603. }
  12604. else
  12605. {
  12606. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  12607. isSuccess = ConfigurationStatus_Accepted;
  12608. }
  12609. }
  12610. else
  12611. {
  12612. isSuccess = ConfigurationStatus_Rejected;
  12613. }
  12614. }
  12615. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12616. {
  12617. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12618. {
  12619. check_ascii = value[0];
  12620. if( (check_ascii < 48) || (check_ascii > 57) )
  12621. {
  12622. isSuccess = ConfigurationStatus_Rejected;
  12623. }
  12624. else
  12625. {
  12626. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12627. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12628. TransactionMessageAttemptsValue = atoi(value);
  12629. isSuccess = ConfigurationStatus_Accepted;
  12630. }
  12631. }
  12632. else
  12633. {
  12634. isSuccess = ConfigurationStatus_Rejected;
  12635. }
  12636. }
  12637. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12638. {
  12639. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12640. {
  12641. check_ascii = value[0];
  12642. if( (check_ascii < 48) || (check_ascii > 57) )
  12643. {
  12644. isSuccess = ConfigurationStatus_Rejected;
  12645. }
  12646. else
  12647. {
  12648. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12649. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12650. TransactionMessageRetryIntervalValue = atoi(value);
  12651. isSuccess = ConfigurationStatus_Accepted;
  12652. }
  12653. }
  12654. else
  12655. {
  12656. isSuccess = ConfigurationStatus_Rejected;
  12657. }
  12658. }
  12659. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12660. {
  12661. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12662. {
  12663. strcpy(str, (const char*)value);
  12664. for(int i = 0; str[i]; i++)
  12665. {
  12666. str[i] = tolower(str[i]);
  12667. }
  12668. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12669. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12670. isSuccess = ConfigurationStatus_Accepted;
  12671. }
  12672. else
  12673. {
  12674. isSuccess = ConfigurationStatus_Rejected;
  12675. }
  12676. }
  12677. if(strcmp(key, "WebSocketPingInterval") == 0)
  12678. {
  12679. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12680. {
  12681. check_ascii = value[0];
  12682. if( (check_ascii < 48) || (check_ascii > 57) )
  12683. {
  12684. isSuccess = ConfigurationStatus_Rejected;
  12685. }
  12686. else
  12687. {
  12688. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12689. isSuccess = ConfigurationStatus_Accepted;
  12690. }
  12691. }
  12692. else
  12693. {
  12694. isSuccess = ConfigurationStatus_Rejected;
  12695. }
  12696. }
  12697. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  12698. {
  12699. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12700. {
  12701. strcpy(str, (const char*)value);
  12702. for(int i = 0; str[i]; i++)
  12703. {
  12704. str[i] = tolower(str[i]);
  12705. }
  12706. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12707. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12708. isSuccess = ConfigurationStatus_Accepted;
  12709. }
  12710. else
  12711. {
  12712. isSuccess = ConfigurationStatus_Rejected;
  12713. }
  12714. }
  12715. if(strcmp(key, "AuthorizationKey") == 0)
  12716. {
  12717. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  12718. {
  12719. strcpy(str, (const char*)value);
  12720. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  12721. isSuccess = ConfigurationStatus_Accepted;
  12722. }
  12723. else
  12724. {
  12725. isSuccess = ConfigurationStatus_Rejected;
  12726. }
  12727. }
  12728. if(strcmp(key, "SecurityProfile") == 0)
  12729. {
  12730. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  12731. {
  12732. check_ascii = value[0];
  12733. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  12734. {
  12735. isSuccess = ConfigurationStatus_Rejected;
  12736. }
  12737. else if(check_ascii == 0x33)
  12738. {
  12739. isSuccess = NotSupported;
  12740. }
  12741. else
  12742. {
  12743. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  12744. {
  12745. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  12746. isSuccess = ConfigurationStatus_Accepted;
  12747. }
  12748. else
  12749. isSuccess = ConfigurationStatus_Rejected;
  12750. }
  12751. }
  12752. else
  12753. {
  12754. isSuccess = ConfigurationStatus_Rejected;
  12755. }
  12756. }
  12757. if(strcmp(key, "DefaultPrice") == 0)
  12758. {
  12759. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  12760. {
  12761. strcpy(str, (const char*)value);
  12762. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  12763. isSuccess = ConfigurationStatus_Accepted;
  12764. }
  12765. else
  12766. {
  12767. isSuccess = ConfigurationStatus_Rejected;
  12768. }
  12769. }
  12770. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  12771. {
  12772. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  12773. {
  12774. strcpy(str, (const char*)value);
  12775. for(int i = 0; str[i]; i++)
  12776. {
  12777. str[i] = tolower(str[i]);
  12778. }
  12779. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12780. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12781. isSuccess = ConfigurationStatus_Accepted;
  12782. }
  12783. else
  12784. {
  12785. isSuccess = ConfigurationStatus_Rejected;
  12786. }
  12787. }
  12788. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  12789. {
  12790. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  12791. {
  12792. strcpy(str, (const char*)value);
  12793. for(int i = 0; str[i]; i++)
  12794. {
  12795. str[i] = tolower(str[i]);
  12796. }
  12797. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12798. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12799. isSuccess = ConfigurationStatus_Accepted;
  12800. }
  12801. else
  12802. {
  12803. isSuccess = ConfigurationStatus_Rejected;
  12804. }
  12805. }
  12806. #if 0
  12807. //For OCPP Test Case
  12808. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  12809. {
  12810. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12811. {
  12812. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  12813. isSuccess = ConfigurationStatus_Accepted;
  12814. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12815. }
  12816. else
  12817. {
  12818. isSuccess = ConfigurationStatus_Rejected;
  12819. }
  12820. }
  12821. #endif
  12822. #if 1
  12823. if(strcmp(key, "LocalAuthListEnabled") == 0)
  12824. {
  12825. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12826. {
  12827. strcpy(str, (const char*)value);
  12828. for(int i = 0; str[i]; i++)
  12829. {
  12830. str[i] = tolower(str[i]);
  12831. }
  12832. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12833. isSuccess = ConfigurationStatus_Accepted;
  12834. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12835. }
  12836. else
  12837. {
  12838. isSuccess = ConfigurationStatus_Rejected;
  12839. }
  12840. }
  12841. #endif
  12842. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12843. {
  12844. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12845. {
  12846. check_ascii = value[0];
  12847. if( (check_ascii < 48) || (check_ascii > 57) )
  12848. {
  12849. isSuccess = ConfigurationStatus_Rejected;
  12850. }
  12851. else
  12852. {
  12853. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12854. isSuccess = ConfigurationStatus_Accepted;
  12855. }
  12856. }
  12857. else
  12858. {
  12859. isSuccess = ConfigurationStatus_Rejected;
  12860. }
  12861. }
  12862. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12863. {
  12864. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12865. {
  12866. check_ascii = value[0];
  12867. if( (check_ascii < 48) || (check_ascii > 57) )
  12868. {
  12869. isSuccess = ConfigurationStatus_Rejected;
  12870. }
  12871. else
  12872. {
  12873. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12874. isSuccess = ConfigurationStatus_Accepted;
  12875. }
  12876. }
  12877. else
  12878. {
  12879. isSuccess = ConfigurationStatus_Rejected;
  12880. }
  12881. }
  12882. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12883. {
  12884. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12885. {
  12886. strcpy(str, (const char*)value);
  12887. for(int i = 0; str[i]; i++)
  12888. {
  12889. str[i] = tolower(str[i]);
  12890. }
  12891. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12892. isSuccess = ConfigurationStatus_Accepted;
  12893. }
  12894. else
  12895. {
  12896. isSuccess = ConfigurationStatus_Rejected;
  12897. }
  12898. }
  12899. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12900. {
  12901. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12902. {
  12903. check_ascii = value[0];
  12904. if( (check_ascii < 48) || (check_ascii > 57) )
  12905. {
  12906. isSuccess = ConfigurationStatus_Rejected;
  12907. }
  12908. else
  12909. {
  12910. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12911. isSuccess = ConfigurationStatus_Accepted;
  12912. }
  12913. }
  12914. else
  12915. {
  12916. isSuccess = ConfigurationStatus_Rejected;
  12917. }
  12918. }
  12919. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12920. {
  12921. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12922. {
  12923. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12924. isSuccess = ConfigurationStatus_Accepted;
  12925. }
  12926. else
  12927. {
  12928. isSuccess = ConfigurationStatus_Rejected;
  12929. }
  12930. }
  12931. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12932. {
  12933. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12934. {
  12935. check_ascii = value[0];
  12936. if( (check_ascii < 48) || (check_ascii > 57) )
  12937. {
  12938. isSuccess = ConfigurationStatus_Rejected;
  12939. }
  12940. else
  12941. {
  12942. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12943. isSuccess = ConfigurationStatus_Accepted;
  12944. }
  12945. }
  12946. else
  12947. {
  12948. isSuccess = ConfigurationStatus_Rejected;
  12949. }
  12950. }
  12951. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12952. {
  12953. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12954. {
  12955. strcpy(str, (const char*)value);
  12956. for(int i = 0; str[i]; i++)
  12957. {
  12958. str[i] = tolower(str[i]);
  12959. }
  12960. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12961. isSuccess = ConfigurationStatus_Accepted;
  12962. }
  12963. else
  12964. {
  12965. isSuccess = ConfigurationStatus_Rejected;
  12966. }
  12967. }
  12968. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12969. {
  12970. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12971. {
  12972. check_ascii = value[0];
  12973. if( (check_ascii < 48) || (check_ascii > 57) )
  12974. {
  12975. isSuccess = ConfigurationStatus_Rejected;
  12976. }
  12977. else
  12978. {
  12979. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12980. isSuccess = ConfigurationStatus_Accepted;
  12981. }
  12982. }
  12983. else
  12984. {
  12985. isSuccess = ConfigurationStatus_Rejected;
  12986. }
  12987. }
  12988. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12989. return isSuccess;
  12990. }
  12991. int TransactionMessageAttemptsGet(void)
  12992. {
  12993. return TransactionMessageAttemptsValue;
  12994. }
  12995. int FirstHeartBeatResponse(void)
  12996. {
  12997. return FirstHeartBeat;
  12998. }
  12999. int TransactionMessageRetryIntervalGet(void)
  13000. {
  13001. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13002. }
  13003. int ReadHttpStatus(int sock)
  13004. {
  13005. //char c;
  13006. char buff[1024]="",*ptr=buff+1;
  13007. int bytes_received, status;
  13008. DEBUG_INFO("Begin Response ..\n");
  13009. while((bytes_received = recv(sock, ptr, 1, 0))){
  13010. if(bytes_received==-1){
  13011. perror("ReadHttpStatus");
  13012. exit(1);
  13013. }
  13014. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  13015. ptr++;
  13016. }
  13017. *ptr=0;
  13018. ptr=buff+1;
  13019. sscanf(ptr,"%*s %d ", &status);
  13020. DEBUG_INFO("%s\n",ptr);
  13021. DEBUG_INFO("status=%d\n",status);
  13022. DEBUG_INFO("End Response ..\n");
  13023. return (bytes_received>0)?status:0;
  13024. }
  13025. //the only filed that it parsed is 'Content-Length'
  13026. int ParseHeader(int sock)
  13027. {
  13028. //char c;
  13029. char buff[1024]="",*ptr=buff+4;
  13030. int bytes_received;
  13031. DEBUG_INFO("Begin HEADER ..\n");
  13032. while((bytes_received = recv(sock, ptr, 1, 0))){
  13033. if(bytes_received==-1){
  13034. perror("Parse Header");
  13035. exit(1);
  13036. }
  13037. if(
  13038. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  13039. (ptr[-1]=='\r') && (*ptr=='\n' )
  13040. ) break;
  13041. ptr++;
  13042. }
  13043. *ptr=0;
  13044. ptr=buff+4;
  13045. //printf("%s",ptr);
  13046. if(bytes_received){
  13047. ptr=strstr(ptr,"Content-Length:");
  13048. if(ptr){
  13049. sscanf(ptr,"%*s %d",&bytes_received);
  13050. }else
  13051. bytes_received=-1; //unknown size
  13052. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  13053. }
  13054. DEBUG_INFO("End HEADER ..\n");
  13055. return bytes_received ;
  13056. }
  13057. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  13058. {
  13059. int result = TRUE;
  13060. char rmFileCmd[100]={0};
  13061. char FilePath[100]={0};
  13062. char ftpbuf[200];
  13063. int systemresult;
  13064. //DEBUG_INFO("filename=%s\n",filename);
  13065. //DEBUG_INFO("url=%s\n",url);
  13066. sprintf(FilePath,"/mnt/%s",filename);
  13067. system("ping 8.8.8.8 &");
  13068. if((access(FilePath,F_OK))!=-1)
  13069. {
  13070. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13071. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13072. system(rmFileCmd);
  13073. }
  13074. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13075. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  13076. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13077. systemresult = system(ftpbuf);
  13078. //DEBUG_INFO("systemresult=%d\n",systemresult);
  13079. if(systemresult != 0)
  13080. {
  13081. DEBUG_INFO("http DownLoad error!\n");
  13082. result = FALSE;
  13083. }
  13084. system("pkill ping");
  13085. return result;
  13086. }
  13087. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  13088. {
  13089. int result = TRUE;
  13090. char rmFileCmd[100]={0};
  13091. char FilePath[100]={0};
  13092. char ftpbuf[200];
  13093. int systemresult;
  13094. //char temp[100];
  13095. sprintf(FilePath,"/mnt/%s",filename);
  13096. system("ping 8.8.8.8 &");
  13097. if((access(FilePath,F_OK))!=-1)
  13098. {
  13099. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13100. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13101. system(rmFileCmd);
  13102. }
  13103. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13104. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  13105. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  13106. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  13107. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13108. systemresult = system(ftpbuf);
  13109. //DEBUG_INFO("systemresult=%d\n",systemresult);
  13110. if(systemresult != 0)
  13111. {
  13112. printf("wget error!\n");
  13113. result = FALSE;
  13114. }
  13115. system("pkill ping");
  13116. return result;
  13117. }
  13118. int httpUploadFile(char *location, char *path, char *filename,char *url)
  13119. {
  13120. char rmFileCmd[100]={0};
  13121. char FilePath[100]={0};
  13122. char ftpbuf[200];
  13123. int systemresult;
  13124. //DEBUG_INFO("filename=%s\n",filename);
  13125. //DEBUG_INFO("url=%s\n",url);
  13126. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  13127. if((access(FilePath,F_OK))!=-1)
  13128. {
  13129. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13130. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13131. system(rmFileCmd);
  13132. }
  13133. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  13134. if(fp == NULL)
  13135. {
  13136. DEBUG_INFO("log is NULL\n");
  13137. return FALSE;
  13138. }
  13139. else
  13140. {
  13141. fprintf(fp, "%s\n", url);
  13142. fprintf(fp, "%s\n", filename);
  13143. fclose(fp);
  13144. }
  13145. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13146. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  13147. systemresult = system(ftpbuf);
  13148. DEBUG_INFO("systemresult = %d\n",systemresult);
  13149. if(systemresult != 0)
  13150. {
  13151. DEBUG_INFO("http upload error!\n");
  13152. return FALSE;
  13153. }
  13154. return TRUE;
  13155. }
  13156. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  13157. {
  13158. struct hostent* server;
  13159. char *IPbuffer;
  13160. char ftpbuf[200];
  13161. int systemresult;
  13162. // To retrieve host information
  13163. server = gethostbyname(location);
  13164. // To convert an Internet network
  13165. // address into ASCII string
  13166. IPbuffer = inet_ntoa(*((struct in_addr*)
  13167. server->h_addr_list[0]));
  13168. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13169. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  13170. /* format : ftpput -u username -p passwd IP target source*/
  13171. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  13172. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  13173. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13174. systemresult = system(ftpbuf);
  13175. DEBUG_INFO("systemresult=%d\n",systemresult);
  13176. if(systemresult != 0)
  13177. {
  13178. DEBUG_INFO("ftpput error!\n");
  13179. return FALSE;
  13180. }
  13181. return TRUE;
  13182. }
  13183. /**
  13184. * Place the contents of the specified file into a memory buffer
  13185. *
  13186. * @param[in] filename The path and name of the file to read
  13187. * @param[out] filebuffer A pointer to the contents in memory
  13188. * @return status 0 success, 1 on failure
  13189. */
  13190. int get_file_contents(const char* filename, char** outbuffer) {
  13191. FILE* file = NULL;
  13192. long filesize;
  13193. const int blocksize = 1;
  13194. size_t readsize;
  13195. char* filebuffer;
  13196. // Open the file
  13197. file = fopen(filename, "r");
  13198. if (NULL == file)
  13199. {
  13200. printf("'%s' not opened\n", filename);
  13201. exit(EXIT_FAILURE);
  13202. }
  13203. // Determine the file size
  13204. fseek(file, 0, SEEK_END);
  13205. filesize = ftell(file);
  13206. rewind (file);
  13207. // Allocate memory for the file contents
  13208. filebuffer = (char*) malloc(sizeof(char) * filesize);
  13209. *outbuffer = filebuffer;
  13210. if (filebuffer == NULL)
  13211. {
  13212. fputs ("malloc out-of-memory", stderr);
  13213. exit(EXIT_FAILURE);
  13214. }
  13215. // Read in the file
  13216. readsize = fread(filebuffer, blocksize, filesize, file);
  13217. if (readsize != filesize)
  13218. {
  13219. fputs ("didn't read file completely",stderr);
  13220. exit(EXIT_FAILURE);
  13221. }
  13222. // Clean exit
  13223. fclose(file);
  13224. return EXIT_SUCCESS;
  13225. }
  13226. static int selectSqlCount = 0;
  13227. static int callback(void *data, int argc, char **argv, char **azColName){
  13228. int i;
  13229. //printf("%s: ", (const char*)data);
  13230. selectSqlCount = argc;
  13231. for(i = 0; i<argc; i++){
  13232. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  13233. }
  13234. //printf("\n");
  13235. return 0;
  13236. }
  13237. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  13238. //int i;
  13239. //printf("%s:\n", (const char*)data);
  13240. localversion = argv[5] ? atoi(argv[5]) : 0;
  13241. //printf("localversion=%d\n", localversion);
  13242. return 0;
  13243. }
  13244. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  13245. //printf("%s:\n", (const char*)data);
  13246. //idTag
  13247. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  13248. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  13249. //parentIdTag
  13250. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  13251. //expir_date
  13252. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  13253. //status
  13254. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  13255. //version
  13256. if(columenCount > 5)
  13257. idTagQuery.listVersionInt = atoi(columnValue[5]);
  13258. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  13259. return 0;
  13260. }
  13261. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  13262. {
  13263. // localversion = argv[5] ? atoi(argv[5]) : 0;
  13264. // printf("localversion=%d\n", localversion);
  13265. return 0;
  13266. }
  13267. //=========================================
  13268. // Sqlite3 related function
  13269. //=========================================
  13270. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  13271. {
  13272. for (int i = 0; i < n_columns; i++)
  13273. {
  13274. DEBUG_INFO("%s\t", col_values[i]);
  13275. }
  13276. DEBUG_INFO("\n");
  13277. return 0;
  13278. }
  13279. int OCPP_cleanLocalCache()
  13280. {
  13281. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  13282. char *errMsg = 0;
  13283. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  13284. if (SQLITE_OK != rc)
  13285. {
  13286. DEBUG_INFO("SQL error: %s\n",errMsg);
  13287. return FALSE;
  13288. }
  13289. return TRUE;
  13290. }
  13291. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  13292. {
  13293. int isSuccess = TRUE;
  13294. int ret = 0;
  13295. //const char* data = "Callback function called";
  13296. char sql[300];
  13297. char zErrMsg[200];
  13298. memset(sql, 0, 300);
  13299. memset(zErrMsg, 0, 200);
  13300. sprintf(sql, "insert or replace into ocpp_auth_cache (idtag, parent_idtag, expir_date, status) " "VALUES ('%s', '%s', '%s', '%s'); ""SELECT * from ocpp_auth_cache", idTag, parentTage, expiryDate, status);
  13301. //* Execute SQL statement */
  13302. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  13303. if( ret != SQLITE_OK )
  13304. {
  13305. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13306. isSuccess = FALSE;
  13307. }
  13308. return isSuccess;
  13309. }
  13310. void OCPP_getIdTagFromLocalCache(char idTag[])
  13311. {
  13312. int rc = 0;
  13313. char sql[100];
  13314. char zErrMsg[100];
  13315. memset(sql, 0, 100);
  13316. memset(zErrMsg, 0, 100);
  13317. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  13318. memset(&idTagQuery, 0, sizeof(idTagQuery));
  13319. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  13320. /* Execute SQL statement */
  13321. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  13322. if( rc != SQLITE_OK )
  13323. {
  13324. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13325. }
  13326. }
  13327. void OCPP_getListVerion()
  13328. {
  13329. int rc = 0;
  13330. // const char* data = "Callback function called";
  13331. char sql[100];
  13332. char zErrMsg[100];
  13333. memset(sql, 0, 100);
  13334. memset(zErrMsg, 0, 100);
  13335. strcpy(sql, "select * from ocpp_auth_local order by idx");
  13336. /* Execute SQL statement */
  13337. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  13338. if( rc != SQLITE_OK )
  13339. {
  13340. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13341. }
  13342. }
  13343. void OCPP_get_TableAuthlocalAllData(void)
  13344. {
  13345. int rc = 0;
  13346. char sql[100];
  13347. char zErrMsg[100];
  13348. memset(sql, 0, 100);
  13349. memset(zErrMsg, 0, 100);
  13350. sprintf(sql,"select * from ocpp_auth_local ");
  13351. /* Execute SQL statement */
  13352. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  13353. if( rc != SQLITE_OK )
  13354. {
  13355. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13356. }
  13357. //return ver;
  13358. }
  13359. int OCPP_cleanLocalList()
  13360. {
  13361. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  13362. char *errMsg = 0;
  13363. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  13364. if (SQLITE_OK != rc)
  13365. {
  13366. DEBUG_INFO("%s\n",errMsg);
  13367. return FALSE;
  13368. }
  13369. return TRUE;
  13370. }
  13371. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  13372. {
  13373. int isSuccess = FALSE;
  13374. int ret = 0;
  13375. //const char* data = "Callback function called";
  13376. char sql[300];
  13377. char zErrMsg[200];
  13378. memset(sql, 0, 300);
  13379. memset(zErrMsg, 0, 200);
  13380. 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);
  13381. //* Execute SQL statement */
  13382. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  13383. if( ret != SQLITE_OK )
  13384. {
  13385. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13386. return isSuccess;
  13387. }
  13388. memset(sql, 0, 300);
  13389. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  13390. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  13391. if( ret != SQLITE_OK )
  13392. {
  13393. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13394. return isSuccess;
  13395. }
  13396. isSuccess = TRUE;
  13397. return isSuccess;
  13398. }
  13399. void OCPP_getIdTagFromLocalList(char idTag[])
  13400. {
  13401. int rc = 0;
  13402. // const char* data = "Callback function called";
  13403. char sql[100];
  13404. char zErrMsg[100];
  13405. memset(sql, 0, 100);
  13406. memset(zErrMsg, 0, 100);
  13407. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  13408. memset(&idTagQuery, 0, sizeof(idTagQuery));
  13409. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  13410. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  13411. /* Execute SQL statement */
  13412. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  13413. if( rc != SQLITE_OK )
  13414. {
  13415. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13416. }
  13417. //return ver;
  13418. }
  13419. void OCPP_deleteIdTagFromLocalList(char idTag[])
  13420. {
  13421. //int ver = 0;
  13422. //int isSuccess = FALSE;
  13423. int rc = 0;
  13424. char sql[100];
  13425. char zErrMsg[100];
  13426. memset(sql, 0, 100);
  13427. memset(zErrMsg, 0, 100);
  13428. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  13429. //* Execute SQL statement */
  13430. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  13431. if( rc != SQLITE_OK )
  13432. {
  13433. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13434. }
  13435. }
  13436. int GetOcppServerURL()
  13437. {
  13438. int result = FALSE;
  13439. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  13440. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  13441. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  13442. struct yuarel url;
  13443. char urlStr[512];
  13444. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  13445. {
  13446. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  13447. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13448. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  13449. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  13450. if(yuarel_parse(&url, urlStr) != -1)
  13451. {
  13452. sprintf(OcppProtocol, "%s", url.scheme);
  13453. sprintf(OcppHost, "%s", url.host);
  13454. if(url.path == NULL)
  13455. OcppTempPath[0] = '\0';
  13456. else
  13457. {
  13458. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  13459. {
  13460. sprintf(OcppTempPath, "%s/", url.path);
  13461. }
  13462. else
  13463. {
  13464. sprintf(OcppTempPath, "%s", url.path);
  13465. }
  13466. }
  13467. if(url.port == 0)
  13468. {
  13469. if(strcmp(OcppProtocol, "wss") == 0)
  13470. OcppPort = 443;
  13471. else
  13472. OcppPort = 80;
  13473. }
  13474. else
  13475. OcppPort = url.port;
  13476. result = TRUE;
  13477. }
  13478. }
  13479. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  13480. {
  13481. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  13482. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13483. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  13484. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  13485. if(yuarel_parse(&url, urlStr) != -1)
  13486. {
  13487. sprintf(OcppProtocol, "%s", url.scheme);
  13488. sprintf(OcppHost, "%s", url.host);
  13489. if(url.path == NULL)
  13490. OcppTempPath[0] = '\0';
  13491. else
  13492. sprintf(OcppTempPath, "%s", url.path);
  13493. if(url.port == 0)
  13494. {
  13495. if(strcmp(OcppProtocol, "wss") == 0)
  13496. OcppPort = 443;
  13497. else
  13498. OcppPort = 80;
  13499. }
  13500. else
  13501. OcppPort = url.port;
  13502. result = TRUE;
  13503. }
  13504. }
  13505. else
  13506. {
  13507. strcpy(OcppHost,"");
  13508. }
  13509. return result;
  13510. }
  13511. int GetOcppPath()
  13512. {
  13513. int result = FALSE;
  13514. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  13515. {
  13516. if(OcppTempPath == NULL)
  13517. {
  13518. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13519. }
  13520. else
  13521. {
  13522. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13523. }
  13524. result = TRUE;
  13525. goto End;
  13526. }
  13527. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  13528. {
  13529. if(OcppTempPath == NULL)
  13530. {
  13531. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  13532. }
  13533. else
  13534. {
  13535. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  13536. }
  13537. result = TRUE;
  13538. goto End;
  13539. }
  13540. else
  13541. {
  13542. strcpy(OcppPath,"");
  13543. }
  13544. End:
  13545. return result;
  13546. }
  13547. int GetOcppPort()
  13548. {
  13549. return OcppPort;
  13550. }
  13551. int GetOcppConnStatus(void)
  13552. {
  13553. return ShmOCPP16Data->OcppConnStatus;
  13554. }
  13555. void SetOcppConnStatus(uint8_t status)
  13556. {
  13557. ShmOCPP16Data->OcppConnStatus = status;
  13558. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  13559. }
  13560. int GetHeartBeatWithNOResponse(void)
  13561. {
  13562. return HeartBeatWithNOResponse;
  13563. }
  13564. void SetHeartBeatWithNOResponse(void)
  13565. {
  13566. HeartBeatWithNOResponse = 0;
  13567. }
  13568. void GetStartTransactionIdTag(int gun_index)
  13569. {
  13570. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  13571. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13572. }
  13573. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  13574. {
  13575. char ch;
  13576. FILE *fptr1;
  13577. int temptransactionId;
  13578. char str[100]={0};
  13579. temptransactionId = 0;
  13580. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  13581. {
  13582. DEBUG_INFO("IdTag is empty.\n");
  13583. return temptransactionId;
  13584. }
  13585. /*------ Read the file ----------------*/
  13586. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  13587. if (!fptr1)
  13588. {
  13589. DEBUG_INFO("QueueTransactionId file open error.\n");
  13590. //printf(" File not found or unable to open the input file!!\n");
  13591. return temptransactionId;
  13592. }
  13593. ch=fgetc(fptr1);
  13594. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  13595. rewind(fptr1);
  13596. if(ch!=EOF)
  13597. {
  13598. // printf("%c",ch);
  13599. while (fgets(str, 100, fptr1) != NULL)
  13600. {
  13601. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13602. if(str[0]=='\0')
  13603. {
  13604. break;
  13605. }
  13606. char *revbuf[8] = {0}; // Variable store string split
  13607. int num = 0;// Quantity after string split
  13608. DEBUG_INFO("Transaction queue data= %s\n", str);
  13609. splitstring(str,",",revbuf,&num); // String split
  13610. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  13611. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  13612. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  13613. DEBUG_INFO("------------------------------\n");
  13614. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  13615. {
  13616. if(isStopTransaction)
  13617. {
  13618. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  13619. {
  13620. temptransactionId = atoi(revbuf[2]);
  13621. //break;
  13622. }
  13623. }
  13624. else
  13625. {
  13626. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  13627. {
  13628. temptransactionId = atoi(revbuf[2]);
  13629. //break;
  13630. }
  13631. }
  13632. }
  13633. }
  13634. }
  13635. else
  13636. DEBUG_INFO("EOF\n");
  13637. fclose(fptr1);
  13638. /*------- End of reading ---------------*/
  13639. return temptransactionId;
  13640. }
  13641. void SetTransactionIdZero(int transactionId)
  13642. {
  13643. char ch;
  13644. FILE *fptr1, *fptr2;
  13645. int temptransactionId = 0;
  13646. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  13647. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  13648. if (!fptr1)
  13649. {
  13650. //printf(" File not found or unable to open the input file!!\n");
  13651. return ;
  13652. }
  13653. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13654. if (!fptr2)
  13655. {
  13656. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  13657. fclose(fptr1);
  13658. return ;
  13659. }
  13660. ch=fgetc(fptr1);
  13661. rewind(fptr1);
  13662. if(ch!=EOF)
  13663. {
  13664. // copy all contents to the temporary file except the specific line
  13665. while (fgets(str, 100, fptr1) != NULL)
  13666. {
  13667. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13668. if(str[0]=='\0')
  13669. {
  13670. break;
  13671. }
  13672. char *revbuf[8] = {0};
  13673. int num = 0;
  13674. strcpy(strtemp, str);
  13675. splitstring(str,",",revbuf,&num);
  13676. if(revbuf[2][0] != '\0')
  13677. {
  13678. temptransactionId = atoi(revbuf[2]);
  13679. if(transactionId != temptransactionId)
  13680. {
  13681. fprintf(fptr2, "%s\n", strtemp);
  13682. }
  13683. }
  13684. }
  13685. }
  13686. fclose(fptr1);
  13687. fclose(fptr2);
  13688. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13689. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13690. /*------ Read the file ----------------*/
  13691. }
  13692. int InternetDisconnect(void)
  13693. {
  13694. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13695. }
  13696. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  13697. void storeTempStopTransaction(int gun_index)
  13698. {
  13699. char guid[37]={0};
  13700. int tempIndex = 0;
  13701. char TempStopTransaction[256];
  13702. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  13703. DEBUG_INFO("storeTempStopTransaction...\n");
  13704. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  13705. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  13706. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  13707. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13708. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  13709. {
  13710. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13711. {
  13712. tempIndex = ((gun_index==2) ? 1: 0);
  13713. }
  13714. else
  13715. {
  13716. tempIndex = gun_index;
  13717. }
  13718. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13719. {
  13720. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13721. {
  13722. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  13723. }
  13724. }// END OF CHAdeMO_QUANTITY
  13725. }
  13726. else if(gunType[gun_index] == GUN_TYPE_CCS)
  13727. {
  13728. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13729. {
  13730. tempIndex = ((gun_index==2) ? 1: 0);
  13731. }
  13732. else
  13733. {
  13734. tempIndex = gun_index;
  13735. }
  13736. for (int index = 0; index < CCS_QUANTITY; index++)
  13737. {
  13738. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13739. {
  13740. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  13741. }
  13742. }// END OF CCS_QUANTITY
  13743. }
  13744. else if(gunType[gun_index] == GUN_TYPE_GBT)
  13745. {
  13746. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13747. {
  13748. tempIndex = ((gun_index==2) ? 1: 0);
  13749. }
  13750. else
  13751. {
  13752. tempIndex = gun_index;
  13753. }
  13754. for (int index = 0; index < GB_QUANTITY; index++)
  13755. {
  13756. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13757. {
  13758. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  13759. }
  13760. }// END OF GB_QUANTITY
  13761. }
  13762. else if(gunType[gun_index] == GUN_TYPE_DO)
  13763. {
  13764. tempIndex = gun_index;
  13765. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13766. {
  13767. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13768. {
  13769. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  13770. }
  13771. }
  13772. }
  13773. else
  13774. {
  13775. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13776. {
  13777. tempIndex = 2;
  13778. }
  13779. else
  13780. {
  13781. tempIndex = gun_index;
  13782. }
  13783. for (int index = 0; index < AC_QUANTITY; index++)
  13784. {
  13785. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13786. {
  13787. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  13788. }
  13789. }// END OF AC_QUANTITY
  13790. }
  13791. //Stop Transaction Time
  13792. struct timeval tmnow;
  13793. struct tm *tm;
  13794. char buf[28];//, usec_buf[6];
  13795. gettimeofday(&tmnow, NULL);
  13796. time_t t;
  13797. t = time(NULL);
  13798. /*UTC time and date*/
  13799. tm = gmtime(&t);
  13800. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  13801. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  13802. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  13803. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13804. random_uuid(guid);
  13805. /***********************************transactionData******************************************************/
  13806. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  13807. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  13808. //=================================
  13809. //1. Transaction_Begin
  13810. //=================================
  13811. //============================== Energy.Active.Import.Interval ===========================================
  13812. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  13813. {
  13814. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  13815. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  13816. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  13817. 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*/]);
  13818. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13819. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  13820. {
  13821. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  13822. }
  13823. else
  13824. {
  13825. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  13826. }
  13827. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  13828. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13829. }
  13830. //=================================
  13831. //2. Transaction_End
  13832. //=================================
  13833. //2.1====================================== Current.Import L1 ==============================================
  13834. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  13835. {
  13836. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  13837. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  13838. {
  13839. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13840. {
  13841. tempIndex = ((gun_index==2) ? 1: 0);
  13842. }
  13843. else
  13844. {
  13845. tempIndex = gun_index;
  13846. }
  13847. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13848. {
  13849. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13850. {
  13851. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13852. }
  13853. }// End of for CHAdeMO_QUANTITY
  13854. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13855. }
  13856. else if(gunType[gun_index] == GUN_TYPE_CCS)
  13857. {
  13858. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13859. {
  13860. tempIndex = ((gun_index==2) ? 1: 0);
  13861. }
  13862. else
  13863. {
  13864. tempIndex = gun_index;
  13865. }
  13866. for (int index = 0; index < CCS_QUANTITY; index++)
  13867. {
  13868. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13869. {
  13870. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13871. }
  13872. }// End of for CCS_QUANTITY
  13873. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13874. }
  13875. else if(gunType[gun_index] == GUN_TYPE_GBT)
  13876. {
  13877. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13878. {
  13879. tempIndex = ((gun_index==2) ? 1: 0);
  13880. }
  13881. else
  13882. {
  13883. tempIndex = gun_index;
  13884. }
  13885. for (int index = 0; index < GB_QUANTITY; index++)
  13886. {
  13887. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13888. {
  13889. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13890. }
  13891. }// End of for GB_QUANTITY
  13892. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13893. }
  13894. else if(gunType[gun_index] == GUN_TYPE_DO)
  13895. {
  13896. tempIndex = gun_index;
  13897. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13898. {
  13899. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13900. {
  13901. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13902. }
  13903. }
  13904. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13905. }
  13906. else
  13907. {
  13908. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13909. {
  13910. tempIndex = 2;
  13911. }
  13912. else
  13913. {
  13914. tempIndex = gun_index;
  13915. }
  13916. for (int index = 0; index < AC_QUANTITY; index++)
  13917. {
  13918. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13919. {
  13920. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  13921. }
  13922. }// End of for AC_QUANTITY
  13923. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13924. }
  13925. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13926. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  13927. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  13928. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13929. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  13930. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13931. }
  13932. //2.2===================================== Energy.Active.Import.Interval ==========================================
  13933. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  13934. {
  13935. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13936. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  13937. {
  13938. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13939. {
  13940. tempIndex = ((gun_index==2) ? 1: 0);
  13941. }
  13942. else
  13943. {
  13944. tempIndex = gun_index;
  13945. }
  13946. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13947. {
  13948. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13949. {
  13950. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13951. }
  13952. }// END OF CHAdeMO_QUANTITY
  13953. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13954. }
  13955. else if(gunType[gun_index] == GUN_TYPE_CCS)
  13956. {
  13957. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13958. {
  13959. tempIndex = ((gun_index==2) ? 1: 0);
  13960. }
  13961. else
  13962. {
  13963. tempIndex = gun_index;
  13964. }
  13965. for (int index = 0; index < CCS_QUANTITY; index++)
  13966. {
  13967. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13968. {
  13969. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13970. }
  13971. }// END OF CCS_QUANTITY
  13972. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13973. }
  13974. else if(gunType[gun_index] == GUN_TYPE_GBT)
  13975. {
  13976. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13977. {
  13978. tempIndex = ((gun_index==2) ? 1: 0);
  13979. }
  13980. else
  13981. {
  13982. tempIndex = gun_index;
  13983. }
  13984. for (int index = 0; index < GB_QUANTITY; index++)
  13985. {
  13986. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13987. {
  13988. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13989. }
  13990. }// END OF GB_QUANTITY
  13991. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13992. }
  13993. else if(gunType[gun_index] == GUN_TYPE_DO)
  13994. {
  13995. tempIndex = gun_index;
  13996. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13997. {
  13998. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13999. {
  14000. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14001. }
  14002. }
  14003. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14004. }
  14005. else
  14006. {
  14007. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14008. {
  14009. tempIndex = 2;
  14010. }
  14011. else
  14012. {
  14013. tempIndex = gun_index;
  14014. }
  14015. for (int index = 0; index < AC_QUANTITY; index++)
  14016. {
  14017. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14018. {
  14019. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14020. }
  14021. }// END OF AC_QUANTITY
  14022. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  14023. }
  14024. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14025. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  14026. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  14027. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  14028. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  14029. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  14030. }
  14031. //2.3====================================== Power.Active.Import =========================================
  14032. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  14033. {
  14034. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14035. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14036. {
  14037. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14038. {
  14039. tempIndex = ((gun_index==2) ? 1: 0);
  14040. }
  14041. else
  14042. {
  14043. tempIndex = gun_index;
  14044. }
  14045. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14046. {
  14047. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14048. {
  14049. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14050. }
  14051. } // End for CHAdeMO_QUANTITY
  14052. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14053. }
  14054. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14055. {
  14056. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14057. {
  14058. tempIndex = ((gun_index==2) ? 1: 0);
  14059. }
  14060. else
  14061. {
  14062. tempIndex = gun_index;
  14063. }
  14064. for (int index = 0; index < CCS_QUANTITY; index++)
  14065. {
  14066. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14067. {
  14068. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14069. }
  14070. } // END for CCS_QUANTITY
  14071. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14072. }
  14073. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14074. {
  14075. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14076. {
  14077. tempIndex = ((gun_index==2) ? 1: 0);
  14078. }
  14079. else
  14080. {
  14081. tempIndex = gun_index;
  14082. }
  14083. for (int index = 0; index < GB_QUANTITY; index++)
  14084. {
  14085. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14086. {
  14087. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14088. }
  14089. }// END for GB_QUANTITY
  14090. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14091. }
  14092. else if(gunType[gun_index] == GUN_TYPE_DO)
  14093. {
  14094. tempIndex = gun_index;
  14095. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14096. {
  14097. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14098. {
  14099. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14100. }
  14101. }
  14102. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14103. }
  14104. else
  14105. {
  14106. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14107. {
  14108. tempIndex = 2;
  14109. }
  14110. else
  14111. {
  14112. tempIndex = gun_index;
  14113. }
  14114. for (int index = 0; index < AC_QUANTITY; index++)
  14115. {
  14116. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14117. {
  14118. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14119. }
  14120. } // END for AC_QUANTITY
  14121. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  14122. }
  14123. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14124. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  14125. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  14126. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  14127. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  14128. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  14129. }
  14130. //2.4====================================== Voltage L1 ====================================================
  14131. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  14132. {
  14133. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14134. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14135. {
  14136. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14137. {
  14138. tempIndex = ((gun_index==2) ? 1: 0);
  14139. }
  14140. else
  14141. {
  14142. tempIndex = gun_index;
  14143. }
  14144. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14145. {
  14146. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14147. {
  14148. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14149. }
  14150. } // END OF FOR CHAdeMO_QUANTITY
  14151. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14152. }
  14153. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14154. {
  14155. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14156. {
  14157. tempIndex = ((gun_index==2) ? 1: 0);
  14158. }
  14159. else
  14160. {
  14161. tempIndex = gun_index;
  14162. }
  14163. for (int index = 0; index < CCS_QUANTITY; index++)
  14164. {
  14165. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14166. {
  14167. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14168. }
  14169. } // END OF FOR CCS_QUANTITY
  14170. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14171. }
  14172. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14173. {
  14174. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14175. {
  14176. tempIndex = ((gun_index==2) ? 1: 0);
  14177. }
  14178. else
  14179. {
  14180. tempIndex = gun_index;
  14181. }
  14182. for (int index = 0; index < GB_QUANTITY; index++)
  14183. {
  14184. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14185. {
  14186. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14187. }
  14188. } // END OF FOR GB_QUANTITY
  14189. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14190. }
  14191. else if(gunType[gun_index] == GUN_TYPE_DO)
  14192. {
  14193. tempIndex = gun_index;
  14194. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14195. {
  14196. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14197. {
  14198. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14199. }
  14200. }
  14201. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14202. }
  14203. else
  14204. {
  14205. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14206. {
  14207. tempIndex = 2;
  14208. }
  14209. else
  14210. {
  14211. tempIndex = gun_index;
  14212. }
  14213. for (int index = 0; index < AC_QUANTITY; index++)
  14214. {
  14215. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14216. {
  14217. 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
  14218. }
  14219. } // END OF FOR AC_QUANTITY
  14220. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  14221. }
  14222. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14223. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  14224. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  14225. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  14226. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  14227. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  14228. }
  14229. //2.5============================================== End SoC =========================================================
  14230. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  14231. {
  14232. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14233. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  14234. {
  14235. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  14236. {
  14237. tempIndex = ((gun_index==2) ? 1: 0);
  14238. }
  14239. else
  14240. {
  14241. tempIndex = gun_index;
  14242. }
  14243. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14244. {
  14245. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14246. {
  14247. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14248. {
  14249. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  14250. }
  14251. }
  14252. }
  14253. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14254. {
  14255. for (int index = 0; index < CCS_QUANTITY; index++)
  14256. {
  14257. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14258. {
  14259. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  14260. }
  14261. }
  14262. }
  14263. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14264. {
  14265. for (int index = 0; index < GB_QUANTITY; index++)
  14266. {
  14267. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14268. {
  14269. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  14270. }
  14271. }
  14272. }
  14273. else if(gunType[gun_index] == GUN_TYPE_DO)
  14274. {
  14275. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14276. {
  14277. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14278. {
  14279. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  14280. }
  14281. }
  14282. }
  14283. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14284. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  14285. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  14286. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  14287. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  14288. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  14289. } // END FOR DC CASE
  14290. }
  14291. //2.6====================================== Current.Import L2 ==============================================
  14292. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  14293. {
  14294. // AC 3 phase L2 current
  14295. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  14296. {
  14297. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14298. {
  14299. tempIndex = 2;
  14300. }
  14301. else
  14302. {
  14303. tempIndex = gun_index;
  14304. }
  14305. for (int index = 0; index < AC_QUANTITY; index++)
  14306. {
  14307. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14308. {
  14309. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  14310. }
  14311. }// End of for AC_QUANTITY
  14312. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  14313. }
  14314. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14315. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  14316. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  14317. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  14318. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14319. }
  14320. //2.7====================================== Current.Import L3 ==============================================
  14321. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  14322. {
  14323. // AC 3 phase L3 current
  14324. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  14325. {
  14326. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14327. {
  14328. tempIndex = 2;
  14329. }
  14330. else
  14331. {
  14332. tempIndex = gun_index;
  14333. }
  14334. for (int index = 0; index < AC_QUANTITY; index++)
  14335. {
  14336. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14337. {
  14338. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  14339. }
  14340. }// End of for AC_QUANTITY
  14341. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  14342. }
  14343. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14344. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  14345. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  14346. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  14347. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14348. }
  14349. //2.9====================================== Voltage L2 ====================================================
  14350. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  14351. {
  14352. // AC 3 phase L2 volatge
  14353. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  14354. {
  14355. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14356. {
  14357. tempIndex = 2;
  14358. }
  14359. else
  14360. {
  14361. tempIndex = gun_index;
  14362. }
  14363. for (int index = 0; index < AC_QUANTITY; index++)
  14364. {
  14365. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14366. {
  14367. 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
  14368. }
  14369. } // END OF FOR AC_QUANTITY
  14370. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  14371. }
  14372. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14373. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  14374. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  14375. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  14376. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  14377. }
  14378. //2.10====================================== Voltage L3 ====================================================
  14379. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  14380. {
  14381. // AC 3 phase L3 volatge
  14382. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  14383. {
  14384. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14385. {
  14386. tempIndex = 2;
  14387. }
  14388. else
  14389. {
  14390. tempIndex = gun_index;
  14391. }
  14392. for (int index = 0; index < AC_QUANTITY; index++)
  14393. {
  14394. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14395. {
  14396. 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
  14397. }
  14398. } // END OF FOR AC_QUANTITY
  14399. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  14400. }
  14401. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14402. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  14403. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  14404. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  14405. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  14406. }
  14407. //====================== Start SoC ================================
  14408. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  14409. {
  14410. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14411. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  14412. {
  14413. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  14414. {
  14415. tempIndex = ((gun_index==2) ? 1: 0);
  14416. }
  14417. else
  14418. {
  14419. tempIndex = gun_index;
  14420. }
  14421. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14422. {
  14423. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14424. {
  14425. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14426. {
  14427. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  14428. }
  14429. }
  14430. }
  14431. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14432. {
  14433. for (int index = 0; index < CCS_QUANTITY; index++)
  14434. {
  14435. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14436. {
  14437. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  14438. }
  14439. }
  14440. }
  14441. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14442. {
  14443. for (int index = 0; index < GB_QUANTITY; index++)
  14444. {
  14445. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14446. {
  14447. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  14448. }
  14449. }
  14450. }
  14451. else if(gunType[gun_index] == GUN_TYPE_DO)
  14452. {
  14453. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14454. {
  14455. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14456. {
  14457. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  14458. }
  14459. }
  14460. }
  14461. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  14462. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  14463. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  14464. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  14465. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  14466. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  14467. } // END FOR DC CASE
  14468. }
  14469. //======================================== Message create ==============================================
  14470. json_object *StopTransaction = json_object_new_object();
  14471. json_object *transactionDatas = json_object_new_array();
  14472. json_object *sampledValues = json_object_new_array();
  14473. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  14474. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  14475. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  14476. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  14477. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  14478. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  14479. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  14480. {
  14481. json_object *transactionData = json_object_new_object();
  14482. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  14483. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  14484. {
  14485. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  14486. {
  14487. json_object *sampledValue = json_object_new_object();
  14488. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  14489. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  14490. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  14491. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  14492. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  14493. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  14494. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  14495. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  14496. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  14497. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  14498. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  14499. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  14500. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  14501. json_object_array_add(sampledValues, sampledValue);
  14502. }
  14503. }
  14504. json_object_object_add(transactionData, "sampledValue", sampledValues);
  14505. json_object_array_add(transactionDatas, transactionData);
  14506. }
  14507. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  14508. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  14509. ,MESSAGE_TYPE_CALL
  14510. ,guid
  14511. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  14512. json_object_put(StopTransaction);
  14513. // Check File "TempStopTransaction" Exist
  14514. if((access(TempStopTransaction,F_OK))!=-1)
  14515. {
  14516. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  14517. fclose(fopen(TempStopTransaction, "w"));
  14518. }
  14519. else
  14520. {
  14521. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  14522. FILE *log = fopen(TempStopTransaction, "w+");
  14523. if(log == NULL)
  14524. {
  14525. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  14526. return ;
  14527. }
  14528. else
  14529. {
  14530. fclose(log);
  14531. }
  14532. }
  14533. //Add TempStopTransaction | Update TempStopTransaction
  14534. // open file for writing
  14535. FILE *outfile;
  14536. outfile = fopen (TempStopTransaction, "a");
  14537. //DEBUG_INFO("data = %s\n", queuedata);
  14538. fputs(queuedata, outfile);
  14539. fputs("\n", outfile);
  14540. fclose (outfile);
  14541. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14542. }
  14543. void checkTempStopTransaction(int gun_index)
  14544. {
  14545. FILE *fptr1;
  14546. char ch;
  14547. char str[QUEUE_MESSAGE_LENGTH]={0};
  14548. char guid[37]={0};
  14549. char tempdata[65]={0};
  14550. char connectorStr[2]={0};
  14551. char TempStopTransaction[256];
  14552. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  14553. fptr1 = fopen(TempStopTransaction, "r");
  14554. //TempStopTransaction格式: 槍號,StopTransaction封包
  14555. if (!fptr1)
  14556. {
  14557. //printf(" File not found or unable to open the input file!!\n");
  14558. return ;
  14559. }
  14560. ch=fgetc(fptr1);
  14561. //printf(" Now the content of the file %s is : \n",fname);
  14562. rewind(fptr1);
  14563. if(ch!=EOF)
  14564. {
  14565. // copy all contents to the temporary file except the specific line
  14566. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  14567. {
  14568. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14569. if(str[0]=='\0')
  14570. {
  14571. break;
  14572. }
  14573. //TempStopTransaction格式: 槍號,StopTransaction封包
  14574. strncpy(connectorStr, str, 1);
  14575. if(atoi(connectorStr) != (gun_index+1))
  14576. {
  14577. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  14578. fclose(fptr1);
  14579. return ;
  14580. }
  14581. //random_uuid(guid);
  14582. strncpy(guid, str+6, 36); //copy guid
  14583. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  14584. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  14585. {
  14586. //DEBUG_INFO("StopTransaction mapitem pass\n");
  14587. }
  14588. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  14589. memset(str,0,ARRAY_SIZE(str));
  14590. }
  14591. }
  14592. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  14593. fclose(fptr1);
  14594. remove(TempStopTransaction); // remove the original file
  14595. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14596. }
  14597. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  14598. {
  14599. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  14600. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  14601. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  14602. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  14603. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  14604. }
  14605. int GetWebSocketPingInterval(void)
  14606. {
  14607. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14608. }
  14609. int GetServerSign(void)
  14610. {
  14611. return server_sign;
  14612. }
  14613. uint8_t GetOcppSecurityProfile()
  14614. {
  14615. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14616. }
  14617. void GetOcppChargerBoxId(uint8_t *data)
  14618. {
  14619. sprintf((char*)data, "%s", ShmOCPP16Data->ChargeBoxId);
  14620. }
  14621. void GetOcppSecurityPassword(uint8_t *data)
  14622. {
  14623. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14624. }
  14625. void SetOcppVersion(uint8_t *version)
  14626. {
  14627. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  14628. DEBUG_INFO("ocpp version: %s\n", version);
  14629. if(strstr((char*)version, "ocpp1.6") != NULL)
  14630. {
  14631. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  14632. }
  14633. else if(strstr((char*)version, "ocpp2.0") != NULL)
  14634. {
  14635. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  14636. system("pkill OcppBackend");
  14637. }
  14638. }
  14639. void SetServerSign(int value)
  14640. {
  14641. server_sign = value;
  14642. }
  14643. int GetBootNotificationInterval(void)
  14644. {
  14645. return BootNotificationInterval;
  14646. }
  14647. int GetInternetConn(void)
  14648. {
  14649. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  14650. }
  14651. int isConnectorInitMode(int gun_index)
  14652. {
  14653. int tempIndex = 0;
  14654. int result = TRUE;
  14655. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14656. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14657. {
  14658. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14659. {
  14660. tempIndex = ((gun_index==2) ? 1: 0);
  14661. }
  14662. else
  14663. {
  14664. tempIndex = gun_index;
  14665. }
  14666. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14667. {
  14668. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  14669. {
  14670. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  14671. } //end of the same index
  14672. }//end of for CHAdeMO_QUANTITY
  14673. }
  14674. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14675. {
  14676. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14677. {
  14678. tempIndex = ((gun_index==2) ? 1: 0);
  14679. }
  14680. else
  14681. {
  14682. tempIndex = gun_index;
  14683. }
  14684. for (int index = 0; index < CCS_QUANTITY; index++)
  14685. {
  14686. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14687. {
  14688. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  14689. } //end of the same index
  14690. } // end of for CCS_QUANTITY
  14691. }
  14692. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14693. {
  14694. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14695. {
  14696. tempIndex = ((gun_index==2) ? 1: 0);
  14697. }
  14698. else
  14699. {
  14700. tempIndex = gun_index;
  14701. }
  14702. for (int index = 0; index < GB_QUANTITY; index++)
  14703. {
  14704. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14705. {
  14706. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  14707. } //end of the same index
  14708. } // end of for GB_QUANTITY
  14709. }
  14710. else if(gunType[gun_index] == GUN_TYPE_DO)
  14711. {
  14712. tempIndex = gun_index;
  14713. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14714. {
  14715. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14716. {
  14717. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  14718. } //end of the same index
  14719. }
  14720. }
  14721. else
  14722. {
  14723. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14724. {
  14725. tempIndex = 2;
  14726. }
  14727. else
  14728. {
  14729. tempIndex = gun_index;
  14730. }
  14731. for (int index = 0; index < AC_QUANTITY; index++)
  14732. {
  14733. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14734. {
  14735. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  14736. }//end of the same index
  14737. }//end of for AC_QUANTITY
  14738. }
  14739. return result;
  14740. }
  14741. void refreshProcDogTimer()
  14742. {
  14743. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  14744. }
  14745. void InitialSystemValue(void)
  14746. {
  14747. int connectorIndex = 0;
  14748. //int valueASCII = 0;
  14749. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14750. gunTotalNumber=0;
  14751. SystemInitial = 0;
  14752. localversion=0;
  14753. BootNotificationInterval = 0;
  14754. authorizeRetryTimes = 0;
  14755. GunStatusInterval = 10;
  14756. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14757. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14758. //Hear Beat
  14759. HeartBeatWithNOResponse = 0;
  14760. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  14761. FirstHeartBeat = 0;
  14762. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  14763. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  14764. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  14765. memset(statusModeChage, 0, ARRAY_SIZE(statusModeChage));
  14766. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  14767. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  14768. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  14769. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  14770. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  14771. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  14772. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  14773. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  14774. memset(gunType, 0, ARRAY_SIZE(gunType));
  14775. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14776. {
  14777. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O')
  14778. {
  14779. // DO series
  14780. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  14781. {
  14782. SystemInitial = SystemInitial + 1;
  14783. gunTotalNumber = gunTotalNumber + 1;
  14784. gunType[connectorIndex] = GUN_TYPE_DO;
  14785. connectorIndex = connectorIndex + 1;
  14786. }
  14787. }
  14788. else
  14789. {
  14790. // DM, DW, DS series
  14791. //check connector / socket type (index: 8, 9, 10)
  14792. for(int index=7; index <10 ; index++)
  14793. {
  14794. if(index != 8)
  14795. {
  14796. // DC Connector
  14797. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  14798. {
  14799. SystemInitial = SystemInitial + 1;
  14800. gunTotalNumber = gunTotalNumber + 1;
  14801. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  14802. connectorIndex = connectorIndex + 1;
  14803. }
  14804. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  14805. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  14806. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  14807. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  14808. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  14809. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  14810. {
  14811. SystemInitial = SystemInitial + 1;
  14812. gunTotalNumber = gunTotalNumber + 1;
  14813. gunType[connectorIndex] = GUN_TYPE_CCS;
  14814. connectorIndex = connectorIndex + 1;
  14815. }
  14816. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  14817. {
  14818. SystemInitial = SystemInitial + 1;
  14819. gunTotalNumber = gunTotalNumber + 1;
  14820. gunType[connectorIndex] = GUN_TYPE_GBT;
  14821. connectorIndex = connectorIndex + 1;
  14822. }
  14823. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  14824. {
  14825. SystemInitial = SystemInitial + 1;
  14826. gunTotalNumber = gunTotalNumber + 1;
  14827. gunType[connectorIndex] = GUN_TYPE_DO;
  14828. connectorIndex = connectorIndex + 1;
  14829. }
  14830. }
  14831. else
  14832. {
  14833. // AC Connector
  14834. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14835. {
  14836. SystemInitial = SystemInitial + 1;
  14837. gunTotalNumber = gunTotalNumber + 1;
  14838. gunType[connectorIndex] = GUN_TYPE_AC;
  14839. connectorIndex = connectorIndex + 1;
  14840. }
  14841. }
  14842. }
  14843. }
  14844. //DEBUG_INFO("DC ...\n");
  14845. }
  14846. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  14847. {
  14848. //check connector / socket type (index: 8, 9, 10)
  14849. for(int index=7; index <10 ; index++)
  14850. {
  14851. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14852. {
  14853. SystemInitial = SystemInitial + 1;
  14854. gunTotalNumber = gunTotalNumber + 1;
  14855. gunType[connectorIndex] = GUN_TYPE_AC;
  14856. connectorIndex = connectorIndex + 1;
  14857. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  14858. }
  14859. }
  14860. }
  14861. //Status && ConnectorPlugIn Setting
  14862. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14863. {
  14864. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  14865. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  14866. }
  14867. for (int index = 0; index < CCS_QUANTITY; index++)
  14868. {
  14869. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  14870. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  14871. }
  14872. for (int index = 0; index < GB_QUANTITY; index++)
  14873. {
  14874. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  14875. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  14876. }
  14877. for (int index = 0; index < AC_QUANTITY; index++)
  14878. {
  14879. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  14880. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  14881. }
  14882. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14883. {
  14884. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  14885. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  14886. }
  14887. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  14888. {
  14889. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  14890. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  14891. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  14892. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  14893. }
  14894. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  14895. clientTime.Heartbeat=time((time_t*)NULL);
  14896. sleep(1);
  14897. }
  14898. void LWS_Send(char * str)
  14899. {
  14900. //=====================================================
  14901. // Check InternetConn 0: disconnected, 1: connected
  14902. //====================================================
  14903. if(GetOcppConnStatus() == 0)
  14904. {
  14905. DEBUG_INFO("offline now !!!\n");
  14906. return;
  14907. }
  14908. pthread_mutex_lock(&lock_send);
  14909. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14910. sprintf((char *)SendBuffer, "%s", str);
  14911. SendBufLen = strlen(str);
  14912. pthread_mutex_unlock(&lock_send);
  14913. lws_callback_on_writable(wsi_client);
  14914. //lws_service(context, 0);
  14915. //sleep(1);
  14916. }
  14917. void LWS_SendNow(char * str)
  14918. {
  14919. //=====================================================
  14920. // Check InternetConn 0: disconnected, 1: connected
  14921. //====================================================
  14922. if(GetOcppConnStatus() == 0)
  14923. {
  14924. DEBUG_INFO("offline now !!!\n");
  14925. return;
  14926. }
  14927. pthread_mutex_lock(&lock_send);
  14928. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14929. sprintf((char *)SendBuffer, "%s", str);
  14930. SendBufLen = strlen(str);
  14931. pthread_mutex_unlock(&lock_send);
  14932. lws_callback_on_writable(wsi_client);
  14933. lws_service(context, 0);
  14934. //sleep(1);
  14935. }