MessageHandler.c 731 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187
  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. // Sqlite3 related function
  355. //=========================================
  356. static int selectSqlCount = 0;
  357. static int callback(void *data, int argc, char **argv, char **azColName){
  358. int i;
  359. //printf("%s: ", (const char*)data);
  360. selectSqlCount = argc;
  361. for(i = 0; i<argc; i++){
  362. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  363. }
  364. //printf("\n");
  365. return 0;
  366. }
  367. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  368. //int i;
  369. //printf("%s:\n", (const char*)data);
  370. localversion = argv[5] ? atoi(argv[5]) : 0;
  371. //printf("localversion=%d\n", localversion);
  372. return 0;
  373. }
  374. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  375. //printf("%s:\n", (const char*)data);
  376. //idTag
  377. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  378. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  379. //parentIdTag
  380. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  381. //expir_date
  382. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  383. //status
  384. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  385. //version
  386. if(columenCount > 5)
  387. idTagQuery.listVersionInt = atoi(columnValue[5]);
  388. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  389. return 0;
  390. }
  391. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  392. {
  393. // localversion = argv[5] ? atoi(argv[5]) : 0;
  394. // printf("localversion=%d\n", localversion);
  395. return 0;
  396. }
  397. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  398. {
  399. for (int i = 0; i < n_columns; i++)
  400. {
  401. DEBUG_INFO("%s\t", col_values[i]);
  402. }
  403. DEBUG_INFO("\n");
  404. return 0;
  405. }
  406. int OCPP_cleanLocalCache()
  407. {
  408. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  409. char *errMsg = 0;
  410. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  411. if (SQLITE_OK != rc)
  412. {
  413. DEBUG_INFO("SQL error: %s\n",errMsg);
  414. return FALSE;
  415. }
  416. return TRUE;
  417. }
  418. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  419. {
  420. int isSuccess = TRUE;
  421. int ret = 0;
  422. //const char* data = "Callback function called";
  423. char sql[300];
  424. char zErrMsg[200];
  425. memset(sql, 0, 300);
  426. memset(zErrMsg, 0, 200);
  427. 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);
  428. //* Execute SQL statement */
  429. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  430. if( ret != SQLITE_OK )
  431. {
  432. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  433. isSuccess = FALSE;
  434. }
  435. return isSuccess;
  436. }
  437. void OCPP_getIdTagFromLocalCache(char idTag[])
  438. {
  439. int rc = 0;
  440. char sql[100];
  441. char zErrMsg[100];
  442. memset(sql, 0, 100);
  443. memset(zErrMsg, 0, 100);
  444. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  445. memset(&idTagQuery, 0, sizeof(idTagQuery));
  446. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  447. /* Execute SQL statement */
  448. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  449. if( rc != SQLITE_OK )
  450. {
  451. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  452. }
  453. }
  454. void OCPP_getListVerion()
  455. {
  456. int rc = 0;
  457. // const char* data = "Callback function called";
  458. char sql[100];
  459. char zErrMsg[100];
  460. memset(sql, 0, 100);
  461. memset(zErrMsg, 0, 100);
  462. strcpy(sql, "select * from ocpp_auth_local order by idx");
  463. /* Execute SQL statement */
  464. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  465. if( rc != SQLITE_OK )
  466. {
  467. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  468. }
  469. }
  470. void OCPP_get_TableAuthlocalAllData(void)
  471. {
  472. int rc = 0;
  473. char sql[100];
  474. char zErrMsg[100];
  475. memset(sql, 0, 100);
  476. memset(zErrMsg, 0, 100);
  477. sprintf(sql,"select * from ocpp_auth_local ");
  478. /* Execute SQL statement */
  479. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  480. if( rc != SQLITE_OK )
  481. {
  482. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  483. }
  484. //return ver;
  485. }
  486. int OCPP_cleanLocalList()
  487. {
  488. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  489. char *errMsg = 0;
  490. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  491. if (SQLITE_OK != rc)
  492. {
  493. DEBUG_INFO("%s\n",errMsg);
  494. return FALSE;
  495. }
  496. return TRUE;
  497. }
  498. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  499. {
  500. int isSuccess = FALSE;
  501. int ret = 0;
  502. //const char* data = "Callback function called";
  503. char sql[300];
  504. char zErrMsg[200];
  505. memset(sql, 0, 300);
  506. memset(zErrMsg, 0, 200);
  507. 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);
  508. //* Execute SQL statement */
  509. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  510. if( ret != SQLITE_OK )
  511. {
  512. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  513. return isSuccess;
  514. }
  515. memset(sql, 0, 300);
  516. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  517. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  518. if( ret != SQLITE_OK )
  519. {
  520. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  521. return isSuccess;
  522. }
  523. isSuccess = TRUE;
  524. return isSuccess;
  525. }
  526. void OCPP_getIdTagFromLocalList(char idTag[])
  527. {
  528. int rc = 0;
  529. // const char* data = "Callback function called";
  530. char sql[100];
  531. char zErrMsg[100];
  532. memset(sql, 0, 100);
  533. memset(zErrMsg, 0, 100);
  534. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  535. memset(&idTagQuery, 0, sizeof(idTagQuery));
  536. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  537. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  538. /* Execute SQL statement */
  539. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  540. if( rc != SQLITE_OK )
  541. {
  542. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  543. }
  544. //return ver;
  545. }
  546. void OCPP_deleteIdTagFromLocalList(char idTag[])
  547. {
  548. //int ver = 0;
  549. //int isSuccess = FALSE;
  550. int rc = 0;
  551. char sql[100];
  552. char zErrMsg[100];
  553. memset(sql, 0, 100);
  554. memset(zErrMsg, 0, 100);
  555. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  556. //* Execute SQL statement */
  557. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  558. if( rc != SQLITE_OK )
  559. {
  560. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  561. }
  562. }
  563. int getCurrentYear()
  564. {
  565. int result = 0;
  566. time_t CurrentTime;
  567. struct tm *tm;
  568. CurrentTime = time(NULL);
  569. tm=localtime(&CurrentTime);
  570. result = (tm->tm_year + 1900);
  571. return result;
  572. }
  573. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  574. {
  575. int result = PASS;
  576. char* errMsg = NULL;
  577. char sqlStr[8192];
  578. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  579. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  580. {
  581. result = FAIL;
  582. DEBUG_INFO( "Insert local transaction record error message: %s\n", errMsg);
  583. }
  584. sprintf(sqlStr, "delete from ocpp_transaction_record where (idx < (select idx from ocpp_transaction_record order by idx desc limit 1)-2000) and (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  585. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  586. {
  587. result = FAIL;
  588. DEBUG_INFO( "delete local transaction record error message: %s\n", errMsg);
  589. }
  590. return result;
  591. }
  592. //==========================================
  593. // Check time passed since today
  594. //==========================================
  595. long long DiffTimebWithNow(struct timeb ST)
  596. {
  597. //return milli-second
  598. struct timeb ET;
  599. long long StartTime,StopTime;
  600. ftime(&ET);
  601. StartTime=(long long)ST.time;
  602. StopTime=(long long)ET.time;
  603. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  604. }
  605. int getTimePassSinceToday()
  606. {
  607. int result = -1;
  608. static time_t lastTime;
  609. time_t t;
  610. struct tm *tmStartToday;
  611. struct timeb tbStartToday;
  612. t=time(NULL);
  613. if(difftime(t, lastTime)>0)
  614. {
  615. tmStartToday=localtime(&t);
  616. tmStartToday->tm_hour = 0;
  617. tmStartToday->tm_min = 0;
  618. tmStartToday->tm_sec = 0;
  619. tbStartToday.time = mktime(tmStartToday);
  620. tbStartToday.millitm = 0;
  621. result = DiffTimebWithNow(tbStartToday)/1000;
  622. lastTime = t;
  623. }
  624. return result;
  625. }
  626. void getNowDatetime(uint8_t *data)
  627. {
  628. time_t t = time(NULL);
  629. struct tm tm = *localtime(&t);
  630. 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);
  631. }
  632. int syncDateTimeRTC(uint8_t *data)
  633. {
  634. struct ParsingResult
  635. {
  636. int result;
  637. int scanedElement;
  638. int year;
  639. int month;
  640. int mday;
  641. int hour;
  642. int min;
  643. int sec;
  644. int tz_hour;
  645. int tz_min;
  646. float minSec;
  647. }result;
  648. struct tm tmOrg;
  649. struct tm *tmTarget;
  650. struct timeb tbTarget;
  651. char buf[128];
  652. memset(&result, 0x00, sizeof(struct ParsingResult));
  653. result.result = PASS;
  654. if(strstr((char*)data, ".") != NULL)
  655. {
  656. // Original data with mini second
  657. if(strstr((char*)data, "Z") != NULL)
  658. {
  659. // Original data with Z
  660. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  661. &result.year,
  662. &result.month,
  663. &result.mday,
  664. &result.hour,
  665. &result.min,
  666. &result.sec,
  667. &result.minSec);
  668. }
  669. else
  670. {
  671. // Original data without Z
  672. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  673. &result.year,
  674. &result.month,
  675. &result.mday,
  676. &result.hour,
  677. &result.min,
  678. &result.sec,
  679. &result.minSec,
  680. &result.tz_hour,
  681. &result.tz_min);
  682. }
  683. }
  684. else
  685. {
  686. // Original data without mini second
  687. if(strstr((char*)data, "Z") != NULL)
  688. {
  689. // Original data with Z
  690. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  691. &result.year,
  692. &result.month,
  693. &result.mday,
  694. &result.hour,
  695. &result.min,
  696. &result.sec);
  697. }
  698. else
  699. {
  700. // Original data without Z
  701. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  702. &result.year,
  703. &result.month,
  704. &result.mday,
  705. &result.hour,
  706. &result.min,
  707. &result.sec,
  708. &result.tz_hour,
  709. &result.tz_min);
  710. }
  711. }
  712. tmOrg.tm_year = result.year - 1900;
  713. tmOrg.tm_mon = result.month - 1;
  714. tmOrg.tm_mday = result.mday;
  715. tmOrg.tm_hour = result.hour;
  716. tmOrg.tm_min = result.min;
  717. tmOrg.tm_sec = result.sec;
  718. tmOrg.tm_gmtoff = 0;
  719. tbTarget.time = mktime(&tmOrg);
  720. tbTarget.timezone = 0;
  721. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  722. tmTarget = gmtime(&tbTarget.time);
  723. sprintf(buf, "date -s '%04d-%02d-%02d %02d:%02d:%02d'", (tmTarget->tm_year+1900), (tmTarget->tm_mon+1), tmTarget->tm_mday, tmTarget->tm_hour, tmTarget->tm_min, tmTarget->tm_sec);
  724. //DEBUG_INFO(" org date time: %s\n", data);
  725. //DEBUG_INFO("parse date time: %s\n", buf);
  726. system(buf);
  727. system("/sbin/hwclock -w --systohc");
  728. if(result.scanedElement < 6)
  729. result.result = FAIL;
  730. return result.result;
  731. }
  732. //==========================================
  733. // GetCompositeSchedule logic related function
  734. //==========================================
  735. int DiffTimebSec(struct timeb ST, struct timeb ET)
  736. {
  737. //return milli-second
  738. unsigned int StartTime,StopTime;
  739. StartTime=(unsigned int)ST.time;
  740. StopTime=(unsigned int)ET.time;
  741. return (StopTime-StartTime);
  742. }
  743. int DiffTimebWithNowSec(struct timeb ST)
  744. {
  745. //return milli-second
  746. struct timeb ET;
  747. unsigned int StartTime,StopTime;
  748. ftime(&ET);
  749. StartTime=(unsigned int)ST.time;
  750. StopTime=(unsigned int)ET.time;
  751. return (StopTime-StartTime);
  752. }
  753. int getStartStop(uint8_t *start, uint8_t *stop)
  754. {
  755. int result = -1;
  756. struct tm tmStart;
  757. struct timeb tbStart;
  758. struct tm tmStop;
  759. struct timeb tbStop;
  760. 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) &&
  761. (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))
  762. {
  763. //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);
  764. //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);
  765. tmStart.tm_year -= 1900;
  766. tmStart.tm_mon -= 1;
  767. tbStart.time = mktime(&tmStart);
  768. tbStart.millitm = 0;
  769. tmStop.tm_year -= 1900;
  770. tmStop.tm_mon -= 1;
  771. tbStop.time = mktime(&tmStop);
  772. tbStop.millitm = 0;
  773. result = DiffTimebSec(tbStart, tbStop);
  774. //DEBUG_INFO("getStartStop(): %d\n", result);
  775. }
  776. else
  777. {
  778. DEBUG_WARN("Start or stop date parsing error.\r\n");
  779. }
  780. return result;
  781. }
  782. int isOvertNow(uint8_t *start)
  783. {
  784. int result = NO;
  785. struct tm tmStart;
  786. struct timeb tbStart;
  787. 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))
  788. {
  789. //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);
  790. tmStart.tm_year -= 1900;
  791. tmStart.tm_mon -= 1;
  792. tbStart.time = mktime(&tmStart);
  793. tbStart.millitm = 0;
  794. if(DiffTimebWithNowSec(tbStart) <= 0)
  795. result = NO;
  796. else
  797. result = YES;
  798. }
  799. else
  800. {
  801. DEBUG_WARN("Start date parsing error.\n");
  802. }
  803. return result;
  804. }
  805. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  806. {
  807. int result = -1;
  808. struct tm tmStart;
  809. struct timeb tbStart;
  810. struct tm tmStop;
  811. struct timeb tbStop;
  812. 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) &&
  813. (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))
  814. {
  815. tmStart.tm_year -= 1900;
  816. tmStart.tm_mon -= 1;
  817. tbStart.time = mktime(&tmStart);
  818. tbStart.millitm = 0;
  819. tmStop.tm_year -= 1900;
  820. tmStop.tm_mon -= 1;
  821. tbStop.time = mktime(&tmStop);
  822. tbStop.millitm = 0;
  823. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  824. }
  825. return result;
  826. }
  827. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  828. {
  829. FILE *fp;
  830. char profileFileName[128];
  831. char *line = NULL;
  832. size_t len = 0;
  833. time_t CurrentTime;
  834. struct tm *tmComposite;
  835. struct StructChargingProfile maxProfile;
  836. struct StructChargingProfile defaultTxProfile;
  837. struct StructChargingProfile txProfile;
  838. struct StructChargingSchedulePeriod tmpPeriod;
  839. uint8_t limitMax=0;
  840. uint8_t limitDef=0;
  841. uint8_t limitTx=0;
  842. int compositePeriodIdx = 0;
  843. CurrentTime = time(NULL);
  844. tmComposite=localtime(&CurrentTime);
  845. 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);
  846. if(isUnitA)
  847. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  848. else
  849. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  850. compositeProfile->ChargingSchedule.Duration = durationReq;
  851. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  852. {
  853. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  854. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  855. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  856. }
  857. compositeProfile->ChargingProfileId = 0;
  858. compositeProfile->StackLevel = 99 ;
  859. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  860. maxProfile.ChargingProfileId = -1;
  861. defaultTxProfile.ChargingProfileId = -1;
  862. txProfile.ChargingProfileId = -1;
  863. maxProfile.ChargingSchedule.Duration = -1;
  864. defaultTxProfile.ChargingSchedule.Duration = -1;
  865. txProfile.ChargingSchedule.Duration = -1;
  866. system("yes|rm /tmp/*.json");
  867. system("cp /Storage/OCPP/*.json /tmp");
  868. /*
  869. * Search valid charging profile
  870. */
  871. //DEBUG_INFO("====================================\n");
  872. // Search tx profile
  873. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  874. if((access(profileFileName, F_OK))!=-1)
  875. {
  876. fp = fopen(profileFileName, "r");
  877. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  878. {
  879. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  880. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  881. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  882. }
  883. txProfile.ChargingProfileId = -1;
  884. txProfile.StackLevel = -1;
  885. while(getline(&line, &len, fp) != -1)
  886. {
  887. json_object *obj = NULL;
  888. obj = json_tokener_parse(line);
  889. if(is_error(obj))
  890. {
  891. DEBUG_ERROR("Parse txProfile from file error.\n");
  892. }
  893. else
  894. {
  895. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  896. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  897. )
  898. {
  899. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  900. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  901. )
  902. {
  903. struct tm tmFrom, tmTo;
  904. struct timeb tbFrom, tbTo;
  905. 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) &&
  906. (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))
  907. {
  908. tmFrom.tm_year -= 1900;
  909. tmFrom.tm_mon -= 1;
  910. tbFrom.time = mktime(&tmFrom);
  911. tmTo.tm_year -= 1900;
  912. tmTo.tm_mon -= 1;
  913. tbTo.time = mktime(&tmTo);
  914. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  915. {
  916. if(txProfile.ChargingProfileId == -1)
  917. DEBUG_INFO("TxProfile found.\n");
  918. else
  919. DEBUG_INFO("TxProfile updated.\n");
  920. // Required item
  921. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  922. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  923. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  924. if(isUnitA)
  925. {
  926. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  927. 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++)
  928. {
  929. 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"));
  930. 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?
  931. 3:
  932. 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")));
  933. 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")));
  934. }
  935. }
  936. else
  937. {
  938. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  939. 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++)
  940. {
  941. 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"));
  942. 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?
  943. 3:
  944. 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")));
  945. 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));
  946. }
  947. }
  948. // Optional item
  949. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  950. {
  951. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  952. }
  953. else
  954. {
  955. sprintf((char*)txProfile.ValidFrom, " ");
  956. }
  957. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  958. {
  959. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  960. }
  961. else
  962. {
  963. sprintf((char*)txProfile.ValidTo, " ");
  964. }
  965. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  966. {
  967. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  968. }
  969. else
  970. {
  971. sprintf((char*)txProfile.RecurrencyKind, " ");
  972. }
  973. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  974. {
  975. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  976. }
  977. else
  978. {
  979. txProfile.TransactionId = -1;
  980. }
  981. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  982. {
  983. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  984. }
  985. else
  986. {
  987. txProfile.ChargingSchedule.Duration = 86400;
  988. }
  989. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  990. {
  991. 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")));
  992. }
  993. else
  994. {
  995. 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));
  996. }
  997. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  998. {
  999. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1000. }
  1001. else
  1002. {
  1003. txProfile.ChargingSchedule.MinChargingRate = -1;
  1004. }
  1005. }
  1006. }
  1007. }
  1008. else
  1009. {
  1010. if(txProfile.ChargingProfileId == -1)
  1011. DEBUG_INFO("TxProfile found.\n");
  1012. else
  1013. DEBUG_INFO("TxProfile updated.\n");
  1014. // Required item
  1015. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1016. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1017. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1018. if(isUnitA)
  1019. {
  1020. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1021. 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++)
  1022. {
  1023. 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"));
  1024. 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?
  1025. 3:
  1026. 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")));
  1027. 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")));
  1028. }
  1029. }
  1030. else
  1031. {
  1032. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1033. 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++)
  1034. {
  1035. 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"));
  1036. 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?
  1037. 3:
  1038. 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")));
  1039. 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));
  1040. }
  1041. }
  1042. // Optional item
  1043. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1044. {
  1045. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1046. }
  1047. else
  1048. {
  1049. sprintf((char*)txProfile.ValidFrom, " ");
  1050. }
  1051. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1052. {
  1053. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1054. }
  1055. else
  1056. {
  1057. sprintf((char*)txProfile.ValidTo, " ");
  1058. }
  1059. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1060. {
  1061. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1062. }
  1063. else
  1064. {
  1065. sprintf((char*)txProfile.RecurrencyKind, " ");
  1066. }
  1067. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1068. {
  1069. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1070. }
  1071. else
  1072. {
  1073. txProfile.TransactionId = -1;
  1074. }
  1075. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1076. {
  1077. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1078. }
  1079. else
  1080. {
  1081. txProfile.ChargingSchedule.Duration = 86400;
  1082. }
  1083. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1084. {
  1085. 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")));
  1086. }
  1087. else
  1088. {
  1089. 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));
  1090. }
  1091. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1092. {
  1093. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1094. }
  1095. else
  1096. {
  1097. txProfile.ChargingSchedule.MinChargingRate = -1;
  1098. }
  1099. }
  1100. }
  1101. }
  1102. json_object_put(obj);
  1103. }
  1104. fclose(fp);
  1105. /*
  1106. if(txProfile.ChargingProfileId != -1)
  1107. {
  1108. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1109. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1110. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1111. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1112. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1113. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1114. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1115. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1116. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1117. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1118. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1119. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1120. {
  1121. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1122. {
  1123. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1124. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1125. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1126. }
  1127. }
  1128. }
  1129. else
  1130. DEBUG_INFO("TxProfile not found.\n");*/
  1131. }
  1132. // Search default tx profile
  1133. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1134. if((access(profileFileName, F_OK))==-1)
  1135. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1136. if((access(profileFileName, F_OK))!=-1)
  1137. {
  1138. fp = fopen(profileFileName, "r");
  1139. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1140. {
  1141. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1142. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1143. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1144. }
  1145. defaultTxProfile.ChargingProfileId = -1;
  1146. defaultTxProfile.StackLevel = -1;
  1147. while(getline(&line, &len, fp) != -1)
  1148. {
  1149. json_object *obj = NULL;
  1150. obj = json_tokener_parse(line);
  1151. if(is_error(obj))
  1152. {
  1153. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1154. }
  1155. else
  1156. {
  1157. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1158. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1159. )
  1160. {
  1161. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1162. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1163. )
  1164. {
  1165. struct tm tmFrom, tmTo;
  1166. struct timeb tbFrom, tbTo;
  1167. 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) &&
  1168. (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))
  1169. {
  1170. tmFrom.tm_year -= 1900;
  1171. tmFrom.tm_mon -= 1;
  1172. tbFrom.time = mktime(&tmFrom);
  1173. tmTo.tm_year -= 1900;
  1174. tmTo.tm_mon -= 1;
  1175. tbTo.time = mktime(&tmTo);
  1176. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1177. {
  1178. if(defaultTxProfile.ChargingProfileId == -1)
  1179. DEBUG_INFO("TxDefaultProfile found.\n");
  1180. else
  1181. DEBUG_INFO("TxDefaultProfile updated.\n");
  1182. // Required item
  1183. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1184. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1185. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1186. if(isUnitA)
  1187. {
  1188. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1189. 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++)
  1190. {
  1191. 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"));
  1192. 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?
  1193. 3:
  1194. 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")));
  1195. 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")));
  1196. }
  1197. }
  1198. else
  1199. {
  1200. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1201. 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++)
  1202. {
  1203. 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"));
  1204. 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?
  1205. 3:
  1206. 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")));
  1207. 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));
  1208. }
  1209. }
  1210. // Optional item
  1211. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1212. {
  1213. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1214. }
  1215. else
  1216. {
  1217. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1218. }
  1219. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1220. {
  1221. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1222. }
  1223. else
  1224. {
  1225. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1226. }
  1227. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1228. {
  1229. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1230. }
  1231. else
  1232. {
  1233. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1234. }
  1235. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1236. {
  1237. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1238. }
  1239. else
  1240. {
  1241. defaultTxProfile.TransactionId = -1;
  1242. }
  1243. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1244. {
  1245. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1246. }
  1247. else
  1248. {
  1249. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1250. }
  1251. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1252. {
  1253. 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")));
  1254. }
  1255. else
  1256. {
  1257. 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));
  1258. }
  1259. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1260. {
  1261. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1262. }
  1263. else
  1264. {
  1265. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1266. }
  1267. }
  1268. }
  1269. }
  1270. else
  1271. {
  1272. if(defaultTxProfile.ChargingProfileId == -1)
  1273. DEBUG_INFO("TxDefaultProfile found.\n");
  1274. else
  1275. DEBUG_INFO("TxDefaultProfile updated.\n");
  1276. // Required item
  1277. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1278. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1279. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1280. if(isUnitA)
  1281. {
  1282. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1283. 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++)
  1284. {
  1285. 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"));
  1286. 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?
  1287. 3:
  1288. 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")));
  1289. 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")));
  1290. }
  1291. }
  1292. else
  1293. {
  1294. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1295. 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++)
  1296. {
  1297. 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"));
  1298. 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?
  1299. 3:
  1300. 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")));
  1301. 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));
  1302. }
  1303. }
  1304. // Optional item
  1305. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1306. {
  1307. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1308. }
  1309. else
  1310. {
  1311. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1312. }
  1313. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1314. {
  1315. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1316. }
  1317. else
  1318. {
  1319. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1320. }
  1321. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1322. {
  1323. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1324. }
  1325. else
  1326. {
  1327. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1328. }
  1329. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1330. {
  1331. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1332. }
  1333. else
  1334. {
  1335. defaultTxProfile.TransactionId = -1;
  1336. }
  1337. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1338. {
  1339. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1340. }
  1341. else
  1342. {
  1343. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1344. }
  1345. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1346. {
  1347. 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")));
  1348. }
  1349. else
  1350. {
  1351. 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));
  1352. }
  1353. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1354. {
  1355. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1356. }
  1357. else
  1358. {
  1359. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1360. }
  1361. }
  1362. }
  1363. }
  1364. json_object_put(obj);
  1365. }
  1366. fclose(fp);
  1367. /*
  1368. if(defaultTxProfile.ChargingProfileId != -1)
  1369. {
  1370. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1371. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1372. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1373. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1374. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1375. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1376. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1377. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  1378. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1379. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1380. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1381. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1382. {
  1383. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1384. {
  1385. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1386. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1387. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1388. }
  1389. }
  1390. }
  1391. else
  1392. DEBUG_INFO("TxDefaultProfile not found.\n");
  1393. DEBUG_INFO("------------------------------------\n");*/
  1394. }
  1395. // Search max profile
  1396. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1397. if((access(profileFileName, F_OK))!=-1)
  1398. {
  1399. fp = fopen(profileFileName, "r");
  1400. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1401. {
  1402. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1403. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1404. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1405. }
  1406. maxProfile.ChargingProfileId = -1;
  1407. maxProfile.StackLevel = -1;
  1408. while(getline(&line, &len, fp) != -1)
  1409. {
  1410. json_object *obj = NULL;
  1411. obj = json_tokener_parse(line);
  1412. if(is_error(obj))
  1413. {
  1414. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1415. }
  1416. else
  1417. {
  1418. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  1419. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1420. )
  1421. {
  1422. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1423. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1424. )
  1425. {
  1426. struct tm tmFrom, tmTo;
  1427. struct timeb tbFrom, tbTo;
  1428. 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) &&
  1429. (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))
  1430. {
  1431. tmFrom.tm_year -= 1900;
  1432. tmFrom.tm_mon -= 1;
  1433. tbFrom.time = mktime(&tmFrom);
  1434. tmTo.tm_year -= 1900;
  1435. tmTo.tm_mon -= 1;
  1436. tbTo.time = mktime(&tmTo);
  1437. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1438. {
  1439. if(maxProfile.ChargingProfileId == -1)
  1440. DEBUG_INFO("MaxProfile found.\n");
  1441. else
  1442. DEBUG_INFO("MaxProfile updated.\n");
  1443. // Required item
  1444. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1445. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1446. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1447. if(isUnitA)
  1448. {
  1449. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1450. 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++)
  1451. {
  1452. 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"));
  1453. 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?
  1454. 3:
  1455. 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")));
  1456. 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")));
  1457. }
  1458. }
  1459. else
  1460. {
  1461. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1462. 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++)
  1463. {
  1464. 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"));
  1465. 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?
  1466. 3:
  1467. 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")));
  1468. 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));
  1469. }
  1470. }
  1471. // Optional item
  1472. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1473. {
  1474. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1475. }
  1476. else
  1477. {
  1478. sprintf((char*)maxProfile.ValidFrom, " ");
  1479. }
  1480. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1481. {
  1482. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1483. }
  1484. else
  1485. {
  1486. sprintf((char*)maxProfile.ValidTo, " ");
  1487. }
  1488. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1489. {
  1490. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1491. }
  1492. else
  1493. {
  1494. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1495. }
  1496. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1497. {
  1498. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1499. }
  1500. else
  1501. {
  1502. maxProfile.TransactionId = -1;
  1503. }
  1504. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1505. {
  1506. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1507. }
  1508. else
  1509. {
  1510. maxProfile.ChargingSchedule.Duration = 86400;
  1511. }
  1512. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1513. {
  1514. 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")));
  1515. }
  1516. else
  1517. {
  1518. 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));
  1519. }
  1520. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1521. {
  1522. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1523. }
  1524. else
  1525. {
  1526. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1527. }
  1528. }
  1529. }
  1530. }
  1531. else
  1532. {
  1533. if(maxProfile.ChargingProfileId == -1)
  1534. DEBUG_INFO("MaxProfile found.\n");
  1535. else
  1536. DEBUG_INFO("MaxProfile updated.\n");
  1537. // Required item
  1538. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1539. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1540. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1541. if(isUnitA)
  1542. {
  1543. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1544. 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++)
  1545. {
  1546. 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"));
  1547. 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?
  1548. 3:
  1549. 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")));
  1550. 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")));
  1551. }
  1552. }
  1553. else
  1554. {
  1555. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1556. 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++)
  1557. {
  1558. 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"));
  1559. 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?
  1560. 3:
  1561. 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")));
  1562. 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));
  1563. }
  1564. }
  1565. // Optional item
  1566. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1567. {
  1568. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1569. }
  1570. else
  1571. {
  1572. sprintf((char*)maxProfile.ValidFrom, " ");
  1573. }
  1574. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1575. {
  1576. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1577. }
  1578. else
  1579. {
  1580. sprintf((char*)maxProfile.ValidTo, " ");
  1581. }
  1582. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1583. {
  1584. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1585. }
  1586. else
  1587. {
  1588. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1589. }
  1590. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1591. {
  1592. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1593. }
  1594. else
  1595. {
  1596. maxProfile.TransactionId = -1;
  1597. }
  1598. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1599. {
  1600. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1601. }
  1602. else
  1603. {
  1604. maxProfile.ChargingSchedule.Duration = 86400;
  1605. }
  1606. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1607. {
  1608. 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")));
  1609. }
  1610. else
  1611. {
  1612. 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));
  1613. }
  1614. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1615. {
  1616. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1617. }
  1618. else
  1619. {
  1620. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1621. }
  1622. }
  1623. }
  1624. }
  1625. json_object_put(obj);
  1626. }
  1627. fclose(fp);
  1628. /*
  1629. if(maxProfile.ChargingProfileId !=-1)
  1630. {
  1631. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1632. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1633. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1634. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1635. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1636. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1637. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1638. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1639. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1640. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1641. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1642. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1643. {
  1644. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1645. {
  1646. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1647. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1648. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1649. }
  1650. }
  1651. }
  1652. else
  1653. DEBUG_INFO("MaxProfile not found.\n");
  1654. DEBUG_INFO("------------------------------------\n");*/
  1655. }
  1656. /*
  1657. * Align found profile start schedule & periods
  1658. */
  1659. //DEBUG_INFO("====================================\n");
  1660. /*
  1661. // For local test usage, force modify found profile start schedule info
  1662. 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);
  1663. 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);
  1664. 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);
  1665. */
  1666. if(txProfile.ChargingProfileId != -1)
  1667. {
  1668. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  1669. {
  1670. if(txProfile.ChargingSchedule.Duration != -1)
  1671. {
  1672. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1673. 0:
  1674. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1675. }
  1676. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1677. {
  1678. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1679. {
  1680. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1681. 0:
  1682. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1683. if(idxPeriod > 0)
  1684. {
  1685. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1686. {
  1687. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1688. }
  1689. }
  1690. }
  1691. }
  1692. }
  1693. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  1694. {
  1695. if(txProfile.ChargingSchedule.Duration != -1)
  1696. {
  1697. 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?
  1698. 0:
  1699. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1700. }
  1701. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1702. {
  1703. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1704. {
  1705. 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?
  1706. 0:
  1707. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1708. if(idxPeriod > 0)
  1709. {
  1710. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1711. {
  1712. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1713. }
  1714. }
  1715. }
  1716. }
  1717. }
  1718. else
  1719. {
  1720. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  1721. {
  1722. if(txProfile.ChargingSchedule.Duration != -1)
  1723. {
  1724. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1725. 0:
  1726. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1727. }
  1728. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1729. {
  1730. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1731. {
  1732. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1733. 0:
  1734. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1735. if(idxPeriod > 0)
  1736. {
  1737. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1738. {
  1739. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1740. }
  1741. }
  1742. }
  1743. }
  1744. }
  1745. else
  1746. {
  1747. if(txProfile.ChargingSchedule.Duration != -1)
  1748. {
  1749. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1750. 0:
  1751. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1752. }
  1753. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1754. {
  1755. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1756. {
  1757. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1758. 0:
  1759. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1760. if(idxPeriod > 0)
  1761. {
  1762. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1763. {
  1764. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1765. }
  1766. }
  1767. }
  1768. }
  1769. }
  1770. }
  1771. /*
  1772. DEBUG_INFO("txProfile after align.\n");
  1773. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1774. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1775. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1776. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1777. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1778. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1779. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1780. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1781. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1782. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1783. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1784. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1785. {
  1786. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1787. {
  1788. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1789. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1790. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1791. }
  1792. }*/
  1793. }
  1794. if(defaultTxProfile.ChargingProfileId != -1)
  1795. {
  1796. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  1797. {
  1798. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1799. {
  1800. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1801. 0:
  1802. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1803. }
  1804. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1805. {
  1806. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1807. {
  1808. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1809. 0:
  1810. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1811. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1812. {
  1813. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1814. }
  1815. if(idxPeriod > 0)
  1816. {
  1817. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1818. {
  1819. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1820. }
  1821. }
  1822. }
  1823. }
  1824. }
  1825. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  1826. {
  1827. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1828. {
  1829. 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?
  1830. 0:
  1831. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1832. }
  1833. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1834. {
  1835. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1836. {
  1837. 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?
  1838. 0:
  1839. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1840. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1841. {
  1842. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1843. }
  1844. if(idxPeriod > 0)
  1845. {
  1846. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1847. {
  1848. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1849. }
  1850. }
  1851. }
  1852. }
  1853. }
  1854. else
  1855. {
  1856. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  1857. {
  1858. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1859. {
  1860. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1861. 0:
  1862. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1863. }
  1864. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1865. {
  1866. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1867. {
  1868. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1869. 0:
  1870. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1871. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1872. {
  1873. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1874. }
  1875. if(idxPeriod > 0)
  1876. {
  1877. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1878. {
  1879. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1880. }
  1881. }
  1882. }
  1883. }
  1884. }
  1885. else
  1886. {
  1887. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1888. {
  1889. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1890. 0:
  1891. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1892. }
  1893. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1894. {
  1895. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1896. {
  1897. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1898. 0:
  1899. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1900. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1901. {
  1902. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1903. }
  1904. if(idxPeriod > 0)
  1905. {
  1906. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1907. {
  1908. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1909. }
  1910. }
  1911. }
  1912. }
  1913. }
  1914. }
  1915. /*
  1916. DEBUG_INFO("defaultTxProfile after align.\n");
  1917. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1918. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1919. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1920. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1921. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1922. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1923. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1924. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1925. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1926. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1927. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1928. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1929. {
  1930. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1931. {
  1932. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1933. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1934. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1935. }
  1936. }
  1937. DEBUG_INFO("------------------------------------\n");*/
  1938. }
  1939. if(maxProfile.ChargingProfileId != -1)
  1940. {
  1941. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1942. {
  1943. if(maxProfile.ChargingSchedule.Duration != -1)
  1944. {
  1945. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1946. 0:
  1947. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1948. }
  1949. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1950. {
  1951. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1952. {
  1953. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1954. 0:
  1955. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1956. if(idxPeriod > 0)
  1957. {
  1958. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1959. {
  1960. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1961. }
  1962. }
  1963. }
  1964. }
  1965. }
  1966. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1967. {
  1968. if(maxProfile.ChargingSchedule.Duration != -1)
  1969. {
  1970. 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?
  1971. 0:
  1972. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1973. }
  1974. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1975. {
  1976. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1977. {
  1978. 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?
  1979. 0:
  1980. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1981. if(idxPeriod > 0)
  1982. {
  1983. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1984. {
  1985. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1986. }
  1987. }
  1988. }
  1989. }
  1990. }
  1991. else
  1992. {
  1993. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1994. {
  1995. if(maxProfile.ChargingSchedule.Duration != -1)
  1996. {
  1997. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1998. 0:
  1999. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2000. }
  2001. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2002. {
  2003. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2004. {
  2005. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2006. 0:
  2007. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2008. if(idxPeriod > 0)
  2009. {
  2010. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2011. {
  2012. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2013. }
  2014. }
  2015. }
  2016. }
  2017. }
  2018. else
  2019. {
  2020. if(maxProfile.ChargingSchedule.Duration != -1)
  2021. {
  2022. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2023. 0:
  2024. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2025. }
  2026. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2027. {
  2028. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2029. {
  2030. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2031. 0:
  2032. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2033. if(idxPeriod > 0)
  2034. {
  2035. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2036. {
  2037. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2038. }
  2039. }
  2040. }
  2041. }
  2042. }
  2043. }
  2044. /*
  2045. DEBUG_INFO("MaxProfile after align.\n");
  2046. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2047. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2048. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2049. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2050. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2051. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2052. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2053. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2054. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2055. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2056. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2057. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2058. {
  2059. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2060. {
  2061. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2062. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2063. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2064. }
  2065. }
  2066. DEBUG_INFO("------------------------------------\n");*/
  2067. }
  2068. /*
  2069. * Merge to conposite schedule
  2070. */
  2071. //DEBUG_INFO("====================================\n");
  2072. // Find each profile period quantity
  2073. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2074. {
  2075. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2076. limitMax = idx+1;
  2077. }
  2078. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2079. {
  2080. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2081. limitDef = idx+1;
  2082. }
  2083. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2084. {
  2085. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2086. limitTx = idx+1;
  2087. }
  2088. // TxProfile found, composite schedule based on it
  2089. if(txProfile.ChargingProfileId != -1)
  2090. {
  2091. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2092. {
  2093. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  2094. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  2095. (txProfile.ChargingSchedule.Duration > 0))
  2096. {
  2097. if(maxProfile.ChargingProfileId != -1)
  2098. {
  2099. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2100. {
  2101. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2102. {
  2103. if((maxProfile.ChargingSchedule.Duration > 0))
  2104. {
  2105. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2106. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2107. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2108. }
  2109. else
  2110. {
  2111. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2112. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2113. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2114. }
  2115. }
  2116. if(idxMaxPeriod == (limitMax-1))
  2117. {
  2118. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2119. {
  2120. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2121. {
  2122. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2123. compositePeriodIdx++;
  2124. }
  2125. else
  2126. {
  2127. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2128. }
  2129. }
  2130. }
  2131. }
  2132. }
  2133. else
  2134. {
  2135. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2136. {
  2137. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2138. compositePeriodIdx++;
  2139. }
  2140. else
  2141. {
  2142. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2143. }
  2144. }
  2145. }
  2146. if(idxTxPeriod == (limitTx-1))
  2147. {
  2148. if(defaultTxProfile.ChargingProfileId != -1)
  2149. {
  2150. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2151. {
  2152. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  2153. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2154. (defaultTxProfile.ChargingSchedule.Duration>0))
  2155. {
  2156. if(maxProfile.ChargingProfileId != -1)
  2157. {
  2158. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2159. {
  2160. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2161. {
  2162. if((maxProfile.ChargingSchedule.Duration > 0))
  2163. {
  2164. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2165. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2166. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2167. }
  2168. else
  2169. {
  2170. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2171. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2172. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2173. }
  2174. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2175. {
  2176. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2177. {
  2178. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2179. compositePeriodIdx++;
  2180. }
  2181. else
  2182. {
  2183. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2184. }
  2185. }
  2186. break;
  2187. }
  2188. }
  2189. }
  2190. else
  2191. {
  2192. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2193. {
  2194. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2195. compositePeriodIdx++;
  2196. }
  2197. else
  2198. {
  2199. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2200. }
  2201. }
  2202. }
  2203. }
  2204. }
  2205. }
  2206. }
  2207. }
  2208. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  2209. else if(defaultTxProfile.ChargingProfileId != -1)
  2210. {
  2211. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2212. {
  2213. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  2214. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2215. (defaultTxProfile.ChargingSchedule.Duration > 0))
  2216. {
  2217. if(maxProfile.ChargingProfileId != -1)
  2218. {
  2219. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2220. {
  2221. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2222. {
  2223. if((maxProfile.ChargingSchedule.Duration > 0))
  2224. {
  2225. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2226. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2227. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  2228. }
  2229. else
  2230. {
  2231. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2232. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2233. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2234. }
  2235. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2236. {
  2237. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2238. {
  2239. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2240. compositePeriodIdx++;
  2241. }
  2242. else
  2243. {
  2244. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2245. }
  2246. }
  2247. break;
  2248. }
  2249. }
  2250. }
  2251. else
  2252. {
  2253. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2254. {
  2255. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2256. compositePeriodIdx++;
  2257. }
  2258. else
  2259. {
  2260. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2261. }
  2262. }
  2263. }
  2264. }
  2265. }
  2266. // Fill other period by MaxProfile
  2267. if(maxProfile.ChargingProfileId != -1)
  2268. {
  2269. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2270. {
  2271. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2272. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2273. (maxProfile.ChargingSchedule.Duration > 0))
  2274. {
  2275. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  2276. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2277. {
  2278. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  2279. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  2280. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2281. }
  2282. if((maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2283. {
  2284. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.Duration;
  2285. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  2286. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2287. }
  2288. if(tmpPeriod.Limit != -1)
  2289. {
  2290. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2291. {
  2292. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2293. {
  2294. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2295. compositePeriodIdx++;
  2296. }
  2297. else
  2298. {
  2299. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2300. }
  2301. }
  2302. }
  2303. }
  2304. }
  2305. }
  2306. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  2307. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2308. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  2309. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  2310. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2311. {
  2312. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2313. {
  2314. compositeProfile->ChargingProfileId = 1;
  2315. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2316. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2317. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2318. }
  2319. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2320. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2321. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2322. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2323. }
  2324. if(line)
  2325. free(line);
  2326. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  2327. }
  2328. //==========================================
  2329. // Init all share memory
  2330. //==========================================
  2331. int InitShareMemory()
  2332. {
  2333. int result = PASS;
  2334. int MeterSMId;
  2335. //creat ShmSysConfigAndInfo
  2336. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  2337. {
  2338. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  2339. result = FAIL;
  2340. }
  2341. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2342. {
  2343. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  2344. result = FAIL;
  2345. }
  2346. else
  2347. {}
  2348. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  2349. {
  2350. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  2351. result = FAIL;
  2352. }
  2353. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2354. {
  2355. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  2356. result = FAIL;
  2357. }
  2358. else
  2359. {}
  2360. //creat ShmPsuData
  2361. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  2362. {
  2363. DEBUG_ERROR("shmget ShmPsuData NG\n");
  2364. result = FAIL;
  2365. }
  2366. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2367. {
  2368. DEBUG_ERROR("shmat ShmPsuData NG\n");
  2369. result = FAIL;
  2370. }
  2371. else
  2372. {}
  2373. //creat ShmOCPP16Data
  2374. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  2375. {
  2376. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  2377. result = FAIL;
  2378. }
  2379. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2380. {
  2381. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  2382. result = FAIL;
  2383. }
  2384. else
  2385. {}
  2386. /****************************** For Initial Settings************************************************/
  2387. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  2388. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  2389. // allocate Configuration memory address
  2390. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  2391. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  2392. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  2393. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  2394. //offline MeterValue Interval
  2395. TempMeterValueInterval = 0;
  2396. return result;
  2397. }
  2398. int ProcessShareMemory()
  2399. {
  2400. if(InitShareMemory() == FAIL)
  2401. {
  2402. DEBUG_ERROR("InitShareMemory NG\n");
  2403. if(ShmStatusCodeData!=NULL)
  2404. {
  2405. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  2406. }
  2407. sleep(5);
  2408. return FAIL;
  2409. }
  2410. return PASS;
  2411. }
  2412. void CheckSystemValue(void)
  2413. {
  2414. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  2415. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  2416. char filenmae[100]={0};
  2417. char str[100]={0};
  2418. int tempIndex = 0;
  2419. //===============================
  2420. // send Heartbeat
  2421. //===============================
  2422. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2423. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  2424. {
  2425. clientTime.Heartbeat=time((time_t*)NULL);
  2426. if(server_sign == TRUE)
  2427. {
  2428. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2429. }
  2430. else
  2431. {
  2432. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  2433. }
  2434. }
  2435. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  2436. {
  2437. //parameter for test
  2438. sendHeartbeatRequest(0);
  2439. //==============================================
  2440. // Reset Waiting Time
  2441. //==============================================
  2442. HeartBeatWithNOResponse += 1;
  2443. }
  2444. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  2445. {
  2446. //==========================================
  2447. // csu trigger DataTransferReq
  2448. //==========================================
  2449. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  2450. {
  2451. sendDataTransferRequest(gun_index);
  2452. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  2453. }
  2454. //===============================
  2455. // CSU Trigger Reset Conf
  2456. //===============================
  2457. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  2458. {
  2459. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  2460. }
  2461. //===============================
  2462. // CSU Trigger Authorize Request
  2463. //===============================
  2464. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  2465. {
  2466. sendAuthorizeRequest(0);
  2467. authorizeRetryTimes = authorizeRetryTimes + 1;
  2468. if(authorizeRetryTimes < 3)
  2469. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2470. }
  2471. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  2472. {
  2473. authorizeRetryTimes = 0;
  2474. SetOcppConnStatus(FALSE);
  2475. server_sign = FALSE;
  2476. }
  2477. 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))
  2478. {
  2479. sendAuthorizeRequest(0);
  2480. }
  2481. //==============================================
  2482. // CSU Trigger Smart Charging Profilw
  2483. //==============================================
  2484. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  2485. {
  2486. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  2487. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  2488. }
  2489. //==============================================
  2490. // Charger start transaction
  2491. //==============================================
  2492. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2493. {
  2494. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  2495. sendStartTransactionRequest(gun_index);
  2496. clientTime.StartTransaction = time((time_t*)NULL);
  2497. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2498. storeTempStopTransaction(gun_index);
  2499. }
  2500. //==============================================
  2501. // Charger stop transaction
  2502. //==============================================
  2503. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2504. {
  2505. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2506. sendStopTransactionRequest(gun_index);
  2507. clientTime.StopTransaction = time((time_t*)NULL);
  2508. }
  2509. //==============================================
  2510. // Charger status report
  2511. //==============================================
  2512. //--- Check Mode Change ---//
  2513. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2514. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2515. {
  2516. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2517. {
  2518. tempIndex = ((gun_index==2) ? 1: 0);
  2519. }
  2520. else
  2521. {
  2522. tempIndex = gun_index;
  2523. }
  2524. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2525. {
  2526. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2527. {
  2528. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  2529. {
  2530. // Sent unplug message for California pricing logic
  2531. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  2532. {
  2533. uint8_t ts[20];
  2534. getNowDatetime(ts);
  2535. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2536. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2537. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2538. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2539. }
  2540. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2541. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2542. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2543. statusModeChage[gun_index] = TRUE;
  2544. }
  2545. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2546. {
  2547. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2548. if((access(filenmae,F_OK))!=-1)
  2549. {
  2550. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2551. sprintf(str,"rm -f %s",filenmae);
  2552. system(str);
  2553. }
  2554. }
  2555. #if 1 // for TempStopTransaction
  2556. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2557. {
  2558. checkTempStopTransaction(gun_index);
  2559. }
  2560. #endif
  2561. }
  2562. }
  2563. }
  2564. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2565. {
  2566. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2567. {
  2568. tempIndex = ((gun_index==2) ? 1: 0);
  2569. }
  2570. else
  2571. {
  2572. tempIndex = gun_index;
  2573. }
  2574. for (int index = 0; index < CCS_QUANTITY; index++)
  2575. {
  2576. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2577. {
  2578. 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]*/ )
  2579. {
  2580. // Sent unplug message for California pricing logic
  2581. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  2582. {
  2583. uint8_t ts[20];
  2584. getNowDatetime(ts);
  2585. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2586. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2587. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2588. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2589. }
  2590. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2591. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2592. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2593. statusModeChage[gun_index] = TRUE;
  2594. }
  2595. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2596. {
  2597. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2598. if((access(filenmae,F_OK))!=-1)
  2599. {
  2600. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2601. sprintf(str,"rm -f %s",filenmae);
  2602. system(str);
  2603. }
  2604. }
  2605. #if 1 // for TempStopTransaction
  2606. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2607. {
  2608. checkTempStopTransaction(gun_index);
  2609. }
  2610. #endif
  2611. }
  2612. }
  2613. }
  2614. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2615. {
  2616. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2617. {
  2618. tempIndex = ((gun_index==2) ? 1: 0);
  2619. }
  2620. else
  2621. {
  2622. tempIndex = gun_index;
  2623. }
  2624. for (int index = 0; index < GB_QUANTITY; index++)
  2625. {
  2626. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2627. {
  2628. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  2629. {
  2630. // Sent unplug message for California pricing logic
  2631. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  2632. {
  2633. uint8_t ts[20];
  2634. getNowDatetime(ts);
  2635. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2636. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2637. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2638. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2639. }
  2640. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2641. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2642. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2643. statusModeChage[gun_index] = TRUE;
  2644. }
  2645. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2646. {
  2647. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2648. if((access(filenmae,F_OK))!=-1)
  2649. {
  2650. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2651. sprintf(str,"rm -f %s",filenmae);
  2652. system(str);
  2653. }
  2654. }
  2655. #if 1 // for TempStopTransaction
  2656. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2657. {
  2658. checkTempStopTransaction(gun_index);
  2659. }
  2660. #endif
  2661. }
  2662. }
  2663. }
  2664. else if(gunType[gun_index] == GUN_TYPE_DO)
  2665. {
  2666. tempIndex = gun_index;
  2667. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2668. {
  2669. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2670. {
  2671. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  2672. {
  2673. // Sent unplug message for California pricing logic
  2674. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  2675. {
  2676. uint8_t ts[20];
  2677. getNowDatetime(ts);
  2678. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2679. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2680. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2681. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2682. }
  2683. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  2684. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  2685. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2686. statusModeChage[gun_index] = TRUE;
  2687. }
  2688. 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
  2689. {
  2690. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2691. if((access(filenmae,F_OK))!=-1)
  2692. {
  2693. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2694. sprintf(str,"rm -f %s",filenmae);
  2695. system(str);
  2696. }
  2697. }
  2698. #if 1 // for TempStopTransaction
  2699. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2700. {
  2701. checkTempStopTransaction(gun_index);
  2702. }
  2703. #endif
  2704. }
  2705. }
  2706. }
  2707. else
  2708. {
  2709. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2710. {
  2711. tempIndex = 2;
  2712. }
  2713. else
  2714. {
  2715. tempIndex = gun_index;
  2716. }
  2717. for (int index = 0; index < AC_QUANTITY; index++)
  2718. {
  2719. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2720. {
  2721. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  2722. {
  2723. // Sent unplug message for California pricing logic
  2724. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)
  2725. {
  2726. uint8_t ts[20];
  2727. getNowDatetime(ts);
  2728. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2729. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2730. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2731. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2732. }
  2733. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2734. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2735. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2736. statusModeChage[gun_index] = TRUE;
  2737. }
  2738. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2739. {
  2740. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2741. if((access(filenmae,F_OK))!=-1)
  2742. {
  2743. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2744. sprintf(str,"rm -f %s",filenmae);
  2745. system(str);
  2746. }
  2747. }
  2748. #if 1 // for TempStopTransaction
  2749. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2750. {
  2751. checkTempStopTransaction(gun_index);
  2752. }
  2753. #endif
  2754. }
  2755. }// END
  2756. }
  2757. if(isWebsocketSendable && (server_sign == TRUE) &&
  2758. (
  2759. (statusModeChage[gun_index] == TRUE) ||
  2760. //((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index))) ||
  2761. ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 10))
  2762. )
  2763. )
  2764. {
  2765. if(SystemInitial > 0)
  2766. SystemInitial -= 1;
  2767. sendStatusNotificationRequest(gun_index);
  2768. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2769. statusModeChage[gun_index] = FALSE;
  2770. }
  2771. //==============================================
  2772. // Meter report
  2773. //==============================================
  2774. // Trigger MeterValue
  2775. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  2776. {
  2777. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  2778. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  2779. }
  2780. // ClockAlign MeterValue
  2781. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  2782. {
  2783. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2784. {
  2785. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2786. {
  2787. tempIndex = ((gun_index==2) ? 1: 0);
  2788. }
  2789. else
  2790. {
  2791. tempIndex = gun_index;
  2792. }
  2793. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2794. {
  2795. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2796. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2797. {
  2798. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2799. {
  2800. reqClockAlignMeter[gun_index] = 1;
  2801. }
  2802. }
  2803. }// End for CHAdeMO
  2804. }
  2805. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2806. {
  2807. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2808. {
  2809. tempIndex = ((gun_index==2) ? 1: 0);
  2810. }
  2811. else
  2812. {
  2813. tempIndex = gun_index;
  2814. }
  2815. for (int index = 0; index < CCS_QUANTITY; index++)
  2816. {
  2817. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2818. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2819. {
  2820. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2821. {
  2822. reqClockAlignMeter[gun_index] = 1;
  2823. }
  2824. }
  2825. } // End for CCS
  2826. }
  2827. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2828. {
  2829. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2830. {
  2831. tempIndex = ((gun_index==2) ? 1: 0);
  2832. }
  2833. else
  2834. {
  2835. tempIndex = gun_index;
  2836. }
  2837. for (int index = 0; index < GB_QUANTITY; index++)
  2838. {
  2839. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2840. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2841. {
  2842. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2843. {
  2844. reqClockAlignMeter[gun_index] = 1;
  2845. }
  2846. }
  2847. }// End for GB
  2848. }
  2849. else if(gunType[gun_index] == GUN_TYPE_DO)
  2850. {
  2851. tempIndex = gun_index;
  2852. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2853. {
  2854. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2855. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2856. {
  2857. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_CHARGING)
  2858. {
  2859. reqClockAlignMeter[gun_index] = 1;
  2860. }
  2861. }
  2862. }
  2863. }
  2864. else
  2865. {
  2866. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2867. {
  2868. tempIndex = 2;
  2869. }
  2870. else
  2871. {
  2872. tempIndex = gun_index;
  2873. }
  2874. for (int index = 0; index < AC_QUANTITY; index++)
  2875. {
  2876. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2877. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2878. {
  2879. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2880. {
  2881. reqClockAlignMeter[gun_index] = 1;
  2882. }
  2883. }
  2884. }//End for AC
  2885. }
  2886. if(reqClockAlignMeter[gun_index] == 1)
  2887. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  2888. }
  2889. // Sample period MeterValue
  2890. if((((time((time_t*)NULL) - clientTime.MeterValues[gun_index]) > (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1))))
  2891. {
  2892. //check Transaction active
  2893. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2894. {
  2895. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2896. {
  2897. tempIndex = ((gun_index==2) ? 1: 0);
  2898. }
  2899. else
  2900. {
  2901. tempIndex = gun_index;
  2902. }
  2903. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2904. {
  2905. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2906. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2907. {
  2908. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2909. {
  2910. reqSampleMeter[gun_index] = 1;
  2911. }
  2912. }
  2913. }// End for CHAdeMO
  2914. }
  2915. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2916. {
  2917. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2918. {
  2919. tempIndex = ((gun_index==2) ? 1: 0);
  2920. }
  2921. else
  2922. {
  2923. tempIndex = gun_index;
  2924. }
  2925. for (int index = 0; index < CCS_QUANTITY; index++)
  2926. {
  2927. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2928. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2929. {
  2930. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2931. {
  2932. reqSampleMeter[gun_index] = 1;
  2933. }
  2934. }
  2935. } // End for CCS
  2936. }
  2937. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2938. {
  2939. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2940. {
  2941. tempIndex = ((gun_index==2) ? 1: 0);
  2942. }
  2943. else
  2944. {
  2945. tempIndex = gun_index;
  2946. }
  2947. for (int index = 0; index < GB_QUANTITY; index++)
  2948. {
  2949. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2950. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2951. {
  2952. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2953. {
  2954. reqSampleMeter[gun_index] = 1;
  2955. }
  2956. }
  2957. }// End for GB
  2958. }
  2959. else if(gunType[gun_index] == GUN_TYPE_DO)
  2960. {
  2961. tempIndex = gun_index;
  2962. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2963. {
  2964. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2965. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2966. {
  2967. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  2968. {
  2969. reqSampleMeter[gun_index] = 1;
  2970. }
  2971. }
  2972. }
  2973. }
  2974. else
  2975. {
  2976. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2977. {
  2978. tempIndex = 2;
  2979. }
  2980. else
  2981. {
  2982. tempIndex = gun_index;
  2983. }
  2984. for (int index = 0; index < AC_QUANTITY; index++)
  2985. {
  2986. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2987. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2988. {
  2989. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  2990. {
  2991. reqSampleMeter[gun_index] = 1;
  2992. }
  2993. }
  2994. }//End for AC
  2995. }
  2996. if(reqSampleMeter[gun_index] == 1)
  2997. {
  2998. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  2999. storeTempStopTransaction(gun_index);
  3000. }
  3001. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3002. }
  3003. //==============================================
  3004. // Check Connector reserved
  3005. //==============================================
  3006. //===============================
  3007. // Check if Reserve is expired
  3008. //===============================
  3009. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  3010. {
  3011. double diff_t;
  3012. struct tm tp;
  3013. // current time
  3014. time_t t = time(NULL);
  3015. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  3016. tp.tm_isdst = -1;
  3017. time_t utc = mktime(&tp);
  3018. diff_t = difftime(utc, t);
  3019. if(diff_t <= 0)
  3020. {
  3021. DEBUG_INFO("reserve expired.\n");
  3022. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  3023. }
  3024. }//END OF Check if Reserve is expired
  3025. //==========================================
  3026. // csu trigger FirmwareStatusNotificationReq
  3027. //==========================================
  3028. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  3029. {
  3030. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  3031. }
  3032. //==========================================
  3033. // csu trigger CancelReservationConf
  3034. //==========================================
  3035. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  3036. {
  3037. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  3038. }
  3039. //==========================================
  3040. // csu trigger ChangeAvailabilityConf
  3041. //==========================================
  3042. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  3043. {
  3044. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  3045. }
  3046. //==========================================
  3047. // csu trigger UnlockConnectorConf
  3048. //==========================================
  3049. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  3050. {
  3051. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  3052. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  3053. }
  3054. //==========================================
  3055. // csu trigger ReserveNowConf
  3056. //==========================================
  3057. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  3058. {
  3059. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  3060. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  3061. }
  3062. }
  3063. }
  3064. //==========================================
  3065. // send request routine
  3066. //==========================================
  3067. int sendAuthorizeRequest(int gun_index)
  3068. {
  3069. mtrace();
  3070. int result = FAIL;
  3071. char message[100]={0};
  3072. char guid[37];
  3073. char tempdata[65]={0};
  3074. DEBUG_INFO("sendAuthorizeRequest...\n");
  3075. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  3076. //Local Authorize
  3077. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  3078. {
  3079. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  3080. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  3081. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  3082. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  3083. result = PASS;
  3084. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3085. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3086. authorizeRetryTimes = 0;
  3087. return result;
  3088. }
  3089. 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))||
  3090. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  3091. {
  3092. // Query from cache
  3093. DEBUG_INFO("Authorize from cache.\n");
  3094. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3095. // Query from list
  3096. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3097. {
  3098. DEBUG_INFO("Authorize from list.\n");
  3099. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3100. }
  3101. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3102. {
  3103. if(strcmp(idTagQuery.idTagstr,"") == 0)
  3104. {
  3105. DEBUG_INFO("off-line Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  3106. }
  3107. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  3108. {
  3109. DEBUG_INFO("off-line Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  3110. }
  3111. DEBUG_INFO("off-line Local Authorization Fail !!!!\n");
  3112. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  3113. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3114. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  3115. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  3116. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3117. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3118. authorizeRetryTimes = 0;
  3119. return result;
  3120. }
  3121. else
  3122. {
  3123. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  3124. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3125. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3126. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  3127. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  3128. else
  3129. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  3130. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  3131. result = PASS;
  3132. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3133. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3134. authorizeRetryTimes = 0;
  3135. return result;
  3136. }
  3137. }
  3138. //initialize struct Authorize
  3139. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  3140. //get data from shared memory
  3141. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3142. random_uuid(guid);
  3143. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  3144. LWS_Send(message);
  3145. sprintf(tempdata, "Authorize,%d", gun_index);
  3146. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3147. {
  3148. result = PASS;
  3149. DEBUG_INFO("Authorize mapItem pass\n");
  3150. }
  3151. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3152. return result;
  3153. }
  3154. int sendBootNotificationRequest(void)
  3155. {
  3156. mtrace();
  3157. int result = FAIL;
  3158. char message[500]={0}, payload[700]={0};
  3159. char guid[37]={0};
  3160. char tempdata[65]={0};
  3161. // Fill BootNotification fields
  3162. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  3163. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  3164. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  3165. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3166. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  3167. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  3168. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  3169. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  3170. ShmOCPP16Data->ChargeBoxId
  3171. ,ShmSysConfigAndInfo->SysConfig.ModelName
  3172. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  3173. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  3174. ,ShmOCPP16Data->BootNotification.CpFwVersion
  3175. ,ShmOCPP16Data->BootNotification.CpIccid
  3176. ,ShmOCPP16Data->BootNotification.CpImsi);
  3177. random_uuid(guid);
  3178. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  3179. LWS_Send(message);
  3180. sprintf(tempdata, "BootNotification,0");
  3181. 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*/)
  3182. {
  3183. result = PASS;
  3184. }
  3185. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3186. strcpy(queuedata,message);
  3187. return result;
  3188. }
  3189. int sendDataTransferRequest(int gun_index)
  3190. {
  3191. mtrace();
  3192. char message[1000]={0};
  3193. char guid[37]={0};
  3194. char tempdata[65]={0};
  3195. int result = FAIL;
  3196. random_uuid(guid);
  3197. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  3198. MESSAGE_TYPE_CALL,
  3199. guid,
  3200. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  3201. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  3202. ShmOCPP16Data->DataTransfer[gun_index].Data);
  3203. LWS_Send(message);
  3204. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  3205. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3206. {
  3207. result = PASS;
  3208. DEBUG_INFO("DataTransfer mapItem pass\n");
  3209. }
  3210. return result;
  3211. }
  3212. int sendDiagnosticsStatusNotificationRequest(char *status)
  3213. {
  3214. mtrace();
  3215. int result = FAIL;
  3216. char message[110]={0};
  3217. char guid[37]={0};
  3218. char tempdata[65]={0};
  3219. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  3220. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  3221. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  3222. random_uuid(guid);
  3223. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  3224. LWS_SendNow(message);
  3225. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  3226. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3227. {
  3228. result = PASS;
  3229. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  3230. }
  3231. //#ifdef SystemLogMessage
  3232. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  3233. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3234. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  3235. //#endif
  3236. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  3237. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  3238. //record status
  3239. if(strcmp(status,"Idle")==0)
  3240. {
  3241. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  3242. }
  3243. else if(strcmp(status,"Uploaded")==0)
  3244. {
  3245. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  3246. }
  3247. else if(strcmp(status,"UploadFailed")==0)
  3248. {
  3249. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  3250. }
  3251. else if(strcmp(status,"Uploading")==0)
  3252. {
  3253. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  3254. }
  3255. return result;
  3256. }
  3257. int sendFirmwareStatusNotificationRequest(char *status)
  3258. {
  3259. mtrace();
  3260. int result = FAIL;
  3261. char message[110]={0};
  3262. char guid[37]={0};
  3263. char tempdata[65]={0};
  3264. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  3265. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  3266. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  3267. random_uuid(guid);
  3268. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  3269. LWS_SendNow(message);
  3270. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  3271. 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*/)
  3272. {
  3273. result = PASS;
  3274. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  3275. }
  3276. //#ifdef SystemLogMessage
  3277. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  3278. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3279. //#endif
  3280. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  3281. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  3282. //record status
  3283. if(strcmp(status,"Downloaded")==0)
  3284. {
  3285. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  3286. }
  3287. else if(strcmp(status,"DownloadFailed")==0)
  3288. {
  3289. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  3290. }
  3291. else if(strcmp(status,"Downloading")==0)
  3292. {
  3293. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  3294. }
  3295. else if(strcmp(status,"Idle")==0)
  3296. {
  3297. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  3298. }
  3299. else if(strcmp(status,"InstallationFailed")==0)
  3300. {
  3301. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  3302. }
  3303. else if(strcmp(status,"Installing")==0)
  3304. {
  3305. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  3306. }
  3307. else if(strcmp(status,"Installed")==0)
  3308. {
  3309. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  3310. }
  3311. return result;
  3312. }
  3313. int sendHeartbeatRequest(int gun_index)
  3314. {
  3315. mtrace();
  3316. int result = FAIL;
  3317. char message[80]={0};
  3318. char guid[37]={0};
  3319. char tempdata[65]={0};
  3320. random_uuid(guid);
  3321. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  3322. , MESSAGE_TYPE_CALL
  3323. , guid );
  3324. LWS_Send(message);
  3325. sprintf(tempdata, "Heartbeat,%d", 0);
  3326. 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*/)
  3327. {
  3328. result = PASS;
  3329. }
  3330. return result;
  3331. }
  3332. int sendStartTransactionRequest(int gun_index)
  3333. {
  3334. mtrace();
  3335. int result = FAIL;
  3336. char message[250]={0};
  3337. char guid[37]={0};
  3338. struct timeval tmnow;
  3339. struct tm *tm;
  3340. char buf[28];//, usec_buf[6];
  3341. char tempdata[65]={0};
  3342. int tempIndex = 0;
  3343. DEBUG_INFO("sendStartTransactionRequest...\n");
  3344. gettimeofday(&tmnow, NULL);
  3345. time_t t;
  3346. t = time(NULL);
  3347. /*UTC time and date*/
  3348. tm = gmtime(&t);
  3349. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3350. #if 0 // remove temporally
  3351. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3352. strcat(buf,".");
  3353. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3354. strcat(buf,usec_buf);
  3355. #endif
  3356. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  3357. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  3358. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3359. // clear StartTransaction Response
  3360. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  3361. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  3362. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  3363. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  3364. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3365. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3366. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3367. {
  3368. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3369. {
  3370. tempIndex = ((gun_index==2) ? 1: 0);
  3371. }
  3372. else
  3373. {
  3374. tempIndex = gun_index;
  3375. }
  3376. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3377. {
  3378. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3379. {
  3380. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3381. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  3382. }
  3383. }
  3384. }
  3385. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3386. {
  3387. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3388. {
  3389. tempIndex = ((gun_index==2) ? 1: 0);
  3390. }
  3391. else
  3392. {
  3393. tempIndex = gun_index;
  3394. }
  3395. for (int index = 0; index < CCS_QUANTITY; index++)
  3396. {
  3397. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3398. {
  3399. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3400. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  3401. }
  3402. }
  3403. }
  3404. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3405. {
  3406. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3407. {
  3408. tempIndex = ((gun_index==2) ? 1: 0);
  3409. }
  3410. else
  3411. {
  3412. tempIndex = gun_index;
  3413. }
  3414. for (int index = 0; index < GB_QUANTITY; index++)
  3415. {
  3416. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3417. {
  3418. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3419. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  3420. }
  3421. }
  3422. }
  3423. else if(gunType[gun_index] == GUN_TYPE_DO)
  3424. {
  3425. tempIndex = gun_index;
  3426. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3427. {
  3428. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3429. {
  3430. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3431. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  3432. }
  3433. }
  3434. }
  3435. else
  3436. {
  3437. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3438. {
  3439. tempIndex = 2;
  3440. }
  3441. else
  3442. {
  3443. tempIndex = gun_index;
  3444. }
  3445. for (int index = 0; index < AC_QUANTITY; index++)
  3446. {
  3447. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3448. {
  3449. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3450. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  3451. }
  3452. }
  3453. }
  3454. random_uuid(guid);
  3455. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  3456. {
  3457. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  3458. , gun_index +1
  3459. , MESSAGE_TYPE_CALL
  3460. , guid
  3461. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3462. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3463. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3464. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3465. }
  3466. else
  3467. {
  3468. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  3469. , gun_index +1
  3470. , MESSAGE_TYPE_CALL
  3471. , guid
  3472. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3473. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3474. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3475. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  3476. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3477. }
  3478. #if 1
  3479. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  3480. 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*/)
  3481. {
  3482. result = PASS;
  3483. }
  3484. #endif
  3485. strcpy(queuedata, message);
  3486. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3487. OCPP_insert_transaction_msg(YES, queuedata);
  3488. return result;
  3489. }
  3490. int sendStatusNotificationRequest(int gun_index)
  3491. {
  3492. mtrace();
  3493. int result = FAIL;
  3494. char message[600]={0};
  3495. char guid[37];
  3496. int currentStatus = 0;
  3497. struct timeval tmnow;
  3498. struct tm *tm;
  3499. char buf[28];//, usec_buf[6];
  3500. char tempdata[65]={0};
  3501. int tempIndex = 0;
  3502. DEBUG_INFO("sendStatusNotificationRequest...\n");
  3503. gettimeofday(&tmnow, NULL);
  3504. time_t t;
  3505. t = time(NULL);
  3506. /*UTC time and date*/
  3507. tm = gmtime(&t);
  3508. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3509. #if 0 // remove temporally
  3510. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3511. strcat(buf,".");
  3512. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3513. strcat(buf,usec_buf);
  3514. #endif
  3515. printf("%s",buf);
  3516. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  3517. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  3518. // it's option
  3519. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  3520. /*
  3521. enum _SYSTEM_STATUS
  3522. {
  3523. S_BOOTING = 0,
  3524. S_IDLE, = 1
  3525. S_AUTHORIZING, =2
  3526. S_REASSIGN_CHECK, =3
  3527. S_REASSIGN, =4
  3528. S_PRECHARGE, =5
  3529. S_PREPARING_FOR_EV, =6
  3530. S_PREPARING_FOR_EVSE, =7
  3531. S_CHARGING, =8
  3532. S_TERMINATING, =9
  3533. S_COMPLETE, =10
  3534. S_ALARM, =11
  3535. S_FAULT =12
  3536. }
  3537. */
  3538. //check Transaction active
  3539. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3540. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3541. {
  3542. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3543. {
  3544. tempIndex = ((gun_index==2) ? 1: 0);
  3545. }
  3546. else
  3547. {
  3548. tempIndex = gun_index;
  3549. }
  3550. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3551. {
  3552. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  3553. {
  3554. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  3555. {
  3556. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3557. {
  3558. currentStatus = Preparing; //OCPP Status: Preparing
  3559. }
  3560. else
  3561. {
  3562. currentStatus = Available; //OCPP Status: Available
  3563. }
  3564. }
  3565. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3566. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3567. ) //S_PRECHARGE
  3568. {
  3569. currentStatus = Preparing; //OCPP Status: Preparing
  3570. }
  3571. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3572. {
  3573. currentStatus = Charging; //OCPP Status: Charging
  3574. }
  3575. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3576. {
  3577. currentStatus = Finishing; //OCPP Status: Finishing
  3578. }
  3579. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3580. {
  3581. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3582. }
  3583. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (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
  3584. {
  3585. currentStatus = Unavailable; //OCPP Status: Unavailable
  3586. }
  3587. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3588. {
  3589. currentStatus = Faulted; //OCPP Status: Faulted
  3590. }
  3591. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3592. {
  3593. currentStatus = Reserved; //OCPP Status: Reserved
  3594. }
  3595. } //end of the same index
  3596. }//end of for CHAdeMO_QUANTITY
  3597. }
  3598. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3599. {
  3600. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3601. {
  3602. tempIndex = ((gun_index==2) ? 1: 0);
  3603. }
  3604. else
  3605. {
  3606. tempIndex = gun_index;
  3607. }
  3608. for (int index = 0; index < CCS_QUANTITY; index++)
  3609. {
  3610. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3611. {
  3612. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3613. {
  3614. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3615. {
  3616. currentStatus = Preparing; //OCPP Status: Preparing
  3617. }
  3618. else
  3619. {
  3620. currentStatus = Available; //OCPP Status: Available
  3621. }
  3622. }
  3623. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3624. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3625. ) //S_PRECHARGE
  3626. {
  3627. currentStatus = Preparing; //OCPP Status: Preparing
  3628. }
  3629. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3630. {
  3631. currentStatus = Charging; //OCPP Status: Charging
  3632. }
  3633. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3634. {
  3635. currentStatus = Finishing; //OCPP Status: Finishing
  3636. }
  3637. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3638. {
  3639. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3640. }
  3641. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (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
  3642. {
  3643. currentStatus = Unavailable; //OCPP Status : Unavailable
  3644. }
  3645. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3646. {
  3647. currentStatus = Faulted; //OCPP Status: Faulted
  3648. }
  3649. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3650. {
  3651. currentStatus = Reserved; //OCPP Status: Reserved
  3652. }
  3653. } //end of the same index
  3654. } // end of for CCS_QUANTITY
  3655. }
  3656. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3657. {
  3658. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3659. {
  3660. tempIndex = ((gun_index==2) ? 1: 0);
  3661. }
  3662. else
  3663. {
  3664. tempIndex = gun_index;
  3665. }
  3666. for (int index = 0; index < GB_QUANTITY; index++)
  3667. {
  3668. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3669. {
  3670. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3671. {
  3672. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3673. {
  3674. currentStatus = Preparing; //OCPP Status: Preparing
  3675. }
  3676. else
  3677. {
  3678. currentStatus = Available; //OCPP Status: Available
  3679. }
  3680. }
  3681. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3682. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3683. ) //S_PRECHARGE
  3684. {
  3685. currentStatus = Preparing; //OCPP Status: Preparing
  3686. }
  3687. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3688. {
  3689. currentStatus = Charging; //OCPP Status: Charging
  3690. }
  3691. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3692. {
  3693. currentStatus = Finishing; //OCPP Status: Finishing
  3694. }
  3695. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3696. {
  3697. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3698. }
  3699. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (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
  3700. {
  3701. currentStatus = Unavailable; //OCPP Status: Unavailable
  3702. }
  3703. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3704. {
  3705. currentStatus = Faulted; //OCPP Status: Faulted
  3706. }
  3707. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3708. {
  3709. currentStatus = Reserved; //OCPP Status: Reserved
  3710. }
  3711. } //end of the same index
  3712. } // end of for GB_QUANTITY
  3713. }
  3714. else if(gunType[gun_index] == GUN_TYPE_DO)
  3715. {
  3716. tempIndex = gun_index;
  3717. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3718. {
  3719. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3720. {
  3721. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3722. {
  3723. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3724. {
  3725. currentStatus = Preparing; //OCPP Status: Preparing
  3726. }
  3727. else
  3728. {
  3729. currentStatus = Available; //OCPP Status: Available
  3730. }
  3731. }
  3732. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3733. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3734. ) //S_PRECHARGE
  3735. {
  3736. currentStatus = Preparing; //OCPP Status: Preparing
  3737. }
  3738. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3739. {
  3740. currentStatus = Charging; //OCPP Status: Charging
  3741. }
  3742. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3743. {
  3744. currentStatus = Finishing; //OCPP Status: Finishing
  3745. }
  3746. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3747. {
  3748. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3749. }
  3750. else if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (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
  3751. {
  3752. currentStatus = Unavailable; //OCPP Status: Unavailable
  3753. }
  3754. 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
  3755. {
  3756. currentStatus = Faulted; //OCPP Status: Faulted
  3757. }
  3758. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3759. {
  3760. currentStatus = Reserved; //OCPP Status: Reserved
  3761. }
  3762. } //end of the same index
  3763. }
  3764. }
  3765. else
  3766. {
  3767. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3768. {
  3769. tempIndex = 2;
  3770. }
  3771. else
  3772. {
  3773. tempIndex = gun_index;
  3774. }
  3775. for (int index = 0; index < AC_QUANTITY; index++)
  3776. {
  3777. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3778. {
  3779. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3780. {
  3781. 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))
  3782. {
  3783. currentStatus = Preparing; //OCPP Status: Preparing
  3784. }
  3785. else
  3786. {
  3787. currentStatus = Available; //OCPP Status: Available
  3788. }
  3789. }
  3790. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  3791. {
  3792. currentStatus = Preparing; //OCPP Status: Preparing
  3793. }
  3794. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3795. {
  3796. currentStatus = Charging; //OCPP Status: Charging
  3797. }
  3798. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3799. {
  3800. currentStatus = Finishing; //OCPP Status: Finishing
  3801. }
  3802. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3803. {
  3804. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3805. }
  3806. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (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
  3807. {
  3808. currentStatus = Unavailable; //OCPP Status: Unavailable
  3809. }
  3810. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3811. {
  3812. currentStatus = Faulted; //OCPP Status: Faulted
  3813. }
  3814. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3815. {
  3816. currentStatus = Reserved; //OCPP Status: Reserved
  3817. }
  3818. }//end of the same index
  3819. }//end of for AC_QUANTITY
  3820. }
  3821. //it's option
  3822. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3823. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3824. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3825. random_uuid(guid);
  3826. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3827. , MESSAGE_TYPE_CALL
  3828. , guid
  3829. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3830. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3831. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3832. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3833. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3834. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3835. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3836. if((server_sign == TRUE))
  3837. {
  3838. LWS_Send(message);
  3839. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3840. 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*/)
  3841. {
  3842. //DEBUG_ERROR("statusNotification mapitem pass");
  3843. result = PASS;
  3844. }
  3845. }
  3846. else
  3847. {
  3848. result = PASS;
  3849. }
  3850. return result;
  3851. }
  3852. int sendStopTransactionRequest(int gun_index)
  3853. {
  3854. mtrace();
  3855. int result = FAIL;
  3856. //char message[1500]={0};
  3857. char guid[37]={0};
  3858. char tempdata[65]={0};
  3859. int tempIndex = 0;
  3860. char TempStopTransaction[256];
  3861. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  3862. //int idx_sample=0;
  3863. DEBUG_INFO("sendStopTransactionRequest \n");
  3864. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3865. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  3866. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  3867. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3868. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3869. {
  3870. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3871. {
  3872. tempIndex = ((gun_index==2) ? 1: 0);
  3873. }
  3874. else
  3875. {
  3876. tempIndex = gun_index;
  3877. }
  3878. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3879. {
  3880. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3881. {
  3882. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3883. }
  3884. }// END OF CHAdeMO_QUANTITY
  3885. }
  3886. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3887. {
  3888. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3889. {
  3890. tempIndex = ((gun_index==2) ? 1: 0);
  3891. }
  3892. else
  3893. {
  3894. tempIndex = gun_index;
  3895. }
  3896. for (int index = 0; index < CCS_QUANTITY; index++)
  3897. {
  3898. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3899. {
  3900. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3901. }
  3902. }// END OF CCS_QUANTITY
  3903. }
  3904. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3905. {
  3906. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3907. {
  3908. tempIndex = ((gun_index==2) ? 1: 0);
  3909. }
  3910. else
  3911. {
  3912. tempIndex = gun_index;
  3913. }
  3914. for (int index = 0; index < GB_QUANTITY; index++)
  3915. {
  3916. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3917. {
  3918. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3919. }
  3920. }// END OF GB_QUANTITY
  3921. }
  3922. else if(gunType[gun_index] == GUN_TYPE_DO)
  3923. {
  3924. tempIndex = gun_index;
  3925. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3926. {
  3927. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3928. {
  3929. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3930. }
  3931. }// END OF GB_QUANTITY
  3932. }
  3933. else
  3934. {
  3935. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3936. {
  3937. tempIndex = 2;
  3938. }
  3939. else
  3940. {
  3941. tempIndex = gun_index;
  3942. }
  3943. for (int index = 0; index < AC_QUANTITY; index++)
  3944. {
  3945. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3946. {
  3947. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3948. }
  3949. }// END OF AC_QUANTITY
  3950. }
  3951. //====================================== Stop Transaction Time =====================================================
  3952. struct timeval tmnow;
  3953. struct tm *tm;
  3954. char buf[28];//, usec_buf[6];
  3955. gettimeofday(&tmnow, NULL);
  3956. time_t t;
  3957. t = time(NULL);
  3958. /*UTC time and date*/
  3959. tm = gmtime(&t);
  3960. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3961. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  3962. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  3963. random_uuid(guid);
  3964. /***********************************transactionData******************************************************/
  3965. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  3966. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  3967. //=================================
  3968. // Transaction_Begin
  3969. //=================================
  3970. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  3971. {
  3972. //============================================ Energy.Active.Import.Interval ================================
  3973. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  3974. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  3975. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  3976. 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*/]);
  3977. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3978. 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))
  3979. {
  3980. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  3981. }
  3982. else
  3983. {
  3984. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  3985. }
  3986. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  3987. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3988. }
  3989. //=================================
  3990. // Transaction_End
  3991. //=================================
  3992. // ================================= Current.Import L1 ===============================================
  3993. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  3994. {
  3995. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  3996. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3997. {
  3998. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3999. {
  4000. tempIndex = ((gun_index==2) ? 1: 0);
  4001. }
  4002. else
  4003. {
  4004. tempIndex = gun_index;
  4005. }
  4006. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4007. {
  4008. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4009. {
  4010. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4011. }
  4012. }// End of for CHAdeMO_QUANTITY
  4013. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4014. }
  4015. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4016. {
  4017. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4018. {
  4019. tempIndex = ((gun_index==2) ? 1: 0);
  4020. }
  4021. else
  4022. {
  4023. tempIndex = gun_index;
  4024. }
  4025. for (int index = 0; index < CCS_QUANTITY; index++)
  4026. {
  4027. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4028. {
  4029. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4030. }
  4031. }// End of for CCS_QUANTITY
  4032. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4033. }
  4034. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4035. {
  4036. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4037. {
  4038. tempIndex = ((gun_index==2) ? 1: 0);
  4039. }
  4040. else
  4041. {
  4042. tempIndex = gun_index;
  4043. }
  4044. for (int index = 0; index < GB_QUANTITY; index++)
  4045. {
  4046. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4047. {
  4048. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4049. }
  4050. }// End of for GB_QUANTITY
  4051. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4052. }
  4053. else if(gunType[gun_index] == GUN_TYPE_DO)
  4054. {
  4055. tempIndex = gun_index;
  4056. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4057. {
  4058. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4059. {
  4060. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4061. }
  4062. }
  4063. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4064. }
  4065. else
  4066. {
  4067. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4068. {
  4069. tempIndex = 2;
  4070. }
  4071. else
  4072. {
  4073. tempIndex = gun_index;
  4074. }
  4075. for (int index = 0; index < AC_QUANTITY; index++)
  4076. {
  4077. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4078. {
  4079. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  4080. }
  4081. }// End of for AC_QUANTITY
  4082. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  4083. }
  4084. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4085. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  4086. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  4087. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  4088. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4089. }
  4090. // ================================= Energy.Active.Import.Interval ==============================================
  4091. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4092. {
  4093. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4094. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4095. {
  4096. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4097. {
  4098. tempIndex = ((gun_index==2) ? 1: 0);
  4099. }
  4100. else
  4101. {
  4102. tempIndex = gun_index;
  4103. }
  4104. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4105. {
  4106. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4107. {
  4108. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4109. }
  4110. }// END OF CHAdeMO_QUANTITY
  4111. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4112. }
  4113. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4114. {
  4115. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4116. {
  4117. tempIndex = ((gun_index==2) ? 1: 0);
  4118. }
  4119. else
  4120. {
  4121. tempIndex = gun_index;
  4122. }
  4123. for (int index = 0; index < CCS_QUANTITY; index++)
  4124. {
  4125. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4126. {
  4127. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4128. }
  4129. }// END OF CCS_QUANTITY
  4130. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4131. }
  4132. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4133. {
  4134. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4135. {
  4136. tempIndex = ((gun_index==2) ? 1: 0);
  4137. }
  4138. else
  4139. {
  4140. tempIndex = gun_index;
  4141. }
  4142. for (int index = 0; index < GB_QUANTITY; index++)
  4143. {
  4144. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4145. {
  4146. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4147. }
  4148. }// END OF GB_QUANTITY
  4149. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4150. }
  4151. else if(gunType[gun_index] == GUN_TYPE_DO)
  4152. {
  4153. tempIndex = gun_index;
  4154. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4155. {
  4156. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4157. {
  4158. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4159. }
  4160. }
  4161. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4162. }
  4163. else
  4164. {
  4165. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4166. {
  4167. tempIndex = 2;
  4168. }
  4169. else
  4170. {
  4171. tempIndex = gun_index;
  4172. }
  4173. for (int index = 0; index < AC_QUANTITY; index++)
  4174. {
  4175. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4176. {
  4177. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4178. }
  4179. }// END OF AC_QUANTITY
  4180. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  4181. }
  4182. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4183. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  4184. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  4185. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  4186. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4187. }
  4188. //=================================== Power.Active.Import ==================================================
  4189. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  4190. {
  4191. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4192. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4193. {
  4194. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4195. {
  4196. tempIndex = ((gun_index==2) ? 1: 0);
  4197. }
  4198. else
  4199. {
  4200. tempIndex = gun_index;
  4201. }
  4202. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4203. {
  4204. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4205. {
  4206. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4207. }
  4208. } // End for CHAdeMO_QUANTITY
  4209. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4210. }
  4211. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4212. {
  4213. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4214. {
  4215. tempIndex = ((gun_index==2) ? 1: 0);
  4216. }
  4217. else
  4218. {
  4219. tempIndex = gun_index;
  4220. }
  4221. for (int index = 0; index < CCS_QUANTITY; index++)
  4222. {
  4223. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4224. {
  4225. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4226. }
  4227. } // END for CCS_QUANTITY
  4228. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4229. }
  4230. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4231. {
  4232. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4233. {
  4234. tempIndex = ((gun_index==2) ? 1: 0);
  4235. }
  4236. else
  4237. {
  4238. tempIndex = gun_index;
  4239. }
  4240. for (int index = 0; index < GB_QUANTITY; index++)
  4241. {
  4242. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4243. {
  4244. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4245. }
  4246. }// END for GB_QUANTITY
  4247. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4248. }
  4249. else if(gunType[gun_index] == GUN_TYPE_DO)
  4250. {
  4251. tempIndex = gun_index;
  4252. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4253. {
  4254. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4255. {
  4256. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4257. }
  4258. }
  4259. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4260. }
  4261. else
  4262. {
  4263. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4264. {
  4265. tempIndex = 2;
  4266. }
  4267. else
  4268. {
  4269. tempIndex = gun_index;
  4270. }
  4271. for (int index = 0; index < AC_QUANTITY; index++)
  4272. {
  4273. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4274. {
  4275. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4276. }
  4277. } // END for AC_QUANTITY
  4278. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  4279. }
  4280. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4281. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  4282. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  4283. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  4284. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  4285. }
  4286. //============================ Voltage L1 ====================================
  4287. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4288. {
  4289. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4290. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4291. {
  4292. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4293. {
  4294. tempIndex = ((gun_index==2) ? 1: 0);
  4295. }
  4296. else
  4297. {
  4298. tempIndex = gun_index;
  4299. }
  4300. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4301. {
  4302. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4303. {
  4304. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4305. }
  4306. } // END OF FOR CHAdeMO_QUANTITY
  4307. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4308. }
  4309. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4310. {
  4311. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4312. {
  4313. tempIndex = ((gun_index==2) ? 1: 0);
  4314. }
  4315. else
  4316. {
  4317. tempIndex = gun_index;
  4318. }
  4319. for (int index = 0; index < CCS_QUANTITY; index++)
  4320. {
  4321. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4322. {
  4323. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4324. }
  4325. } // END OF FOR CCS_QUANTITY
  4326. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4327. }
  4328. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4329. {
  4330. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4331. {
  4332. tempIndex = ((gun_index==2) ? 1: 0);
  4333. }
  4334. else
  4335. {
  4336. tempIndex = gun_index;
  4337. }
  4338. for (int index = 0; index < GB_QUANTITY; index++)
  4339. {
  4340. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4341. {
  4342. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4343. }
  4344. } // END OF FOR GB_QUANTITY
  4345. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4346. }
  4347. else if(gunType[gun_index] == GUN_TYPE_DO)
  4348. {
  4349. tempIndex = gun_index;
  4350. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4351. {
  4352. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4353. {
  4354. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4355. }
  4356. }
  4357. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4358. }
  4359. else
  4360. {
  4361. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4362. {
  4363. tempIndex = 2;
  4364. }
  4365. else
  4366. {
  4367. tempIndex = gun_index;
  4368. }
  4369. for (int index = 0; index < AC_QUANTITY; index++)
  4370. {
  4371. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4372. {
  4373. 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
  4374. }
  4375. } // END OF FOR AC_QUANTITY
  4376. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  4377. }
  4378. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4379. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  4380. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  4381. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  4382. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4383. }
  4384. //====================== End SoC ================================
  4385. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4386. {
  4387. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4388. 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))
  4389. {
  4390. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4391. {
  4392. tempIndex = ((gun_index==2) ? 1: 0);
  4393. }
  4394. else
  4395. {
  4396. tempIndex = gun_index;
  4397. }
  4398. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4399. {
  4400. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4401. {
  4402. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4403. {
  4404. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  4405. }
  4406. }
  4407. }
  4408. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4409. {
  4410. for (int index = 0; index < CCS_QUANTITY; index++)
  4411. {
  4412. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4413. {
  4414. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  4415. }
  4416. }
  4417. }
  4418. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4419. {
  4420. for (int index = 0; index < GB_QUANTITY; index++)
  4421. {
  4422. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4423. {
  4424. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  4425. }
  4426. }
  4427. }
  4428. else if(gunType[gun_index] == GUN_TYPE_DO)
  4429. {
  4430. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4431. {
  4432. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4433. {
  4434. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  4435. }
  4436. }
  4437. }
  4438. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4439. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  4440. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4441. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  4442. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  4443. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4444. } // END FOR DC CASE
  4445. }
  4446. // ================================= Current.Import L2 ===============================================
  4447. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4448. {
  4449. // AC 3 phse L2 current
  4450. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4451. {
  4452. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4453. {
  4454. tempIndex = 2;
  4455. }
  4456. else
  4457. {
  4458. tempIndex = gun_index;
  4459. }
  4460. for (int index = 0; index < AC_QUANTITY; index++)
  4461. {
  4462. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4463. {
  4464. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  4465. }
  4466. }// End of for AC_QUANTITY
  4467. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  4468. }
  4469. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4470. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  4471. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  4472. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  4473. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4474. }
  4475. // ================================= Current.Import L3 ===============================================
  4476. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4477. {
  4478. // AC 3 phse L3 current
  4479. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4480. {
  4481. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4482. {
  4483. tempIndex = 2;
  4484. }
  4485. else
  4486. {
  4487. tempIndex = gun_index;
  4488. }
  4489. for (int index = 0; index < AC_QUANTITY; index++)
  4490. {
  4491. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4492. {
  4493. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  4494. }
  4495. }// End of for AC_QUANTITY
  4496. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  4497. }
  4498. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4499. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  4500. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  4501. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  4502. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4503. }
  4504. //============================ Voltage L2 ====================================
  4505. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4506. {
  4507. // AC 3 phse L2 voltage
  4508. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4509. {
  4510. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4511. {
  4512. tempIndex = 2;
  4513. }
  4514. else
  4515. {
  4516. tempIndex = gun_index;
  4517. }
  4518. for (int index = 0; index < AC_QUANTITY; index++)
  4519. {
  4520. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4521. {
  4522. 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
  4523. }
  4524. } // END OF FOR AC_QUANTITY
  4525. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  4526. }
  4527. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4528. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  4529. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  4530. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  4531. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4532. }
  4533. //============================ Voltage L3 ====================================
  4534. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4535. {
  4536. // AC 3 phse L3 voltage
  4537. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4538. {
  4539. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4540. {
  4541. tempIndex = 2;
  4542. }
  4543. else
  4544. {
  4545. tempIndex = gun_index;
  4546. }
  4547. for (int index = 0; index < AC_QUANTITY; index++)
  4548. {
  4549. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4550. {
  4551. 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
  4552. }
  4553. } // END OF FOR AC_QUANTITY
  4554. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  4555. }
  4556. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4557. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  4558. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  4559. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  4560. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4561. }
  4562. //====================== Start SoC ================================
  4563. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4564. {
  4565. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4566. 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))
  4567. {
  4568. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4569. {
  4570. tempIndex = ((gun_index==2) ? 1: 0);
  4571. }
  4572. else
  4573. {
  4574. tempIndex = gun_index;
  4575. }
  4576. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4577. {
  4578. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4579. {
  4580. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4581. {
  4582. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  4583. }
  4584. }
  4585. }
  4586. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4587. {
  4588. for (int index = 0; index < CCS_QUANTITY; index++)
  4589. {
  4590. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4591. {
  4592. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  4593. }
  4594. }
  4595. }
  4596. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4597. {
  4598. for (int index = 0; index < GB_QUANTITY; index++)
  4599. {
  4600. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4601. {
  4602. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  4603. }
  4604. }
  4605. }
  4606. else if(gunType[gun_index] == GUN_TYPE_DO)
  4607. {
  4608. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4609. {
  4610. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4611. {
  4612. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  4613. }
  4614. }
  4615. }
  4616. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4617. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  4618. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4619. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  4620. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  4621. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4622. } // END FOR DC CASE
  4623. }
  4624. //================================================ Message create ====================================================
  4625. json_object *StopTransaction = json_object_new_object();
  4626. json_object *transactionDatas = json_object_new_array();
  4627. json_object *sampledValues = json_object_new_array();
  4628. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  4629. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  4630. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  4631. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  4632. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  4633. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  4634. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  4635. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  4636. {
  4637. json_object *transactionData = json_object_new_object();
  4638. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  4639. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  4640. {
  4641. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  4642. {
  4643. json_object *sampledValue = json_object_new_object();
  4644. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  4645. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  4646. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  4647. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  4648. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  4649. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  4650. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  4651. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  4652. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  4653. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  4654. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  4655. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  4656. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  4657. json_object_array_add(sampledValues, sampledValue);
  4658. }
  4659. }
  4660. json_object_object_add(transactionData, "sampledValue", sampledValues);
  4661. json_object_array_add(transactionDatas, transactionData);
  4662. }
  4663. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  4664. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  4665. ,MESSAGE_TYPE_CALL
  4666. ,guid
  4667. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  4668. json_object_put(StopTransaction);
  4669. #if 1 // for TempStopTransaction
  4670. //Delete TempStopTransaction
  4671. if((access(TempStopTransaction,F_OK))!=-1)
  4672. {
  4673. remove(TempStopTransaction); // remove file "TempStopTransaction"
  4674. }
  4675. #endif
  4676. #if 1
  4677. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4678. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4679. {
  4680. result = PASS;
  4681. //DEBUG_INFO("StopTransaction mapitem pass\n");
  4682. }
  4683. #endif
  4684. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4685. OCPP_insert_transaction_msg(NO, queuedata);
  4686. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4687. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  4688. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  4689. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4690. {
  4691. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  4692. }
  4693. //for test
  4694. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4695. return result;
  4696. }
  4697. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  4698. {
  4699. mtrace();
  4700. int result = FAIL;
  4701. char guid[37]={0};
  4702. char tempdata[65]={0};
  4703. int tempIndex = 0;
  4704. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4705. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4706. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  4707. //set value
  4708. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4709. 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) )?
  4710. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  4711. -1);
  4712. random_uuid(guid);
  4713. //UTC Date time
  4714. struct timeval tmnow;
  4715. struct tm *tm;
  4716. char buf[28];//, usec_buf[6];
  4717. gettimeofday(&tmnow, NULL);
  4718. time_t t;
  4719. t = time(NULL);
  4720. /*UTC time and date*/
  4721. tm = gmtime(&t);
  4722. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4723. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4724. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4725. //********************************(1)Current.Import L1************************************************/
  4726. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  4727. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  4728. (dataType == ReadingContext_Trigger))
  4729. {
  4730. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4731. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4732. {
  4733. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4734. {
  4735. tempIndex = ((gun_index==2) ? 1: 0);
  4736. }
  4737. else
  4738. {
  4739. tempIndex = gun_index;
  4740. }
  4741. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4742. {
  4743. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4744. {
  4745. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4746. }
  4747. }
  4748. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4749. }
  4750. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4751. {
  4752. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4753. {
  4754. tempIndex = ((gun_index==2) ? 1: 0);
  4755. }
  4756. else
  4757. {
  4758. tempIndex = gun_index;
  4759. }
  4760. for (int index = 0; index < CCS_QUANTITY; index++)
  4761. {
  4762. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4763. {
  4764. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4765. }
  4766. }
  4767. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4768. }
  4769. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4770. {
  4771. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4772. {
  4773. tempIndex = ((gun_index==2) ? 1: 0);
  4774. }
  4775. else
  4776. {
  4777. tempIndex = gun_index;
  4778. }
  4779. for (int index = 0; index < GB_QUANTITY; index++)
  4780. {
  4781. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4782. {
  4783. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4784. }
  4785. }
  4786. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4787. }
  4788. else if(gunType[gun_index] == GUN_TYPE_DO)
  4789. {
  4790. tempIndex = gun_index;
  4791. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4792. {
  4793. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4794. {
  4795. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  4796. }
  4797. }
  4798. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4799. }
  4800. else
  4801. {
  4802. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4803. {
  4804. tempIndex = 2;
  4805. }
  4806. else
  4807. {
  4808. tempIndex = gun_index;
  4809. }
  4810. for (int index = 0; index < AC_QUANTITY; index++)
  4811. {
  4812. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4813. {
  4814. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4815. }
  4816. }
  4817. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4818. }
  4819. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4820. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4821. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4822. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4823. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4824. }
  4825. //********************************(2)Energy.Active.Import.Register ************************************************/
  4826. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4827. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4828. (dataType == ReadingContext_Trigger))
  4829. {
  4830. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4831. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4832. {
  4833. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4834. {
  4835. tempIndex = ((gun_index==2) ? 1: 0);
  4836. }
  4837. else
  4838. {
  4839. tempIndex = gun_index;
  4840. }
  4841. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4842. {
  4843. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4844. {
  4845. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4846. }
  4847. }
  4848. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4849. }
  4850. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4851. {
  4852. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4853. {
  4854. tempIndex = ((gun_index==2) ? 1: 0);
  4855. }
  4856. else
  4857. {
  4858. tempIndex = gun_index;
  4859. }
  4860. for (int index = 0; index < CCS_QUANTITY; index++)
  4861. {
  4862. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4863. {
  4864. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4865. }
  4866. }
  4867. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4868. }
  4869. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4870. {
  4871. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4872. {
  4873. tempIndex = ((gun_index==2) ? 1: 0);
  4874. }
  4875. else
  4876. {
  4877. tempIndex = gun_index;
  4878. }
  4879. for (int index = 0; index < GB_QUANTITY; index++)
  4880. {
  4881. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4882. {
  4883. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4884. }
  4885. }
  4886. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4887. }
  4888. else if(gunType[gun_index] == GUN_TYPE_DO)
  4889. {
  4890. tempIndex = gun_index;
  4891. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4892. {
  4893. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4894. {
  4895. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  4896. }
  4897. }
  4898. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4899. }
  4900. else
  4901. {
  4902. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4903. {
  4904. tempIndex = 2;
  4905. }
  4906. else
  4907. {
  4908. tempIndex = gun_index;
  4909. }
  4910. for (int index = 0; index < AC_QUANTITY; index++)
  4911. {
  4912. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4913. {
  4914. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  4915. }
  4916. }
  4917. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4918. }
  4919. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  4920. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  4921. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  4922. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  4923. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4924. }
  4925. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  4926. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  4927. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  4928. (dataType == ReadingContext_Trigger))
  4929. {
  4930. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4931. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4932. {
  4933. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4934. {
  4935. tempIndex = ((gun_index==2) ? 1: 0);
  4936. }
  4937. else
  4938. {
  4939. tempIndex = gun_index;
  4940. }
  4941. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4942. {
  4943. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4944. {
  4945. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  4946. }
  4947. } // END OF FOR CHAdeMO_QUANTITY
  4948. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4949. }
  4950. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4951. {
  4952. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4953. {
  4954. tempIndex = ((gun_index==2) ? 1: 0);
  4955. }
  4956. else
  4957. {
  4958. tempIndex = gun_index;
  4959. }
  4960. for (int index = 0; index < CCS_QUANTITY; index++)
  4961. {
  4962. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4963. {
  4964. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  4965. }
  4966. } // END OF CCS_QUANTITY
  4967. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4968. }
  4969. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4970. {
  4971. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4972. {
  4973. tempIndex = ((gun_index==2) ? 1: 0);
  4974. }
  4975. else
  4976. {
  4977. tempIndex = gun_index;
  4978. }
  4979. for (int index = 0; index < GB_QUANTITY; index++)
  4980. {
  4981. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4982. {
  4983. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  4984. }
  4985. } // END OF GB_QUANTITY
  4986. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4987. }
  4988. else if(gunType[gun_index] == GUN_TYPE_DO)
  4989. {
  4990. tempIndex = gun_index;
  4991. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4992. {
  4993. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4994. {
  4995. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  4996. }
  4997. }
  4998. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4999. }
  5000. else
  5001. {
  5002. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5003. {
  5004. tempIndex = 2;
  5005. }
  5006. else
  5007. {
  5008. tempIndex = gun_index;
  5009. }
  5010. for (int index = 0; index < AC_QUANTITY; index++)
  5011. {
  5012. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5013. {
  5014. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  5015. }
  5016. }
  5017. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  5018. }
  5019. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  5020. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  5021. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  5022. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  5023. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5024. }
  5025. //********************************(4)Power.Active.Import************************************************/
  5026. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Power.Active.Import") != NULL)) ||
  5027. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Power.Active.Import") != NULL)) ||
  5028. (dataType == ReadingContext_Trigger))
  5029. {
  5030. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5031. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5032. {
  5033. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5034. {
  5035. tempIndex = ((gun_index==2) ? 1: 0);
  5036. }
  5037. else
  5038. {
  5039. tempIndex = gun_index;
  5040. }
  5041. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5042. {
  5043. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5044. {
  5045. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  5046. }
  5047. } // END OF FOR
  5048. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5049. }
  5050. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5051. {
  5052. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5053. {
  5054. tempIndex = ((gun_index==2) ? 1: 0);
  5055. }
  5056. else
  5057. {
  5058. tempIndex = gun_index;
  5059. }
  5060. for (int index = 0; index < CCS_QUANTITY; index++)
  5061. {
  5062. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5063. {
  5064. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  5065. }
  5066. }
  5067. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5068. }
  5069. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5070. {
  5071. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5072. {
  5073. tempIndex = ((gun_index==2) ? 1: 0);
  5074. }
  5075. else
  5076. {
  5077. tempIndex = gun_index;
  5078. }
  5079. for (int index = 0; index < GB_QUANTITY; index++)
  5080. {
  5081. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5082. {
  5083. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5084. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  5085. }
  5086. }
  5087. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5088. }
  5089. else if(gunType[gun_index] == GUN_TYPE_DO)
  5090. {
  5091. tempIndex = gun_index;
  5092. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5093. {
  5094. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5095. {
  5096. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5097. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  5098. }
  5099. }
  5100. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5101. }
  5102. else
  5103. {
  5104. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5105. {
  5106. tempIndex = 2;
  5107. }
  5108. else
  5109. {
  5110. tempIndex = gun_index;
  5111. }
  5112. for (int index = 0; index < AC_QUANTITY; index++)
  5113. {
  5114. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5115. {
  5116. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  5117. }
  5118. }
  5119. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  5120. }
  5121. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  5122. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  5123. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  5124. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  5125. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  5126. }
  5127. //***********************************************(5)VOLTAGE L1******************************************************/
  5128. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5129. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5130. (dataType == ReadingContext_Trigger))
  5131. {
  5132. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5133. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5134. {
  5135. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5136. {
  5137. tempIndex = ((gun_index==2) ? 1: 0);
  5138. }
  5139. else
  5140. {
  5141. tempIndex = gun_index;
  5142. }
  5143. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5144. {
  5145. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5146. {
  5147. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  5148. }
  5149. }
  5150. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5151. }
  5152. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5153. {
  5154. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5155. {
  5156. tempIndex = ((gun_index==2) ? 1: 0);
  5157. }
  5158. else
  5159. {
  5160. tempIndex = gun_index;
  5161. }
  5162. for (int index = 0; index < CCS_QUANTITY; index++)
  5163. {
  5164. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5165. {
  5166. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  5167. }
  5168. }
  5169. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5170. }
  5171. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5172. {
  5173. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5174. {
  5175. tempIndex = ((gun_index==2) ? 1: 0);
  5176. }
  5177. else
  5178. {
  5179. tempIndex = gun_index;
  5180. }
  5181. for (int index = 0; index < GB_QUANTITY; index++)
  5182. {
  5183. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5184. {
  5185. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  5186. }
  5187. }
  5188. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5189. }
  5190. else if(gunType[gun_index] == GUN_TYPE_DO)
  5191. {
  5192. tempIndex = gun_index;
  5193. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5194. {
  5195. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5196. {
  5197. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  5198. }
  5199. }
  5200. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5201. }
  5202. else
  5203. {
  5204. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5205. {
  5206. tempIndex = 2;
  5207. }
  5208. else
  5209. {
  5210. tempIndex = gun_index;
  5211. }
  5212. for (int index = 0; index < AC_QUANTITY; index++)
  5213. {
  5214. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5215. {
  5216. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  5217. }
  5218. }
  5219. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  5220. }
  5221. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  5222. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  5223. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  5224. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  5225. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5226. }
  5227. //***********************************************(6)SOC******************************************************/
  5228. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "SOC") != NULL)) ||
  5229. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "SOC") != NULL)) ||
  5230. (dataType == ReadingContext_Trigger))
  5231. {
  5232. 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))
  5233. {
  5234. //idx_sample=5;
  5235. //sampledValue = NULL;
  5236. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5237. {
  5238. tempIndex = ((gun_index==2) ? 1: 0);
  5239. }
  5240. else
  5241. {
  5242. tempIndex = gun_index;
  5243. }
  5244. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5245. {
  5246. //tempIndex = ((gun_index==2) ? 1: 0);
  5247. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5248. {
  5249. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5250. {
  5251. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  5252. }
  5253. }
  5254. }
  5255. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5256. {
  5257. //tempIndex = ((gun_index==2) ? 1: 0);
  5258. for (int index = 0; index < CCS_QUANTITY; index++)
  5259. {
  5260. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5261. {
  5262. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  5263. }
  5264. }
  5265. }
  5266. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5267. {
  5268. //tempIndex = ((gun_index==2) ? 1: 0);
  5269. for (int index = 0; index < GB_QUANTITY; index++)
  5270. {
  5271. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5272. {
  5273. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  5274. }
  5275. }
  5276. }
  5277. else if(gunType[gun_index] == GUN_TYPE_DO)
  5278. {
  5279. //tempIndex = ((gun_index==2) ? 1: 0);
  5280. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5281. {
  5282. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5283. {
  5284. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  5285. }
  5286. }
  5287. }
  5288. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  5289. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  5290. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  5291. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  5292. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  5293. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  5294. }
  5295. }
  5296. //********************************(7)Current.Import L2************************************************/
  5297. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5298. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5299. (dataType == ReadingContext_Trigger))
  5300. {
  5301. // Only for AC 3 phase
  5302. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5303. {
  5304. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5305. {
  5306. tempIndex = 2;
  5307. }
  5308. else
  5309. {
  5310. tempIndex = gun_index;
  5311. }
  5312. for (int index = 0; index < AC_QUANTITY; index++)
  5313. {
  5314. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5315. {
  5316. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  5317. }
  5318. }
  5319. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  5320. }
  5321. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  5322. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  5323. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  5324. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  5325. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5326. }
  5327. //********************************(8)Current.Import L3************************************************/
  5328. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5329. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5330. (dataType == ReadingContext_Trigger))
  5331. {
  5332. // Only for AC 3 phase
  5333. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5334. {
  5335. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5336. {
  5337. tempIndex = 2;
  5338. }
  5339. else
  5340. {
  5341. tempIndex = gun_index;
  5342. }
  5343. for (int index = 0; index < AC_QUANTITY; index++)
  5344. {
  5345. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5346. {
  5347. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  5348. }
  5349. }
  5350. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  5351. }
  5352. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  5353. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  5354. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  5355. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  5356. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5357. }
  5358. //***********************************************(9)VOLTAGE L2******************************************************/
  5359. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5360. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5361. (dataType == ReadingContext_Trigger))
  5362. {
  5363. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5364. {
  5365. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5366. {
  5367. tempIndex = 2;
  5368. }
  5369. else
  5370. {
  5371. tempIndex = gun_index;
  5372. }
  5373. for (int index = 0; index < AC_QUANTITY; index++)
  5374. {
  5375. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5376. {
  5377. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  5378. }
  5379. }
  5380. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  5381. }
  5382. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  5383. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  5384. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  5385. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  5386. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5387. }
  5388. //***********************************************(10)VOLTAGE L3******************************************************/
  5389. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5390. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5391. (dataType == ReadingContext_Trigger))
  5392. {
  5393. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5394. {
  5395. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5396. {
  5397. tempIndex = 2;
  5398. }
  5399. else
  5400. {
  5401. tempIndex = gun_index;
  5402. }
  5403. for (int index = 0; index < AC_QUANTITY; index++)
  5404. {
  5405. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5406. {
  5407. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  5408. }
  5409. }
  5410. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  5411. }
  5412. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  5413. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  5414. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  5415. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  5416. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5417. }
  5418. // Message create ====================================================================================================
  5419. if(TRUE)
  5420. {
  5421. json_object *MeterValueReq = json_object_new_object();
  5422. json_object *MeterValues = json_object_new_array();
  5423. json_object *sampledValues = json_object_new_array();
  5424. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  5425. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  5426. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  5427. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  5428. {
  5429. json_object *MeterValue = json_object_new_object();
  5430. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  5431. {
  5432. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  5433. {
  5434. json_object *sampledValue = json_object_new_object();
  5435. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  5436. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  5437. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  5438. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  5439. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  5440. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  5441. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  5442. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  5443. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  5444. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  5445. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  5446. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  5447. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  5448. json_object_array_add(sampledValues, sampledValue);
  5449. }
  5450. }
  5451. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  5452. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  5453. json_object_array_add(MeterValues, MeterValue);
  5454. }
  5455. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  5456. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  5457. ,gun_index + 1
  5458. ,MESSAGE_TYPE_CALL
  5459. ,guid
  5460. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  5461. json_object_put(MeterValueReq);
  5462. }
  5463. // Put request guid to hash map
  5464. sprintf(tempdata, "MeterValues,%d", (gun_index));
  5465. 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*/)
  5466. {
  5467. result = PASS;
  5468. //DEBUG_INFO("MeterValues mapitem pass\n");
  5469. }
  5470. if((dataType != ReadingContext_Trigger) &&
  5471. (dataType != ReadingContext_Sample_Clock) &&
  5472. (ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1))
  5473. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  5474. else
  5475. {
  5476. if(FirstHeartBeat)
  5477. LWS_Send(queuedata +2);
  5478. }
  5479. return result;
  5480. }
  5481. //==========================================
  5482. // send confirm routine
  5483. //==========================================
  5484. int sendCancelReservationConfirmation(char *uuid,char *payload)
  5485. {
  5486. mtrace();
  5487. int result = FAIL;
  5488. char message[100]={0};
  5489. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  5490. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5491. LWS_Send(message);
  5492. result = TRUE;
  5493. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  5494. return result;
  5495. }
  5496. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  5497. {
  5498. mtrace();
  5499. int result = FAIL;
  5500. char message[100]={0};
  5501. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  5502. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5503. LWS_Send(message);
  5504. result = TRUE;
  5505. return result;
  5506. }
  5507. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  5508. {
  5509. mtrace();
  5510. int result = FAIL;
  5511. char message[100]={0};
  5512. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  5513. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5514. LWS_Send(message);
  5515. result = TRUE;
  5516. return result;
  5517. }
  5518. int sendClearCacheConfirmation(char *uuid,char *payload)
  5519. {
  5520. mtrace();
  5521. int result = FAIL;
  5522. char message[500]={0};
  5523. DEBUG_INFO("sendClearCacheConfirmation...\n");
  5524. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5525. LWS_Send(message);
  5526. return result;
  5527. }
  5528. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  5529. {
  5530. mtrace();
  5531. int result = FAIL;
  5532. char message[500]={0};
  5533. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  5534. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5535. LWS_Send(message);
  5536. return result;
  5537. }
  5538. int sendDataTransferConfirmation(char *uuid,char *payload)
  5539. {
  5540. mtrace();
  5541. char statusStr[20]={0};
  5542. char dataStr[10]={0};
  5543. char sstr[20]={0};
  5544. int c = 0;
  5545. char *loc;
  5546. int result = FAIL;
  5547. DEBUG_INFO("sendDataTransferConfirmation...\n");
  5548. /**********************status**************************/
  5549. loc = strstr(payload, "status");
  5550. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5551. c = 0;
  5552. while (loc[3+strlen("status")+c] != '\"')
  5553. {
  5554. sstr[c] = loc[3+strlen("status")+c];
  5555. c++;
  5556. }
  5557. sstr[c] = '\0';
  5558. strcpy(statusStr, sstr);
  5559. /**********************data**************************/
  5560. loc = strstr(payload, "data");
  5561. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5562. c = 0;
  5563. while (loc[3+strlen("data")+c] != '\"')
  5564. {
  5565. sstr[c] = loc[3+strlen("data")+c];
  5566. c++;
  5567. }
  5568. sstr[c] = '\0';
  5569. strcpy(dataStr, sstr);
  5570. return result;
  5571. }
  5572. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  5573. {
  5574. mtrace();
  5575. int result = FAIL;
  5576. char message[1000]={0};
  5577. int CompositeScheduleIndex = 0;
  5578. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  5579. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  5580. if(nPeriod == 0)
  5581. {
  5582. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  5583. {
  5584. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  5585. ,MESSAGE_TYPE_CALLRESULT
  5586. ,uuid
  5587. ,payload
  5588. ,connectorIdInt);
  5589. }
  5590. else
  5591. {
  5592. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  5593. ,MESSAGE_TYPE_CALLRESULT
  5594. ,uuid
  5595. ,payload
  5596. ,connectorIdInt
  5597. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5598. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5599. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5600. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  5601. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  5602. }
  5603. }
  5604. else
  5605. {
  5606. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  5607. ,MESSAGE_TYPE_CALLRESULT
  5608. ,uuid
  5609. ,payload
  5610. ,connectorIdInt
  5611. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5612. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5613. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5614. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  5615. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  5616. {
  5617. if (idx_sample == 0)
  5618. {
  5619. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5620. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5621. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5622. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5623. }
  5624. else
  5625. {
  5626. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5627. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5628. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5629. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5630. }
  5631. }
  5632. sprintf(message + strlen(message), "]}}]");
  5633. }
  5634. LWS_Send(message);
  5635. result = TRUE;
  5636. return result;
  5637. }
  5638. int sendGetConfigurationConfirmation(char *uuid)
  5639. {
  5640. mtrace();
  5641. int result = FAIL;
  5642. int MaxKeySupported = 0;
  5643. int sentConfigurationNumber= 0;
  5644. int sentunConfigurationNumber= 0;
  5645. char message[4000]={0};
  5646. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  5647. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  5648. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  5649. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  5650. ,MESSAGE_TYPE_CALLRESULT
  5651. ,uuid );
  5652. //configuration key
  5653. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  5654. {
  5655. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  5656. {
  5657. if (sentConfigurationNumber == 0)
  5658. {
  5659. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5660. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5661. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5662. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5663. }
  5664. else
  5665. {
  5666. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5667. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5668. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5669. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5670. }
  5671. sentConfigurationNumber = sentConfigurationNumber + 1;
  5672. }
  5673. }
  5674. sprintf(message + strlen(message), "]");
  5675. if(UnknownKeynum != 0)
  5676. {
  5677. sprintf(message + strlen(message), ",\"unknownKey\":[");
  5678. //unkown key
  5679. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  5680. {
  5681. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  5682. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  5683. if(sentunConfigurationNumber == 0)
  5684. {
  5685. sprintf(message + strlen(message), "\"%s\""
  5686. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5687. }
  5688. else
  5689. {
  5690. sprintf(message + strlen(message), ",\"%s\""
  5691. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5692. }
  5693. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  5694. }
  5695. sprintf(message + strlen(message), "]");
  5696. }
  5697. sprintf(message + strlen(message), "}]");
  5698. LWS_Send(message);
  5699. return result;
  5700. }
  5701. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  5702. {
  5703. mtrace();
  5704. int result = FAIL;
  5705. char message[400]={0};
  5706. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  5707. if(strcmp(payload,"")==0)
  5708. {
  5709. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5710. }
  5711. else
  5712. {
  5713. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5714. }
  5715. LWS_Send(message);
  5716. result = TRUE;
  5717. return result;
  5718. }
  5719. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  5720. {
  5721. mtrace();
  5722. int result = FAIL;
  5723. char message[80]={0};
  5724. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  5725. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  5726. LWS_Send(message);
  5727. result = TRUE;
  5728. return result;
  5729. }
  5730. int sendRemoteStartConfirmation(char *uuid,char *payload)
  5731. {
  5732. mtrace();
  5733. int result = FAIL;
  5734. char message[80]={0};
  5735. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  5736. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5737. LWS_Send(message);
  5738. result = TRUE;
  5739. return result;
  5740. }
  5741. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5742. {
  5743. mtrace();
  5744. int result = FAIL;
  5745. char message[80]={0};
  5746. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5747. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5748. LWS_Send(message);
  5749. result = TRUE;
  5750. return result;
  5751. }
  5752. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5753. {
  5754. mtrace();
  5755. int result = FAIL;
  5756. char message[80]={0};
  5757. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5758. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  5759. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5760. LWS_Send(message);
  5761. result = TRUE;
  5762. return result;
  5763. }
  5764. int sendResetConfirmation(char *uuid,char *payload)
  5765. {
  5766. mtrace();
  5767. int result = FAIL;
  5768. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  5769. char message[80]={0};
  5770. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  5771. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5772. LWS_Send(message);
  5773. result = TRUE;
  5774. return result;
  5775. }
  5776. int sendSendLocalListConfirmation(char *uuid,char *payload)
  5777. {
  5778. mtrace();
  5779. int result = FAIL;
  5780. char message[500]={0};
  5781. // [ 3, "1571284266109", { "status": "Accepted" } ]
  5782. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5783. LWS_Send(message);
  5784. result = TRUE;
  5785. return result;
  5786. }
  5787. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  5788. {
  5789. mtrace();
  5790. int result = FAIL;
  5791. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  5792. char message[80]={0};
  5793. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  5794. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5795. LWS_Send(message);
  5796. result = TRUE;
  5797. return result;
  5798. }
  5799. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  5800. {
  5801. mtrace();
  5802. int result = FAIL;
  5803. char message[80]={0};
  5804. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  5805. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5806. LWS_Send(message);
  5807. result = TRUE;
  5808. return result;
  5809. }
  5810. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  5811. {
  5812. mtrace();
  5813. int result = FAIL;
  5814. char message[80]={0};
  5815. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5816. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  5817. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5818. LWS_Send(message);
  5819. result = TRUE;
  5820. return result;
  5821. }
  5822. int sendUpdateFirmwareConfirmation(char *uuid)
  5823. {
  5824. mtrace();
  5825. int result = FAIL;
  5826. char message[60]={0};
  5827. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5828. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  5829. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5830. LWS_Send(message);
  5831. result = TRUE;
  5832. return result;
  5833. }
  5834. int sendUnknownConfirmation(char *uuid)
  5835. {
  5836. mtrace();
  5837. int result = FAIL;
  5838. char message[256]={0};
  5839. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5840. DEBUG_INFO("sendUnknownConfirmation...\n");
  5841. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  5842. LWS_Send(message);
  5843. result = TRUE;
  5844. return result;
  5845. }
  5846. //==========================================
  5847. // Handle server request routine Start
  5848. //==========================================
  5849. int handleCancelReservationRequest(char *uuid, char *payload)
  5850. {
  5851. mtrace();
  5852. int result = FAIL;
  5853. int gunNO = 0;
  5854. int reservationIdInt = -1;
  5855. char comfirmstr[20];
  5856. DEBUG_INFO("handleCancelReservationRequest...\n");
  5857. json_object *CancelReservation;
  5858. CancelReservation = json_tokener_parse(payload);
  5859. if(!is_error(CancelReservation))
  5860. {
  5861. // Required data
  5862. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  5863. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  5864. }
  5865. json_object_put(CancelReservation);
  5866. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  5867. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5868. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  5869. if(reservationIdInt != -1)
  5870. {
  5871. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  5872. //check Transaction active
  5873. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5874. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5875. {
  5876. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  5877. {
  5878. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5879. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5880. if(gunType[2] == GUN_TYPE_CHAdeMO)
  5881. {
  5882. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  5883. }
  5884. else
  5885. {
  5886. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  5887. }
  5888. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5889. goto end;
  5890. }
  5891. }
  5892. for (int index = 0; index < CCS_QUANTITY; index++)
  5893. {
  5894. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  5895. {
  5896. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5897. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5898. if(gunType[2] == GUN_TYPE_CCS)
  5899. {
  5900. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  5901. }
  5902. else
  5903. {
  5904. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  5905. }
  5906. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5907. goto end;
  5908. }
  5909. }
  5910. for (int index = 0; index < GB_QUANTITY; index++)
  5911. {
  5912. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  5913. {
  5914. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5915. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5916. if(gunType[2] == GUN_TYPE_GBT)
  5917. {
  5918. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  5919. }
  5920. else
  5921. {
  5922. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  5923. }
  5924. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5925. goto end;
  5926. }
  5927. }
  5928. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5929. {
  5930. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  5931. {
  5932. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5933. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5934. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  5935. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5936. goto end;
  5937. }
  5938. }
  5939. for (int index = 0; index < AC_QUANTITY; index++)
  5940. {
  5941. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  5942. {
  5943. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5944. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5945. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5946. {
  5947. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  5948. }
  5949. else
  5950. {
  5951. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  5952. }
  5953. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5954. goto end;
  5955. }
  5956. }
  5957. }
  5958. //The reservationId does NOT match the reservationId
  5959. sendCancelReservationConfirmation(uuid, comfirmstr);
  5960. end:
  5961. // Fill in ocpp packet uuid
  5962. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  5963. return result;
  5964. }
  5965. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  5966. {
  5967. mtrace();
  5968. int result = FAIL;
  5969. int gunIndex = 0;
  5970. char typeStr[16]={0};
  5971. char comfirmstr[20];
  5972. int specificId = FALSE;
  5973. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  5974. json_object *ChangeAvailability;
  5975. ChangeAvailability = json_tokener_parse(payload);
  5976. if(!is_error(ChangeAvailability))
  5977. {
  5978. // Required data
  5979. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  5980. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  5981. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  5982. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  5983. }
  5984. json_object_put(ChangeAvailability);
  5985. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5986. {
  5987. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  5988. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  5989. }
  5990. else if(gunIndex == 0)
  5991. {
  5992. for(int i=0; i < gunTotalNumber; i++)
  5993. {
  5994. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  5995. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  5996. }
  5997. }
  5998. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5999. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6000. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  6001. {
  6002. specificId = TRUE;
  6003. }
  6004. if(specificId == FALSE)
  6005. goto end;
  6006. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  6007. {
  6008. //----------------------gunIndex is 0 ------------------------------------------------//
  6009. if(gunIndex == 0)
  6010. {
  6011. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6012. {
  6013. for(int i=0; i < gunTotalNumber; i++)
  6014. {
  6015. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6016. {
  6017. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  6018. {
  6019. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6020. {
  6021. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6022. goto end;
  6023. }
  6024. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6025. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6026. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6027. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6028. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6029. {
  6030. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6031. goto end;
  6032. }
  6033. }
  6034. }//END FOR CHAdeMO_QUANTITY
  6035. for (int index = 0; index < CCS_QUANTITY; index++)
  6036. {
  6037. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  6038. {
  6039. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  6040. {
  6041. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6042. goto end;
  6043. }
  6044. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6045. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6046. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6047. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6048. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6049. {
  6050. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6051. goto end;
  6052. }
  6053. }
  6054. }//END FOR CCS_QUANTITY
  6055. for (int index = 0; index < GB_QUANTITY; index++)
  6056. {
  6057. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  6058. {
  6059. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6060. {
  6061. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6062. goto end;
  6063. }
  6064. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6065. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6066. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6067. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6068. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6069. {
  6070. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6071. goto end;
  6072. }
  6073. }
  6074. }// END FOR GB_QUANTITY
  6075. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6076. {
  6077. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  6078. {
  6079. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6080. {
  6081. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6082. goto end;
  6083. }
  6084. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  6085. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  6086. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  6087. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  6088. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6089. {
  6090. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6091. goto end;
  6092. }
  6093. }
  6094. }// END FOR GENERAL_GUN_QUANTITY
  6095. for (int index = 0; index < AC_QUANTITY; index++)
  6096. {
  6097. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  6098. {
  6099. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6100. {
  6101. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6102. goto end;
  6103. }
  6104. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6105. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6106. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6107. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6108. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6109. {
  6110. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6111. goto end;
  6112. }
  6113. }
  6114. }//END FOR AC_QUANTITY
  6115. }// END FOR gunTotalNumber
  6116. }
  6117. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6118. {
  6119. for(int i=0; i < gunTotalNumber; i++)
  6120. {
  6121. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6122. {
  6123. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6124. goto end;
  6125. }
  6126. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6127. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  6128. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  6129. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  6130. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6131. {
  6132. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6133. goto end;
  6134. }
  6135. }
  6136. }
  6137. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6138. goto end;
  6139. }
  6140. //----------------------gunIndex is not 0 ------------------------------------------------//
  6141. //check Transaction active
  6142. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6143. {
  6144. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  6145. {
  6146. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  6147. {
  6148. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6149. goto end;
  6150. }
  6151. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6152. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6153. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6154. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6155. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6156. {
  6157. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6158. goto end;
  6159. }
  6160. else
  6161. {
  6162. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  6163. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6164. goto end;
  6165. }
  6166. }
  6167. }//END FOR CHAdeMO_QUANTITY
  6168. for (int index = 0; index < CCS_QUANTITY; index++)
  6169. {
  6170. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  6171. {
  6172. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  6173. {
  6174. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6175. goto end;
  6176. }
  6177. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6178. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6179. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6180. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6181. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6182. {
  6183. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6184. goto end;
  6185. }
  6186. else
  6187. {
  6188. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  6189. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6190. goto end;
  6191. }
  6192. }
  6193. }//END FOR CCS_QUANTITY
  6194. for (int index = 0; index < GB_QUANTITY; index++)
  6195. {
  6196. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  6197. {
  6198. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6199. {
  6200. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6201. goto end;
  6202. }
  6203. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6204. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6205. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6206. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6207. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6208. {
  6209. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6210. goto end;
  6211. }
  6212. else
  6213. {
  6214. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  6215. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6216. goto end;
  6217. }
  6218. }
  6219. }// END FOR GB_QUANTITY
  6220. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6221. {
  6222. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  6223. {
  6224. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6225. {
  6226. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6227. goto end;
  6228. }
  6229. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  6230. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  6231. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  6232. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  6233. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6234. {
  6235. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6236. goto end;
  6237. }
  6238. else
  6239. {
  6240. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  6241. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6242. goto end;
  6243. }
  6244. }
  6245. }// END FOR GENERAL_GUN_QUANTITY
  6246. for (int index = 0; index < AC_QUANTITY; index++)
  6247. {
  6248. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  6249. {
  6250. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6251. {
  6252. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6253. goto end;
  6254. }
  6255. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6256. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6257. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6258. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6259. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6260. {
  6261. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6262. goto end;
  6263. }
  6264. else
  6265. {
  6266. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  6267. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6268. goto end;
  6269. }
  6270. }
  6271. }//END FOR AC_QUANTITY
  6272. }//END FOR AvailabilityTypeStr[Inoperative]
  6273. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  6274. {
  6275. //----------------------gunIndex is 0 ------------------------------------------------//
  6276. if(gunIndex == 0)
  6277. {
  6278. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6279. {
  6280. for(int i=0; i < gunTotalNumber; i++)
  6281. {
  6282. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6283. {
  6284. 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
  6285. {
  6286. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6287. goto end;
  6288. }
  6289. }//END FOR CHAdeMO_QUANTITY
  6290. for (int index = 0; index < CCS_QUANTITY; index++)
  6291. {
  6292. 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
  6293. {
  6294. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6295. goto end;
  6296. }
  6297. }//END FOR CCS_QUANTITY
  6298. for (int index = 0; index < GB_QUANTITY; index++)
  6299. {
  6300. 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
  6301. {
  6302. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6303. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6304. goto end;
  6305. }
  6306. }// END FOR GB_QUANTITY
  6307. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6308. {
  6309. 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
  6310. {
  6311. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6312. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6313. goto end;
  6314. }
  6315. }// END FOR GENERAL_GUN_QUANTITY
  6316. for (int index = 0; index < AC_QUANTITY; index++)
  6317. {
  6318. 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
  6319. {
  6320. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6321. goto end;
  6322. }
  6323. }//END FOR CHAdeMO_QUANTITY
  6324. }// END FOR gunTotalNumber
  6325. }
  6326. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6327. {
  6328. for(int i=0; i < gunTotalNumber; i++)
  6329. {
  6330. for (int index = 0; index < AC_QUANTITY; index++)
  6331. {
  6332. 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
  6333. {
  6334. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6335. goto end;
  6336. }
  6337. }//END FOR CHAdeMO_QUANTITY
  6338. } // END FOR gunTotalNumber
  6339. }
  6340. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6341. goto end;
  6342. }
  6343. //----------------------gunIndex is not 0 ------------------------------------------------//
  6344. //check Transaction active
  6345. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6346. {
  6347. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6348. {
  6349. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6350. goto end;
  6351. }
  6352. }//END FOR CHAdeMO_QUANTITY
  6353. for (int index = 0; index < CCS_QUANTITY; index++)
  6354. {
  6355. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6356. {
  6357. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6358. goto end;
  6359. }
  6360. }//END FOR CCS_QUANTITY
  6361. for (int index = 0; index < GB_QUANTITY; index++)
  6362. {
  6363. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6364. {
  6365. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6366. goto end;
  6367. }
  6368. }// END FOR GB_QUANTITY
  6369. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6370. {
  6371. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6372. {
  6373. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6374. goto end;
  6375. }
  6376. }// END FOR GENERAL_GUN_QUANTITY
  6377. for (int index = 0; index < AC_QUANTITY; index++)
  6378. {
  6379. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6380. {
  6381. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6382. goto end;
  6383. }
  6384. }//END FOR AC_QUANTITY
  6385. }//END FOR AvailabilityTypeStr[Operative]
  6386. end:
  6387. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6388. {
  6389. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  6390. }
  6391. else
  6392. {
  6393. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  6394. }
  6395. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6396. {
  6397. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6398. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6399. }
  6400. else if(gunIndex == 0)
  6401. {
  6402. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6403. {
  6404. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  6405. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  6406. }
  6407. }
  6408. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  6409. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6410. return result;
  6411. }
  6412. int handleChangeConfigurationRequest(char *uuid, char *payload)
  6413. {
  6414. mtrace();
  6415. int result = FAIL;
  6416. char keystr[40]={0};
  6417. char valuestr[256]={0};
  6418. char comfirmstr[20]={0};
  6419. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  6420. json_object *ChangeConfiguration;
  6421. ChangeConfiguration = json_tokener_parse(payload);
  6422. if(!is_error(ChangeConfiguration))
  6423. {
  6424. // Required data
  6425. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  6426. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  6427. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  6428. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  6429. }
  6430. json_object_put(ChangeConfiguration);
  6431. if((uuid==NULL) || (payload ==NULL) )
  6432. {
  6433. DEBUG_ERROR("Payload is null\n");
  6434. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6435. }
  6436. else
  6437. {
  6438. int status = setKeyValue(keystr, valuestr);
  6439. switch(status)
  6440. {
  6441. case ConfigurationStatus_Accepted:
  6442. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  6443. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  6444. StoreConfigurationTable();
  6445. break;
  6446. case RebootRequired:
  6447. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  6448. StoreConfigurationTable();
  6449. break;
  6450. case NotSupported:
  6451. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  6452. break;
  6453. case ConfigurationStatus_Rejected:
  6454. default:
  6455. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6456. break;
  6457. }
  6458. }
  6459. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  6460. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  6461. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6462. {
  6463. ChageWebSocketPingInterval(atoi(valuestr));
  6464. }
  6465. if((strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6466. {
  6467. SetOcppConnStatus(FALSE);
  6468. }
  6469. return result;
  6470. }
  6471. int handleClearCacheRequest(char *uuid, char *payload)
  6472. {
  6473. mtrace();
  6474. int result = FAIL;
  6475. char comfirmstr[20];
  6476. char rmFileCmd[100]={0};
  6477. struct stat stats;
  6478. DEBUG_INFO("handleClearCacheRequest...\n");
  6479. stat("/Storage/OCPP", &stats);
  6480. // Check for directory existence
  6481. if (S_ISDIR(stats.st_mode) == 1)
  6482. {}
  6483. else
  6484. {
  6485. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  6486. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  6487. system(rmFileCmd);
  6488. }
  6489. if(OCPP_cleanLocalCache())
  6490. {
  6491. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  6492. }
  6493. else
  6494. {
  6495. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  6496. }
  6497. sendClearCacheConfirmation(uuid, comfirmstr);
  6498. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6499. return result;
  6500. }
  6501. int handleClearChargingProfileRequest(char *uuid, char *payload)
  6502. {
  6503. mtrace();
  6504. int result = FAIL;
  6505. int resultRename;
  6506. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  6507. char chargingProfilePurposeStr[26]={0};
  6508. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  6509. char tempchargingProfilePurposeStr[26]={0};
  6510. char str[100]={0};
  6511. char fname[200]={0};
  6512. char comfirmstr[20]={0};
  6513. char word[1600]={0};
  6514. int clearflag = FALSE;
  6515. int chargingProfileIdIsNULL = FALSE;
  6516. int connectorIsNULL = FALSE;
  6517. int chargingProfilePurposeIsNULL = FALSE;
  6518. int stackLevelIsNULL = FALSE;
  6519. //int GotoEnd = FALSE;
  6520. FILE *fptr1, *fptr2;
  6521. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  6522. int n_chargingProfile=0;
  6523. int isEmptyFile = FALSE;
  6524. char sLineWord[1600]={0};
  6525. char chargingProfiles[10][100]={0};
  6526. int ChargeProfileCount = 0;
  6527. int ch;
  6528. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  6529. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  6530. json_object *ClearChargingProfile;
  6531. ClearChargingProfile = json_tokener_parse(payload);
  6532. if(!is_error(ClearChargingProfile))
  6533. {
  6534. // Optional data
  6535. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  6536. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  6537. else
  6538. chargingProfileIdIsNULL = TRUE;
  6539. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  6540. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  6541. else
  6542. connectorIsNULL = TRUE;
  6543. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  6544. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  6545. else
  6546. chargingProfilePurposeIsNULL = TRUE;
  6547. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  6548. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  6549. else
  6550. stackLevelIsNULL = TRUE;
  6551. }
  6552. json_object_put(ClearChargingProfile);
  6553. if(connectorIsNULL == FALSE)
  6554. {
  6555. switch(connectorIdInt)
  6556. {
  6557. case 0:
  6558. if(chargingProfilePurposeIsNULL == TRUE)
  6559. {
  6560. int l = 0;
  6561. strcpy(fname, ChargePointMaxProfile_JSON);
  6562. if((access(fname,F_OK))!=-1)
  6563. {
  6564. strcpy(chargingProfiles[l], fname);
  6565. l = l + 1;
  6566. }
  6567. strcpy(fname, TxDefaultProfile_0_JSON);
  6568. if((access(fname,F_OK))!=-1)
  6569. {
  6570. strcpy(chargingProfiles[l], fname);
  6571. l = l + 1;
  6572. }
  6573. ChargeProfileCount = l;
  6574. }
  6575. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  6576. {
  6577. strcpy(fname, ChargePointMaxProfile_JSON);
  6578. if((access(fname,F_OK))!=-1)
  6579. {
  6580. strcpy(chargingProfiles[0], fname);
  6581. ChargeProfileCount = 1;
  6582. }
  6583. }
  6584. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6585. {
  6586. strcpy(fname, TxDefaultProfile_0_JSON);
  6587. if((access(fname,F_OK))!=-1)
  6588. {
  6589. strcpy(chargingProfiles[0], fname);
  6590. ChargeProfileCount = 1;
  6591. }
  6592. }
  6593. break;
  6594. default:
  6595. if(chargingProfilePurposeIsNULL == TRUE)
  6596. {
  6597. int m = 0;
  6598. memset(fname, 0, ARRAY_SIZE(fname));
  6599. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6600. if((access(fname,F_OK))!=-1)
  6601. {
  6602. strcpy(chargingProfiles[m], fname);
  6603. m = m + 1;
  6604. }
  6605. memset(fname, 0, ARRAY_SIZE(fname));
  6606. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6607. if((access(fname,F_OK))!=-1)
  6608. {
  6609. strcpy(chargingProfiles[m], fname);
  6610. m = m + 1;
  6611. }
  6612. ChargeProfileCount = m;
  6613. }
  6614. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6615. {
  6616. //strcpy(fname, TxDefaultProfile_1_JSON);
  6617. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6618. if((access(fname,F_OK))!=-1)
  6619. {
  6620. strcpy(chargingProfiles[0], fname);
  6621. ChargeProfileCount = 1;
  6622. }
  6623. }
  6624. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  6625. {
  6626. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6627. if((access(fname,F_OK))!=-1)
  6628. {
  6629. strcpy(chargingProfiles[0], fname);
  6630. ChargeProfileCount = 1;
  6631. }
  6632. //strcpy(fname, TxProfile_1_JSON);
  6633. }
  6634. //strcpy(fname, ChargePointMaxProfile_JSON );
  6635. break;
  6636. }
  6637. }
  6638. else // Check all Charging Profiles
  6639. {
  6640. int i = 0;
  6641. char fnametemp[200]={0};
  6642. ChargeProfileCount = 0;
  6643. //Check ChargePointMaxProfile.json exit
  6644. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  6645. {
  6646. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  6647. i = i + 1;
  6648. }
  6649. //Check TxDefaultProfile_0.json exit
  6650. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  6651. {
  6652. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  6653. i = i + 1;
  6654. }
  6655. //Check TxDefaultProfile_%d.json
  6656. for(int j=1; j <= gunTotalNumber; j++)
  6657. {
  6658. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6659. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  6660. if((access(fnametemp,F_OK))!=-1)
  6661. {
  6662. strcpy(chargingProfiles[i], fnametemp);
  6663. i = i + 1;
  6664. }
  6665. }
  6666. //Check TxProfile_%d.json
  6667. for(int j=1; j <= gunTotalNumber; j++)
  6668. {
  6669. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6670. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  6671. if((access(fnametemp,F_OK))!=-1)
  6672. {
  6673. strcpy(chargingProfiles[i], fnametemp);
  6674. i = i + 1;
  6675. }
  6676. }
  6677. ChargeProfileCount = i;
  6678. }// End connectorIsNULL is TRUE
  6679. if(ChargeProfileCount == 0)
  6680. {
  6681. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6682. goto end;
  6683. }
  6684. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  6685. {
  6686. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6687. goto end;
  6688. }
  6689. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  6690. {
  6691. memset(str, 0, ARRAY_SIZE(str));
  6692. // clear temp file
  6693. sprintf(str,"rm -f %s",temp);
  6694. system(str);
  6695. for(int k=0; k < ChargeProfileCount; k++)
  6696. {
  6697. memset(str, 0, ARRAY_SIZE(str));
  6698. //clear file in C
  6699. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6700. system(str);
  6701. }
  6702. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6703. goto end;
  6704. }
  6705. else if(connectorIsNULL == TRUE)
  6706. {
  6707. for(int k=0; k < ChargeProfileCount; k++)
  6708. {
  6709. fptr1 = fopen(chargingProfiles[k], "r");
  6710. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  6711. //Check Charging Profile Count
  6712. while(fscanf(fptr1, "%s", word) != EOF)
  6713. {
  6714. //DEBUG_INFO("word=%s\n",word);
  6715. if(strstr(word, "chargingProfileId")!= NULL)
  6716. {
  6717. //DEBUG_INFO("test chargingProfileId \n");
  6718. n_chargingProfile = n_chargingProfile + 1;
  6719. //DEBUG_INFO("chargingProfileId Found\n");
  6720. }
  6721. }
  6722. rewind(fptr1);
  6723. //search Charging Profile Element
  6724. //int i= 0;
  6725. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6726. {
  6727. json_object *tmpProfilee;
  6728. tmpProfilee = json_tokener_parse(sLineWord);
  6729. if(!is_error(tmpProfilee))
  6730. {
  6731. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  6732. {
  6733. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  6734. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  6735. }
  6736. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  6737. {
  6738. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  6739. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  6740. }
  6741. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  6742. {
  6743. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  6744. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  6745. }
  6746. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  6747. {
  6748. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  6749. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  6750. }
  6751. }
  6752. json_object_put(tmpProfilee);
  6753. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6754. {
  6755. //------- not write to fptr2-------//
  6756. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6757. //clearflag = TRUE;
  6758. }
  6759. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  6760. {
  6761. //------- not write to fptr2-------//
  6762. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6763. }
  6764. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6765. {
  6766. //------- not write to fptr2-------//
  6767. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6768. }
  6769. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  6770. {
  6771. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6772. }
  6773. else
  6774. {
  6775. fprintf(fptr2, sLineWord);//writing data into file
  6776. }
  6777. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6778. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6779. if(clearflag == TRUE)
  6780. {
  6781. fclose(fptr1);
  6782. fclose(fptr2);
  6783. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6784. system(str);
  6785. // clear temp file
  6786. sprintf(str,"rm -f %s",temp);
  6787. system(str);
  6788. }
  6789. else
  6790. {
  6791. fclose(fptr1);
  6792. fclose(fptr2);
  6793. memset(str, 0, ARRAY_SIZE(str));
  6794. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6795. system(str);
  6796. resultRename = rename(temp, chargingProfiles[k]);
  6797. if(resultRename == 0)
  6798. {
  6799. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  6800. }
  6801. else
  6802. {
  6803. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  6804. }
  6805. if(comfirmstr[0]== 0)
  6806. {
  6807. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6808. }
  6809. //Check chargingProfile is empty file
  6810. /*------ Read the file ----------------*/
  6811. fptr1=fopen(chargingProfiles[k],"r");
  6812. ch=fgetc(fptr1);
  6813. rewind(fptr1);
  6814. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6815. if(ch!=EOF)
  6816. {
  6817. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6818. {
  6819. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6820. if(sLineWord[0]=='\0')
  6821. {
  6822. isEmptyFile = TRUE;
  6823. break;
  6824. }
  6825. else
  6826. {
  6827. isEmptyFile = FALSE;
  6828. break;
  6829. }
  6830. }
  6831. }
  6832. else
  6833. isEmptyFile = TRUE;
  6834. fclose(fptr1);
  6835. if(isEmptyFile == TRUE)
  6836. {
  6837. memset(str, 0, ARRAY_SIZE(str));
  6838. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6839. system(str);
  6840. }
  6841. }
  6842. }// End of while(int k=0; k < ChargePointCount; k++)
  6843. }
  6844. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  6845. {
  6846. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  6847. for(int k=0; k < ChargeProfileCount; k++)
  6848. {
  6849. fptr1 = fopen(chargingProfiles[k], "r");
  6850. fptr2 = fopen(temp, "w+");
  6851. //Check Charging Profile Count
  6852. while(fscanf(fptr1, "%s", word) != EOF)
  6853. {
  6854. //DEBUG_INFO("word=%s\n",word);
  6855. if(strstr(word, "chargingProfileId")!= NULL)
  6856. {
  6857. n_chargingProfile = n_chargingProfile + 1;
  6858. }
  6859. }
  6860. rewind(fptr1);
  6861. //search Charging Profile Element
  6862. //int i= 0;
  6863. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6864. {
  6865. json_object *tmpProfilee;
  6866. tmpProfilee = json_tokener_parse(sLineWord);
  6867. if(!is_error(tmpProfilee))
  6868. {
  6869. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  6870. {
  6871. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  6872. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  6873. }
  6874. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  6875. {
  6876. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  6877. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  6878. }
  6879. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  6880. {
  6881. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  6882. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  6883. }
  6884. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  6885. {
  6886. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  6887. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  6888. }
  6889. }
  6890. json_object_put(tmpProfilee);
  6891. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6892. {
  6893. //------- not write to fptr2-------//
  6894. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6895. //clearflag = TRUE;
  6896. }
  6897. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6898. {
  6899. //------- not write to fptr2-------//
  6900. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6901. }
  6902. else if(stackLevelIsNULL == TRUE)
  6903. {
  6904. //Clear Whole File
  6905. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6906. clearflag = TRUE;
  6907. break;
  6908. }
  6909. else
  6910. {
  6911. fprintf(fptr2, sLineWord);//writing data into file
  6912. }
  6913. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6914. }
  6915. if(clearflag == TRUE)
  6916. {
  6917. fclose(fptr1);
  6918. fclose(fptr2);
  6919. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6920. system(str);
  6921. // clear temp file
  6922. sprintf(str,"rm -f %s",temp);
  6923. system(str);
  6924. }
  6925. else
  6926. {
  6927. fclose(fptr1);
  6928. fclose(fptr2);
  6929. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6930. system(str);
  6931. resultRename = rename(temp, chargingProfiles[k]);
  6932. if(resultRename == 0)
  6933. {
  6934. DEBUG_INFO("File ChargingProfile renamed successfully");
  6935. }
  6936. else
  6937. {
  6938. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6939. }
  6940. if(comfirmstr[0]== 0)
  6941. {
  6942. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6943. }
  6944. //Check chargingProfile is empty file
  6945. /*------ Read the file ----------------*/
  6946. fptr1=fopen(chargingProfiles[k],"r");
  6947. ch=fgetc(fptr1);
  6948. rewind(fptr1);
  6949. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6950. if(ch!=EOF)
  6951. {
  6952. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6953. {
  6954. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6955. if(sLineWord[0]=='\0')
  6956. {
  6957. isEmptyFile = TRUE;
  6958. break;
  6959. }
  6960. else
  6961. {
  6962. isEmptyFile = FALSE;
  6963. break;
  6964. }
  6965. }
  6966. }
  6967. else
  6968. isEmptyFile = TRUE;
  6969. fclose(fptr1);
  6970. if(isEmptyFile == TRUE)
  6971. {
  6972. memset(str, 0, ARRAY_SIZE(str));
  6973. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6974. system(str);
  6975. }
  6976. /*------- End of reading ---------------*/
  6977. }
  6978. } // while(int k=0; k < ChargeProfileCount; k++)
  6979. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  6980. end:
  6981. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  6982. {
  6983. if(connectorIdInt == 0)
  6984. {
  6985. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  6986. {
  6987. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  6988. }
  6989. }
  6990. else
  6991. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  6992. }
  6993. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  6994. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6995. return result;
  6996. }
  6997. void createFirmwareVersionByDataTransfer(void)
  6998. {
  6999. json_object *FirmwareDataTransfer = json_object_new_object();
  7000. // AC & DC model
  7001. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  7002. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  7003. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  7004. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  7005. // DC model
  7006. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O')
  7007. {
  7008. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  7009. {
  7010. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7011. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7012. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  7013. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  7014. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7015. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7016. }
  7017. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  7018. ((gunType[1] != GUN_TYPE_UNKNOWN) || (gunType[2] != GUN_TYPE_UNKNOWN) || (gunType[3] != GUN_TYPE_UNKNOWN)))
  7019. {
  7020. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  7021. }
  7022. }
  7023. else
  7024. {
  7025. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7026. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7027. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7028. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7029. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  7030. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  7031. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  7032. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  7033. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  7034. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  7035. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  7036. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  7037. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  7038. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  7039. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  7040. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  7041. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  7042. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  7043. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  7044. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  7045. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  7046. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  7047. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  7048. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  7049. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  7050. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  7051. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  7052. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  7053. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  7054. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  7055. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  7056. }
  7057. // 4G model
  7058. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  7059. {
  7060. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  7061. }
  7062. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  7063. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  7064. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  7065. json_object_put(FirmwareDataTransfer);
  7066. }
  7067. int handleDataTransferRequest(char *uuid, char *payload)
  7068. {
  7069. mtrace();
  7070. json_object *response = json_object_new_object();
  7071. int result = FAIL;
  7072. char tempvendorId[255]={0};
  7073. char tempmessageId[50]={0};
  7074. char tempdata[512]={0};
  7075. char message[2048]={0};
  7076. DEBUG_INFO("handleDataTransferRequest...\n");
  7077. if((uuid != NULL) && (payload != NULL))
  7078. {
  7079. json_object *DataTransfer;
  7080. DataTransfer = json_tokener_parse(payload);
  7081. if(!is_error(DataTransfer))
  7082. {
  7083. // Required data
  7084. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  7085. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  7086. // Optional data
  7087. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  7088. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  7089. if(json_object_object_get(DataTransfer, "data") != NULL)
  7090. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  7091. result = PASS;
  7092. }
  7093. json_object_put(DataTransfer);
  7094. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  7095. {
  7096. // Send all moudle firmware version on EVSE
  7097. createFirmwareVersionByDataTransfer();
  7098. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7099. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  7100. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7101. json_object_put(response);
  7102. }
  7103. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  7104. {
  7105. system("/usr/bin/run_tmate_restart.sh &");
  7106. }
  7107. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  7108. {
  7109. json_object *data;
  7110. data = json_tokener_parse(tempdata);
  7111. if(!is_error(data))
  7112. {
  7113. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  7114. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  7115. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  7116. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  7117. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  7118. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  7119. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  7120. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  7121. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  7122. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  7123. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7124. }
  7125. else
  7126. {
  7127. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7128. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7129. }
  7130. json_object_put(data);
  7131. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7132. json_object_put(response);
  7133. }
  7134. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  7135. {
  7136. json_object *data;
  7137. data = json_tokener_parse(tempdata);
  7138. if(!is_error(data))
  7139. {
  7140. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  7141. if(json_object_object_get(data, "idToken") != NULL)
  7142. {
  7143. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  7144. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  7145. }
  7146. if(json_object_object_get(data, "price") != NULL)
  7147. {
  7148. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  7149. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  7150. }
  7151. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7152. }
  7153. else
  7154. {
  7155. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7156. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7157. }
  7158. json_object_put(data);
  7159. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7160. json_object_put(response);
  7161. }
  7162. else if(strstr(tempmessageId, "RunningCost") != NULL)
  7163. {
  7164. json_object *data;
  7165. data = json_tokener_parse(tempdata);
  7166. if(!is_error(data))
  7167. {
  7168. if(json_object_object_get(data, "txId") != NULL)
  7169. {
  7170. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7171. for(int idx = 0;idx<gunTotalNumber;idx++)
  7172. {
  7173. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7174. {
  7175. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  7176. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7177. if(json_object_object_get(data, "description") != NULL)
  7178. {
  7179. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7180. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7181. }
  7182. }
  7183. }
  7184. }
  7185. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7186. }
  7187. else
  7188. {
  7189. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7190. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7191. }
  7192. json_object_put(data);
  7193. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7194. json_object_put(response);
  7195. }
  7196. else if(strstr(tempmessageId, "FinalCost") != NULL)
  7197. {
  7198. json_object *data;
  7199. data = json_tokener_parse(tempdata);
  7200. if(!is_error(data))
  7201. {
  7202. if(json_object_object_get(data, "txId") != NULL)
  7203. {
  7204. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7205. for(int idx = 0;idx<gunTotalNumber;idx++)
  7206. {
  7207. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7208. {
  7209. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  7210. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7211. if(json_object_object_get(data, "description") != NULL)
  7212. {
  7213. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7214. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7215. }
  7216. }
  7217. }
  7218. }
  7219. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7220. }
  7221. else
  7222. {
  7223. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7224. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7225. }
  7226. json_object_put(data);
  7227. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7228. json_object_put(response);
  7229. }
  7230. else
  7231. {
  7232. // Can not find valid message id
  7233. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  7234. }
  7235. }
  7236. else
  7237. {
  7238. // Payload is null
  7239. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  7240. }
  7241. LWS_Send(message);
  7242. return result;
  7243. }
  7244. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  7245. {
  7246. mtrace();
  7247. int result = FAIL;
  7248. int connectorIdInt, durationInt;
  7249. char chargingRateUnitStr[4]={0};
  7250. char comfirmstr[20];
  7251. int confirmPeriods = 0;
  7252. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  7253. json_object *GetCompositeSchedule;
  7254. GetCompositeSchedule = json_tokener_parse(payload);
  7255. if(!is_error(GetCompositeSchedule))
  7256. {
  7257. // Required data
  7258. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  7259. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  7260. else
  7261. connectorIdInt = -1;
  7262. if(json_object_object_get(GetCompositeSchedule, "duration"))
  7263. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  7264. else
  7265. durationInt = 86400;
  7266. // Optional data
  7267. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  7268. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  7269. }
  7270. json_object_put(GetCompositeSchedule);
  7271. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  7272. if((connectorIdInt == 0) ||
  7273. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  7274. {
  7275. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  7276. struct StructChargingProfile tmpProfile[1];
  7277. if(strstr(chargingRateUnitStr, "W") != NULL)
  7278. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  7279. else
  7280. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  7281. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7282. {
  7283. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7284. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7285. }
  7286. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  7287. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  7288. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  7289. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7290. {
  7291. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7292. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7293. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  7294. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0))
  7295. {
  7296. confirmPeriods = idx;
  7297. break;
  7298. }
  7299. }
  7300. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  7301. }
  7302. else
  7303. {
  7304. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  7305. }
  7306. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  7307. return result;
  7308. }
  7309. int handleGetConfigurationRequest(char *uuid, char *payload)
  7310. {
  7311. mtrace();
  7312. int result = FAIL;
  7313. int MaxKeySupported = 0;
  7314. int n_keys = 0;
  7315. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  7316. DEBUG_INFO("handleGetConfigurationRequest...\n");
  7317. json_object *GetConfiguration;
  7318. GetConfiguration = json_tokener_parse(payload);
  7319. if(!is_error(GetConfiguration))
  7320. {
  7321. // Optional data
  7322. if(json_object_object_get(GetConfiguration, "key") != NULL)
  7323. {
  7324. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  7325. {
  7326. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  7327. n_keys = idx + 1;
  7328. }
  7329. }
  7330. }
  7331. json_object_put(GetConfiguration);
  7332. UnknownKeynum = 0;
  7333. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  7334. MaxKeySupported = GetConfigurationMaxKeysNUM;
  7335. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  7336. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  7337. if(n_keys != 0)
  7338. {
  7339. for(int i=0;i<n_keys;i++)
  7340. {
  7341. getKeyValue(requestKey[i]);
  7342. }
  7343. }
  7344. else
  7345. {
  7346. DEBUG_INFO("There is no key in Message, get all configuration\n");
  7347. getKeyValue("");
  7348. }
  7349. processUnkownKey();
  7350. sendGetConfigurationConfirmation(uuid);
  7351. return result;
  7352. }
  7353. static char fnamePlusPath[100]={0};
  7354. static char fnamePWithNoPath[60]={0};
  7355. void checkUploadLog(void)
  7356. {
  7357. FILE *fp;
  7358. /* Open the command for reading. */
  7359. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  7360. if (fp == NULL) {
  7361. printf("Failed to run command\n" );
  7362. exit(1);
  7363. }
  7364. int ftppathlen = 0;
  7365. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  7366. int i = 0;
  7367. /* Read the output a line at a time - output it. */
  7368. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  7369. if(i==0)
  7370. {
  7371. ftppathlen = strlen(fnamePlusPath);
  7372. printf("%s\n", fnamePlusPath);
  7373. fnamePlusPath[ftppathlen]='\0';
  7374. break;
  7375. }
  7376. i= i+1;
  7377. }
  7378. /* close */
  7379. pclose(fp);
  7380. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  7381. {
  7382. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  7383. {
  7384. fnamePlusPath[k]='\0';
  7385. }
  7386. }
  7387. i=1;
  7388. //char fname[60]={0};
  7389. while(i < ftppathlen)
  7390. {
  7391. int len=ftppathlen-i;
  7392. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  7393. {
  7394. printf("compare '/' all right\n");
  7395. break;
  7396. }
  7397. i=i+1;
  7398. }
  7399. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  7400. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  7401. fnamePWithNoPath[i+1] = '\0';
  7402. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  7403. {
  7404. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  7405. {
  7406. fnamePWithNoPath[j]='\0';
  7407. }
  7408. }
  7409. FILE* fp1 = fopen(fnamePlusPath, "r");
  7410. if (fp1)
  7411. {
  7412. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  7413. // file exists
  7414. fclose(fp1);
  7415. }
  7416. else
  7417. {
  7418. // file doesn't exist
  7419. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  7420. }
  7421. }
  7422. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  7423. {
  7424. mtrace();
  7425. int result = FAIL;
  7426. time_t CurrentTime;
  7427. struct tm *tm;
  7428. pthread_t th_Status;
  7429. CurrentTime = time(NULL);
  7430. tm = localtime(&CurrentTime);
  7431. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  7432. 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);
  7433. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  7434. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  7435. return result;
  7436. }
  7437. void* GetDiagnosticsProcess(void* data)
  7438. {
  7439. pthread_detach(pthread_self());
  7440. mtrace();
  7441. int retriesInt=0, retryIntervalInt=0;
  7442. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  7443. 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};
  7444. int port=0;
  7445. int isSuccess = FALSE;
  7446. char ftpbuf[200]={0};
  7447. char cmdBuf[2048];
  7448. struct tm *tmNow;
  7449. time_t CurrentTime;
  7450. struct tm tmStart;
  7451. struct tm tmStop;
  7452. CurrentTime = time(NULL);
  7453. tmNow=localtime(&CurrentTime);
  7454. uint16_t targetYear, targetMonth;
  7455. json_object *GetDiagnostics;
  7456. DEBUG_INFO("GetDiagnosticsProcess...\n");
  7457. GetDiagnostics = json_tokener_parse(data);
  7458. if(!is_error(GetDiagnostics))
  7459. {
  7460. // Required data
  7461. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  7462. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  7463. // Optional data
  7464. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  7465. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  7466. else
  7467. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  7468. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  7469. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  7470. else
  7471. retryIntervalInt = 30;
  7472. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  7473. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  7474. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  7475. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  7476. }
  7477. json_object_put(GetDiagnostics);
  7478. // Pack log to compress file
  7479. 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) &&
  7480. (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))
  7481. {
  7482. // Pack system log
  7483. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  7484. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  7485. targetYear = tmStart.tm_year;
  7486. targetMonth = tmStart.tm_mon;
  7487. do
  7488. {
  7489. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7490. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7491. if(targetMonth+1>=13)
  7492. {
  7493. targetYear += 1;
  7494. targetMonth = 1;
  7495. }
  7496. else
  7497. {
  7498. targetMonth += 1;
  7499. }
  7500. }while((targetYear < (tmNow->tm_year+1900)) ||
  7501. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  7502. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  7503. system(cmdBuf);
  7504. // Pack charging & event log
  7505. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  7506. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  7507. targetYear = tmStart.tm_year;
  7508. targetMonth = tmStart.tm_mon;
  7509. do
  7510. {
  7511. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7512. if(targetMonth+1>=13)
  7513. {
  7514. targetYear += 1;
  7515. targetMonth = 1;
  7516. }
  7517. else
  7518. {
  7519. targetMonth += 1;
  7520. }
  7521. }while((targetYear < (tmNow->tm_year+1900)) ||
  7522. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  7523. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  7524. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  7525. system(cmdBuf);
  7526. // Combine log file
  7527. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  7528. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  7529. }
  7530. else
  7531. {
  7532. system("exec /root/logPackTools 'log' 6");
  7533. }
  7534. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  7535. system(cmdBuf);
  7536. checkUploadLog();
  7537. //****************location*******************/
  7538. if(strcmp(locationstr,"")==0)
  7539. {
  7540. DEBUG_INFO("location is <Empty>!\n");
  7541. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7542. goto end;
  7543. }
  7544. memset(protocol, 0, ARRAY_SIZE(protocol));
  7545. memset(user, 0, ARRAY_SIZE(user) );
  7546. memset(password, 0, ARRAY_SIZE(password));
  7547. memset(host, 0, ARRAY_SIZE(host));
  7548. memset(path, 0, ARRAY_SIZE(path));
  7549. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  7550. memset(host1, 0, ARRAY_SIZE(host1));
  7551. memset(path1, 0, ARRAY_SIZE(path1));
  7552. /*location: ftp://user:password@host:port/path*/
  7553. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  7554. if((access(fnamePlusPath,F_OK))!=-1)
  7555. {
  7556. DEBUG_INFO("fnamePlusPath exist.\n");
  7557. }
  7558. else
  7559. {
  7560. DEBUG_INFO("fnamePlusPath not exist!\n");
  7561. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7562. goto end;
  7563. }
  7564. if(strchr(locationstr,'@')==NULL)
  7565. {
  7566. sscanf(locationstr,
  7567. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  7568. protocol, host, &port, path);
  7569. strcpy(user,"anonymous");
  7570. strcpy(password,"");
  7571. }
  7572. else
  7573. {
  7574. //DEBUG_INFO("pch=%s\n", pch);
  7575. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  7576. protocol, user, password, host, &port, path);
  7577. }
  7578. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  7579. {
  7580. DEBUG_INFO("protocol is not ftp/http ! \n");
  7581. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7582. goto end;
  7583. }
  7584. if(strncmp(locationstr,"http", 4) == 0)
  7585. {
  7586. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  7587. sprintf(ftppath,"/%s", path);
  7588. do
  7589. {
  7590. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  7591. sleep(3);
  7592. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  7593. if(!isSuccess)
  7594. {
  7595. DEBUG_INFO("Diagnostics fail.\n");
  7596. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7597. sleep(retryIntervalInt);
  7598. }
  7599. else
  7600. {
  7601. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  7602. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  7603. }
  7604. retriesInt--;
  7605. }while((isSuccess == 0)&&(retriesInt >= 0));
  7606. }
  7607. else
  7608. {
  7609. sscanf(host,"%[^/]%s",host1, path1);
  7610. if(strlen(path) > 0)
  7611. sprintf(ftppath,"/%s", path);
  7612. else
  7613. sprintf(ftppath,"/%s", path1);
  7614. int ftppathlen=strlen(ftppath);
  7615. int i=1;
  7616. char filenametemp[50];
  7617. while(i < ftppathlen)
  7618. {
  7619. int len=ftppathlen-i;
  7620. if(ftppath[len]== 47) // '/' ascll code: 47
  7621. {
  7622. DEBUG_INFO("find '/' all right\n");
  7623. break;
  7624. }
  7625. i=i+1;
  7626. }
  7627. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  7628. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  7629. filenametemp[i+1] = 0;
  7630. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  7631. if(port == 0)
  7632. port = 21;
  7633. do
  7634. {
  7635. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  7636. sleep(3);
  7637. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  7638. if(!isSuccess)
  7639. {
  7640. DEBUG_INFO("Diagnostics fail.\n");
  7641. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7642. sleep(retryIntervalInt);
  7643. }
  7644. else
  7645. {
  7646. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  7647. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  7648. }
  7649. retriesInt--;
  7650. }while((!isSuccess)&&(retriesInt >= 0));
  7651. }
  7652. end:
  7653. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  7654. system("rm -f /mnt/*");
  7655. pthread_exit(NULL);
  7656. }
  7657. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  7658. {
  7659. mtrace();
  7660. int result = FAIL;
  7661. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  7662. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  7663. {
  7664. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  7665. localversion = -1;
  7666. }
  7667. else
  7668. {
  7669. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  7670. OCPP_getListVerion();
  7671. }
  7672. //from db.OCPP_getListVerion
  7673. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  7674. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  7675. sendGetLocalListVersionConfirmation(uuid,"");
  7676. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  7677. return result;
  7678. }
  7679. int handleRemoteStartRequest(char *uuid, char *payload)
  7680. {
  7681. mtrace();
  7682. int result = FAIL;
  7683. int connectorIdInt=0;
  7684. int tempIndex = 0;
  7685. int connectorIdIsNULL, chargingProfileIsNULL;
  7686. char comfirmstr[20]={0};
  7687. char cmdBuf[512];
  7688. json_object *RemoteStartTransaction;
  7689. FILE *fp;
  7690. DEBUG_INFO("handleRemoteStartRequest ...\n");
  7691. if(server_pending == TRUE)
  7692. {
  7693. return 0;
  7694. }
  7695. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  7696. RemoteStartTransaction = json_tokener_parse(payload);
  7697. if(!is_error(RemoteStartTransaction))
  7698. {
  7699. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  7700. {
  7701. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  7702. if(connectorIdInt <= gunTotalNumber)
  7703. {
  7704. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  7705. // Required data
  7706. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  7707. // Optional data
  7708. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  7709. {
  7710. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  7711. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  7712. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  7713. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  7714. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  7715. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  7716. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  7717. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  7718. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  7719. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  7720. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  7721. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  7722. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  7723. {
  7724. 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")));
  7725. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  7726. 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"));
  7727. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  7728. 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"));
  7729. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  7730. 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")));
  7731. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  7732. {
  7733. 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++)
  7734. {
  7735. 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"));
  7736. 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"));
  7737. 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)
  7738. 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"));
  7739. }
  7740. }
  7741. }
  7742. }
  7743. else
  7744. chargingProfileIsNULL = TRUE;
  7745. }
  7746. }
  7747. else
  7748. connectorIdIsNULL = TRUE;
  7749. }
  7750. else
  7751. connectorIdIsNULL = TRUE;
  7752. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  7753. {
  7754. DEBUG_WARN("Connector id is NULL\n.");
  7755. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7756. goto end;
  7757. }
  7758. /*
  7759. enum _SYSTEM_STATUS
  7760. {
  7761. S_BOOTING = 0,
  7762. S_IDLE, = 1
  7763. S_AUTHORIZING, = 2
  7764. S_REASSIGN_CHECK, = 3
  7765. S_REASSIGN, = 4
  7766. S_PRECHARGE, = 5
  7767. S_PREPARING_FOR_EV, = 6
  7768. S_PREPARING_FOR_EVSE, = 7
  7769. S_CHARGING, = 8
  7770. S_TERMINATING, = 9
  7771. S_COMPLETE, = 10
  7772. S_ALARM, = 11
  7773. S_FAULT = 12
  7774. }
  7775. */
  7776. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  7777. {
  7778. //check Transaction active
  7779. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  7780. {
  7781. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7782. {
  7783. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7784. }
  7785. else
  7786. {
  7787. tempIndex = connectorIdInt -1;
  7788. }
  7789. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7790. {
  7791. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  7792. {
  7793. 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))
  7794. {
  7795. //Reserved
  7796. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7797. }
  7798. 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))
  7799. {
  7800. //Reserved
  7801. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7802. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7803. goto end;
  7804. }
  7805. else
  7806. {
  7807. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7808. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  7809. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  7810. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  7811. {
  7812. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  7813. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7814. goto end;
  7815. }
  7816. }//END FOR ELSE
  7817. }
  7818. }// END FOR CHAdeMO_QUANTITY
  7819. }
  7820. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  7821. {
  7822. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7823. {
  7824. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7825. }
  7826. else
  7827. {
  7828. tempIndex = connectorIdInt -1;
  7829. }
  7830. for (int index = 0; index < CCS_QUANTITY; index++)
  7831. {
  7832. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7833. {
  7834. 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))
  7835. {
  7836. //Reserved
  7837. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7838. }
  7839. 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))
  7840. {
  7841. //Reserved
  7842. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7843. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7844. goto end;
  7845. }
  7846. else
  7847. {
  7848. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7849. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7850. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7851. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7852. {
  7853. DEBUG_WARN("CCS connector not allow start\n.");
  7854. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7855. goto end;
  7856. }
  7857. }// END FOR ELSE
  7858. }
  7859. }// END FOR CCS_QUANTITY
  7860. }
  7861. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  7862. {
  7863. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7864. {
  7865. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7866. }
  7867. else
  7868. {
  7869. tempIndex = connectorIdInt -1;
  7870. }
  7871. for (int index = 0; index < GB_QUANTITY; index++)
  7872. {
  7873. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  7874. {
  7875. 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))
  7876. {
  7877. //Reserved
  7878. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7879. }
  7880. 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))
  7881. {
  7882. //Reserved
  7883. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7884. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7885. goto end;
  7886. }
  7887. else
  7888. {
  7889. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7890. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7891. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7892. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7893. {
  7894. DEBUG_WARN("GB connector not allow start\n.");
  7895. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7896. goto end;
  7897. }
  7898. }// END FOR ELSE
  7899. }
  7900. } // END FOR GB_QUANTITY
  7901. }
  7902. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  7903. {
  7904. tempIndex = connectorIdInt -1;
  7905. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7906. {
  7907. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  7908. {
  7909. 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))
  7910. {
  7911. //Reserved
  7912. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7913. }
  7914. 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))
  7915. {
  7916. //Reserved
  7917. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7918. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7919. goto end;
  7920. }
  7921. else
  7922. {
  7923. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7924. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7925. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7926. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7927. {
  7928. DEBUG_WARN("GB connector not allow start\n.");
  7929. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7930. goto end;
  7931. }
  7932. }// END FOR ELSE
  7933. }
  7934. } // END FOR GB_QUANTITY
  7935. }
  7936. else
  7937. {
  7938. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7939. {
  7940. tempIndex = 2;
  7941. }
  7942. else
  7943. {
  7944. tempIndex = connectorIdInt -1;
  7945. }
  7946. for (int index = 0; index < AC_QUANTITY; index++)
  7947. {
  7948. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  7949. {
  7950. 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))
  7951. {
  7952. //Reserved
  7953. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7954. }
  7955. 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))
  7956. {
  7957. //Reserved
  7958. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7959. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7960. goto end;
  7961. }
  7962. else
  7963. {
  7964. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7965. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7966. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7967. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7968. {
  7969. DEBUG_WARN("AC connector not allow start\n.");
  7970. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7971. goto end;
  7972. }
  7973. }//END FOR ELSE
  7974. }
  7975. }// END FOR AC_QUANTITY
  7976. }
  7977. if(chargingProfileIsNULL == FALSE)
  7978. {
  7979. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7980. {
  7981. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7982. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7983. //memset idTag
  7984. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7985. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7986. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7987. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7988. // Save profile to file
  7989. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7990. system(cmdBuf);
  7991. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7992. fp = fopen(cmdBuf, "w");
  7993. 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));
  7994. fclose(fp);
  7995. }
  7996. else
  7997. {
  7998. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  7999. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8000. }
  8001. }
  8002. else
  8003. {
  8004. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  8005. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8006. //memset idTag
  8007. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  8008. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8009. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  8010. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8011. }
  8012. }
  8013. else
  8014. {
  8015. DEBUG_WARN("Connector id over\n.");
  8016. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8017. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  8018. }
  8019. end:
  8020. json_object_put(RemoteStartTransaction);
  8021. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  8022. {
  8023. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  8024. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  8025. }
  8026. //OCPP send RemoteStartConfirmation by first.
  8027. sendRemoteStartConfirmation(uuid, comfirmstr);
  8028. return result;
  8029. }
  8030. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  8031. {
  8032. mtrace();
  8033. int result = FAIL;
  8034. int match = FALSE;
  8035. int GunNO = 0;
  8036. int tempIndex = 0;
  8037. int transactionIdInt=0;
  8038. int transactionIdIsNULL= TRUE;
  8039. char comfirmstr[20];
  8040. json_object *RemoteStopTransaction;
  8041. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  8042. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  8043. if(server_pending == TRUE)
  8044. {
  8045. return 0;
  8046. }
  8047. RemoteStopTransaction = json_tokener_parse(payload);
  8048. if(!is_error(RemoteStopTransaction))
  8049. {
  8050. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  8051. {
  8052. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  8053. transactionIdIsNULL = FALSE;
  8054. }
  8055. }
  8056. json_object_put(RemoteStopTransaction);
  8057. if(transactionIdIsNULL == FALSE)
  8058. {
  8059. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  8060. {
  8061. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  8062. {
  8063. //check Transaction active
  8064. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  8065. {
  8066. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8067. {
  8068. tempIndex = ((gun_index==2) ? 1: 0);
  8069. }
  8070. else
  8071. {
  8072. tempIndex = gun_index;
  8073. }
  8074. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8075. {
  8076. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8077. {
  8078. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8079. {
  8080. match = TRUE;
  8081. GunNO = gun_index;
  8082. }
  8083. }
  8084. }// END FOR CHAdeMO_QUANTITY
  8085. }
  8086. else if(gunType[gun_index] == GUN_TYPE_CCS)
  8087. {
  8088. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8089. {
  8090. tempIndex = ((gun_index==2) ? 1: 0);
  8091. }
  8092. else
  8093. {
  8094. tempIndex = gun_index;
  8095. }
  8096. for (int index = 0; index < CCS_QUANTITY; index++)
  8097. {
  8098. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8099. {
  8100. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8101. {
  8102. match = TRUE;
  8103. GunNO = gun_index;
  8104. }
  8105. }
  8106. }// END FOR CCS_QUANTITY
  8107. }
  8108. else if(gunType[gun_index] == GUN_TYPE_GBT)
  8109. {
  8110. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8111. {
  8112. tempIndex = ((gun_index==2) ? 1: 0);
  8113. }
  8114. else
  8115. {
  8116. tempIndex = gun_index;
  8117. }
  8118. for (int index = 0; index < GB_QUANTITY; index++)
  8119. {
  8120. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8121. {
  8122. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8123. {
  8124. match = TRUE;
  8125. GunNO = gun_index;
  8126. }
  8127. }
  8128. }// END FOR GB_QUANTITY
  8129. }
  8130. else if(gunType[gun_index] == GUN_TYPE_DO)
  8131. {
  8132. tempIndex = gun_index;
  8133. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8134. {
  8135. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8136. {
  8137. 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
  8138. {
  8139. match = TRUE;
  8140. GunNO = gun_index;
  8141. }
  8142. }
  8143. }// END FOR GB_QUANTITY
  8144. }
  8145. else
  8146. {
  8147. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8148. {
  8149. tempIndex = 2;
  8150. }
  8151. else
  8152. {
  8153. tempIndex = gun_index;
  8154. }
  8155. for (int index = 0; index < AC_QUANTITY; index++)
  8156. {
  8157. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8158. {
  8159. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8160. {
  8161. match = TRUE;
  8162. GunNO = gun_index;
  8163. }
  8164. }
  8165. }// END FOR CHAdeMO_QUANTITY
  8166. } // END FOR AC ELSE
  8167. }// CHECK IF ResponseTransactionId == transactionIdInt
  8168. }//END FOR
  8169. if( match == TRUE)
  8170. {
  8171. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  8172. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8173. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  8174. }
  8175. else
  8176. {
  8177. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8178. }
  8179. }
  8180. else
  8181. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8182. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  8183. return result;
  8184. }
  8185. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  8186. {
  8187. mtrace();
  8188. int result = FAIL;
  8189. int connectorIdInt=0, reservationIdInt=0;
  8190. int tempIndex = 0;
  8191. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  8192. char comfirmstr[20]={0};
  8193. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  8194. int c = 0;
  8195. char *loc;
  8196. //char *ptr;
  8197. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  8198. strcpy(sstrtemp, stringtrimspace(payload));
  8199. //***(1)connectorId ****/
  8200. c=0;
  8201. loc = strstr(sstrtemp, "connectorId");
  8202. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8203. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  8204. {
  8205. sstr[c] = loc[strlen("connectorId")+2+c];
  8206. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8207. c++;
  8208. }
  8209. sstr[c] = '\0';
  8210. connectorIdInt = atoi(sstr);
  8211. //***(2)expiryDate ****/
  8212. loc = strstr(sstrtemp, "expiryDate");
  8213. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8214. c = 0;
  8215. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  8216. {
  8217. sstr[c] = loc[3+strlen("expiryDate")+c];
  8218. c++;
  8219. }
  8220. sstr[c] = '\0';
  8221. strcpy(expiryDatestr, sstr);
  8222. //***(3)idTag ****/
  8223. loc = strstr(sstrtemp, "idTag");
  8224. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8225. c = 0;
  8226. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  8227. {
  8228. sstr[c] = loc[3+strlen("idTag")+c];
  8229. c++;
  8230. }
  8231. sstr[c] = '\0';
  8232. strcpy(idTagstr, sstr);
  8233. //***(4)parentIdTag ****/
  8234. loc = strstr(sstrtemp, "parentIdTag");
  8235. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8236. c = 0;
  8237. if(loc == NULL)
  8238. {
  8239. strcpy(parentIdTagstr, "");
  8240. }
  8241. else
  8242. {
  8243. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8244. {
  8245. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8246. c++;
  8247. }
  8248. sstr[c] = '\0';
  8249. strcpy(parentIdTagstr, sstr);
  8250. }
  8251. //***(5)reservationId ****/
  8252. c=0;
  8253. loc = strstr(sstrtemp, "reservationId");
  8254. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8255. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  8256. {
  8257. sstr[c] = loc[strlen("reservationId")+2+c];
  8258. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8259. c++;
  8260. }
  8261. sstr[c] = '\0';
  8262. reservationIdInt = atoi(sstr);
  8263. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8264. /*
  8265. enum SYSTEM_STATUS
  8266. {
  8267. SYS_MODE_BOOTING = 0,
  8268. SYS_MODE_IDLE = 1,
  8269. SYS_MODE_AUTHORIZING = 2,
  8270. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  8271. SYS_MODE_REASSIGN = 4,
  8272. SYS_MODE_PREPARING = 5,
  8273. SYS_MODE_PREPARE_FOR_EV = 6,
  8274. SYS_MODE_PREPARE_FOR_EVSE = 7,
  8275. SYS_MODE_CHARGING = 8,
  8276. SYS_MODE_TERMINATING = 9,
  8277. SYS_MODE_COMPLETE = 10,
  8278. SYS_MODE_ALARM = 11,
  8279. SYS_MODE_FAULT = 12,
  8280. SYS_MODE_RESERVATION = 13,
  8281. SYS_MODE_BOOKING = 14,
  8282. SYS_MODE_MAINTAIN = 15,
  8283. SYS_MODE_DEBUG = 16,
  8284. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  8285. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  8286. SYS_MODE_UPDATE = 19
  8287. };
  8288. */
  8289. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  8290. {
  8291. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8292. goto end;
  8293. }
  8294. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  8295. {
  8296. //check Transaction active
  8297. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8298. {
  8299. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8300. {
  8301. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8302. }
  8303. else
  8304. {
  8305. tempIndex = connectorIdInt -1;
  8306. }
  8307. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8308. {
  8309. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8310. {
  8311. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  8312. {
  8313. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8314. {
  8315. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8316. {
  8317. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8318. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8319. }
  8320. 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'))
  8321. {
  8322. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8323. }
  8324. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8325. {
  8326. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8327. }
  8328. else
  8329. {
  8330. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8331. }
  8332. }
  8333. 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
  8334. {
  8335. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8336. }
  8337. }
  8338. else
  8339. {
  8340. //replace reservation
  8341. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8342. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8343. }
  8344. }
  8345. } // END FOR CHAdeMO_QUANTITY
  8346. }
  8347. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8348. {
  8349. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8350. {
  8351. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8352. }
  8353. else
  8354. {
  8355. tempIndex = connectorIdInt -1;
  8356. }
  8357. for (int index = 0; index < CCS_QUANTITY; index++)
  8358. {
  8359. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8360. {
  8361. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8362. {
  8363. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8364. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8365. {
  8366. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8367. {
  8368. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8369. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8370. }
  8371. 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'))
  8372. {
  8373. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8374. }
  8375. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  8376. {
  8377. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8378. }
  8379. else
  8380. {
  8381. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8382. }
  8383. }
  8384. 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
  8385. {
  8386. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8387. }
  8388. }
  8389. else
  8390. {
  8391. //replace reservation
  8392. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8393. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8394. }
  8395. }
  8396. } // END FOR CCS_QUANTITY
  8397. }
  8398. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8399. {
  8400. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8401. {
  8402. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8403. }
  8404. else
  8405. {
  8406. tempIndex = connectorIdInt -1;
  8407. }
  8408. for (int index = 0; index < GB_QUANTITY; index++)
  8409. {
  8410. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8411. {
  8412. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8413. {
  8414. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8415. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  8416. {
  8417. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8418. {
  8419. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8420. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8421. }
  8422. 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'))
  8423. {
  8424. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8425. }
  8426. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8427. {
  8428. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8429. }
  8430. else
  8431. {
  8432. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8433. }
  8434. }
  8435. 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
  8436. {
  8437. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8438. }
  8439. }
  8440. else
  8441. {
  8442. //replace reservation
  8443. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8444. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8445. }
  8446. }
  8447. }// END FOR GB_QUANTITY
  8448. }
  8449. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8450. {
  8451. tempIndex = connectorIdInt -1;
  8452. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8453. {
  8454. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8455. {
  8456. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  8457. {
  8458. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8459. 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
  8460. {
  8461. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8462. {
  8463. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8464. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8465. }
  8466. 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'))
  8467. {
  8468. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8469. }
  8470. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8471. {
  8472. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8473. }
  8474. else
  8475. {
  8476. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8477. }
  8478. }
  8479. 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
  8480. {
  8481. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8482. }
  8483. }
  8484. else
  8485. {
  8486. //replace reservation
  8487. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8488. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8489. }
  8490. }
  8491. }// END FOR GB_QUANTITY
  8492. }
  8493. else
  8494. {
  8495. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8496. {
  8497. tempIndex = 2;
  8498. }
  8499. else
  8500. {
  8501. tempIndex = (connectorIdInt -1);
  8502. }
  8503. for (int index = 0; index < AC_QUANTITY; index++)
  8504. {
  8505. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8506. {
  8507. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  8508. {
  8509. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  8510. {
  8511. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8512. {
  8513. 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))
  8514. {
  8515. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8516. }
  8517. else
  8518. {
  8519. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8520. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8521. }
  8522. }
  8523. 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'))
  8524. {
  8525. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8526. }
  8527. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8528. {
  8529. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8530. }
  8531. else
  8532. {
  8533. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8534. }
  8535. }
  8536. 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
  8537. {
  8538. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8539. }
  8540. }
  8541. else
  8542. {
  8543. //replace reservation
  8544. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8545. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8546. }
  8547. }
  8548. } // END FOR AC_QUANTITY
  8549. }
  8550. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8551. }
  8552. else if(connectorIdInt == 0)
  8553. {
  8554. //check Transaction active
  8555. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8556. {
  8557. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  8558. {
  8559. 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'))
  8560. {
  8561. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8562. goto end;
  8563. }
  8564. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8565. {
  8566. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8567. goto end;
  8568. }
  8569. 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
  8570. {
  8571. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8572. goto end;
  8573. }
  8574. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8575. {
  8576. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8577. goto end;
  8578. }
  8579. }
  8580. }// END FOR CHAdeMO_QUANTITY
  8581. for (int index = 0; index < CCS_QUANTITY; index++)
  8582. {
  8583. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8584. {
  8585. 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'))
  8586. {
  8587. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8588. goto end;
  8589. }
  8590. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  8591. {
  8592. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8593. goto end;
  8594. }
  8595. 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
  8596. {
  8597. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8598. goto end;
  8599. }
  8600. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8601. {
  8602. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8603. goto end;
  8604. }
  8605. }
  8606. } // END FOR CCS_QUANTITY
  8607. for (int index = 0; index < GB_QUANTITY; index++)
  8608. {
  8609. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8610. {
  8611. 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'))
  8612. {
  8613. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8614. goto end;
  8615. }
  8616. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8617. {
  8618. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8619. goto end;
  8620. }
  8621. 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
  8622. {
  8623. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8624. goto end;
  8625. }
  8626. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8627. {
  8628. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8629. goto end;
  8630. }
  8631. }
  8632. } // END FOR GB_QUANTITY
  8633. for (int index = 0; index < AC_QUANTITY; index++)
  8634. {
  8635. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  8636. {
  8637. 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'))
  8638. {
  8639. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8640. goto end;
  8641. }
  8642. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8643. {
  8644. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8645. goto end;
  8646. }
  8647. 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
  8648. {
  8649. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8650. goto end;
  8651. }
  8652. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8653. {
  8654. 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))
  8655. {
  8656. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8657. goto end;
  8658. }
  8659. }
  8660. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8661. {
  8662. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8663. goto end;
  8664. }
  8665. }
  8666. }// END FOR AC_QUANTITY
  8667. //The connectorId is 0
  8668. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  8669. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8670. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  8671. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  8672. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  8673. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  8674. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  8675. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  8676. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  8677. result = TRUE;
  8678. return result;
  8679. }
  8680. else
  8681. {
  8682. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8683. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8684. }
  8685. if(strcmp(comfirmstr,"Accepted") == 0)
  8686. {
  8687. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  8688. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  8689. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  8690. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  8691. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  8692. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  8693. result = TRUE;
  8694. return result;
  8695. }
  8696. end:
  8697. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  8698. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  8699. return result;
  8700. }
  8701. int handleResetRequest(char *uuid, char *payload)
  8702. {
  8703. mtrace();
  8704. int result = FAIL;
  8705. char sstr[10]={0},sstrtemp[30]={ 0 };
  8706. char typestr[10]={0};
  8707. char comfirmstr[20]={0};
  8708. int c = 0;
  8709. char *loc;
  8710. DEBUG_INFO("handleResetRequest...\n");
  8711. strcpy(sstrtemp, stringtrimspace(payload));
  8712. loc = strstr(sstrtemp, "type");
  8713. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8714. c = 0;
  8715. while (loc[3+strlen("type")+c] != '\"')
  8716. {
  8717. sstr[c] = loc[3+strlen("type")+c];
  8718. c++;
  8719. }
  8720. sstr[c] = '\0';
  8721. strcpy(typestr,sstr);
  8722. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  8723. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  8724. {
  8725. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  8726. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  8727. result = TRUE;
  8728. return result;
  8729. }
  8730. else
  8731. {
  8732. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  8733. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  8734. goto errorend;
  8735. }
  8736. errorend:
  8737. sendResetConfirmation(uuid, comfirmstr);
  8738. return result;
  8739. }
  8740. int handleSendLocalListRequest(char *uuid, char *payload)
  8741. {
  8742. mtrace();
  8743. int result = FAIL;
  8744. int listVersionInt;
  8745. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  8746. char listsearch[]="listVersion";
  8747. char updateTypesearch[]="updateType";
  8748. char localAuthorizationListsearch[]="localAuthorizationList";
  8749. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  8750. char CardList[500][160]={0};
  8751. char updateTypestr[15]={0};
  8752. char idTagstr[20]={0};
  8753. char parentIdTag[20]={0};
  8754. char expiryDate[30]={0};
  8755. char idTagstatus[16]={0};
  8756. int c = 0;
  8757. int i = 0;
  8758. char *delim1 = "}";
  8759. char * pch;
  8760. char *loc;
  8761. //char *ptr;
  8762. char comfirmstr[20];
  8763. //int n_localAuthorizations = 0;
  8764. int checkState_Faulted = FALSE;
  8765. DEBUG_INFO("handleSendLocalListRequest...\n");
  8766. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  8767. {
  8768. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8769. goto end;
  8770. }
  8771. //check Charge Point state
  8772. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8773. {
  8774. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8775. {
  8776. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8777. }
  8778. }
  8779. for (int index = 0; index < CCS_QUANTITY; index++)
  8780. {
  8781. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8782. {
  8783. checkState_Faulted = TRUE; //OCPP Status
  8784. }
  8785. }
  8786. for (int index = 0; index < GB_QUANTITY; index++)
  8787. {
  8788. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8789. {
  8790. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8791. }
  8792. }
  8793. //check Charge Point state
  8794. for (int index = 0; index < AC_QUANTITY; index++)
  8795. {
  8796. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8797. {
  8798. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8799. }
  8800. }
  8801. if(checkState_Faulted == TRUE)
  8802. {
  8803. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8804. goto end;
  8805. }
  8806. //Filter payload space
  8807. strcpy(sstrtemp, stringtrimspace(payload));
  8808. //listVersion
  8809. c = 0;
  8810. loc = strstr(sstrtemp, listsearch);
  8811. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  8812. {
  8813. sstr[c] = loc[strlen("listVersion")+2+c];
  8814. c++;
  8815. }
  8816. sstr[c] = '\0';
  8817. listVersionInt = atoi(sstr);
  8818. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8819. //updateType
  8820. loc = strstr(sstrtemp, updateTypesearch);
  8821. c = 0;
  8822. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  8823. {
  8824. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  8825. c++;
  8826. }
  8827. sstr[c] = '\0';
  8828. strcpy(updateTypestr, sstr);
  8829. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  8830. //localAuthorizationList
  8831. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8832. loc = strstr(sstrtemp, localAuthorizationListsearch);
  8833. if(loc != NULL) // localAuthorizationList is not NULL
  8834. {
  8835. //Check UpdateType
  8836. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8837. {
  8838. //Local list full update
  8839. printf("Local list full update.\n");
  8840. OCPP_getListVerion();
  8841. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8842. {
  8843. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8844. goto end;
  8845. }
  8846. OCPP_cleanLocalList();
  8847. }
  8848. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8849. {
  8850. //Local list different update
  8851. printf("Local list different update.\n");
  8852. OCPP_getListVerion();
  8853. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8854. {
  8855. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  8856. goto end;
  8857. }
  8858. }
  8859. else
  8860. {
  8861. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8862. goto end;
  8863. }
  8864. c = 0;
  8865. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  8866. {
  8867. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  8868. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8869. c++;
  8870. }
  8871. sstr[c] = '\0';
  8872. //DEBUG_INFO("sstr=%s\n", sstr);
  8873. //parsing strings to words
  8874. i = 0;
  8875. pch = strtok(sstr,delim1);
  8876. while (pch != NULL)
  8877. {
  8878. strcpy(CardList[i], pch);
  8879. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  8880. pch = strtok (NULL, delim1);
  8881. i = i + 1;
  8882. }
  8883. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  8884. //local Authorizations List Numbers
  8885. //n_localAuthorizations = i;
  8886. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8887. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  8888. c= 0;
  8889. while(c < i) // i is CardList Number
  8890. {
  8891. //Search "IdToken"
  8892. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8893. loc = strstr(CardList[c], "idTag");
  8894. int j = 0;
  8895. while (loc[3+strlen("idTag")+j] != '\"')
  8896. {
  8897. sstr[j] = loc[3+strlen("idTag")+j];
  8898. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8899. j++;
  8900. }
  8901. sstr[j] = '\0';
  8902. strcpy(idTagstr, sstr);
  8903. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  8904. //Search "expiryDate"
  8905. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8906. loc = strstr(CardList[c], "expiryDate");
  8907. j = 0;
  8908. if(loc != NULL)
  8909. {
  8910. while (loc[3+strlen("expiryDate")+j] != '\"')
  8911. {
  8912. sstr[j] = loc[3+strlen("expiryDate")+j];
  8913. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8914. j++;
  8915. }
  8916. sstr[j] = '\0';
  8917. strcpy(expiryDate, sstr);
  8918. }
  8919. else
  8920. {
  8921. strcpy(expiryDate, "");
  8922. }
  8923. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  8924. //Search "parentIdTag"
  8925. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8926. loc = strstr(CardList[c], "parentIdTag");
  8927. j = 0;
  8928. if(loc != NULL)
  8929. {
  8930. while (loc[3+strlen("parentIdTag")+j] != '\"')
  8931. {
  8932. sstr[j] = loc[3+strlen("parentIdTag")+j];
  8933. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8934. j++;
  8935. }
  8936. sstr[j] = '\0';
  8937. strcpy(parentIdTag, sstr);
  8938. }
  8939. else
  8940. {
  8941. strcpy(parentIdTag, "");
  8942. }
  8943. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  8944. //Search "status"
  8945. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8946. loc = strstr(CardList[c], "status");
  8947. j = 0;
  8948. while (loc[3+strlen("status")+j] != '\"')
  8949. {
  8950. sstr[j] = loc[3+strlen("status")+j];
  8951. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8952. j++;
  8953. }
  8954. sstr[j] = '\0';
  8955. strcpy(idTagstatus, sstr);
  8956. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  8957. OCPP_getIdTagFromLocalList(idTagstr);
  8958. //OCPP_getIdTagFromLocalList("test"); For Test
  8959. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  8960. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  8961. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8962. {
  8963. //Local list full update
  8964. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8965. // update list
  8966. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8967. //DEBUG_INFO("Local list full update. 1\n");
  8968. //OCPP_get_TableAuthlocalAllData();
  8969. //DEBUG_INFO("Local list full update. 2\n");
  8970. }
  8971. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8972. {
  8973. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8974. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  8975. }
  8976. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  8977. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  8978. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  8979. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  8980. c++;
  8981. }
  8982. }
  8983. else
  8984. {
  8985. //Check UpdateType
  8986. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8987. {
  8988. //Local list full update
  8989. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  8990. OCPP_cleanLocalList();
  8991. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8992. goto end;
  8993. }
  8994. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8995. {
  8996. //Local list different update
  8997. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  8998. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8999. goto end;
  9000. }
  9001. }
  9002. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9003. end:
  9004. sendSendLocalListConfirmation(uuid, comfirmstr);
  9005. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  9006. return result;
  9007. }
  9008. #define MAX 200
  9009. int handleSetChargingProfileRequest(char *uuid, char *payload)
  9010. {
  9011. mtrace();
  9012. int result = FAIL;
  9013. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  9014. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  9015. char chargingProfilePurposeStr[30]={0};
  9016. char chargingProfileKindStr[16]={0};
  9017. char recurrencyKindStr[10]={0};
  9018. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  9019. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  9020. int chargingSchedulePeriodCount = 0;
  9021. char comfirmstr[20]={0};
  9022. int meet= FALSE;
  9023. FILE *fptr1;
  9024. char filename[MAX]={0};
  9025. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  9026. char rmFileCmd[50]={0};
  9027. char tempchargingProfilePurposeStr[30]={0};
  9028. char word[1600]={0};
  9029. int n_chargingProfile = 0;
  9030. json_object *SetChargingProfile;
  9031. DEBUG_INFO("handleSetChargingProfileRequest\n");
  9032. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  9033. SetChargingProfile = json_tokener_parse(payload);
  9034. if(!is_error(SetChargingProfile))
  9035. {
  9036. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  9037. {
  9038. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  9039. if(connectorIdInt == 0)
  9040. {
  9041. memset(&ShmOCPP16Data->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  9042. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  9043. }
  9044. else
  9045. {
  9046. memset(&ShmOCPP16Data->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  9047. ShmOCPP16Data->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  9048. }
  9049. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  9050. }
  9051. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  9052. {
  9053. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  9054. {
  9055. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  9056. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9057. {
  9058. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  9059. }
  9060. else
  9061. {
  9062. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  9063. }
  9064. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  9065. }
  9066. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  9067. {
  9068. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  9069. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9070. {
  9071. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  9072. }
  9073. else
  9074. {
  9075. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  9076. }
  9077. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  9078. }
  9079. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9080. {
  9081. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  9082. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9083. {
  9084. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  9085. }
  9086. else
  9087. {
  9088. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  9089. }
  9090. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  9091. }
  9092. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  9093. {
  9094. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  9095. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9096. {
  9097. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  9098. }
  9099. else
  9100. {
  9101. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  9102. }
  9103. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  9104. }
  9105. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  9106. {
  9107. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  9108. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9109. {
  9110. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  9111. }
  9112. else
  9113. {
  9114. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  9115. }
  9116. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  9117. }
  9118. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  9119. {
  9120. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  9121. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9122. {
  9123. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9124. }
  9125. else
  9126. {
  9127. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9128. }
  9129. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  9130. }
  9131. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  9132. {
  9133. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  9134. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9135. {
  9136. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  9137. }
  9138. else
  9139. {
  9140. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  9141. }
  9142. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  9143. }
  9144. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  9145. {
  9146. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  9147. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9148. {
  9149. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  9150. }
  9151. else
  9152. {
  9153. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  9154. }
  9155. //DEBUG_INFO("validToStr: %s\n", validToStr);
  9156. }
  9157. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  9158. {
  9159. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  9160. {
  9161. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  9162. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9163. {
  9164. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9165. }
  9166. else
  9167. {
  9168. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9169. }
  9170. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  9171. }
  9172. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  9173. {
  9174. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  9175. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9176. {
  9177. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9178. }
  9179. else
  9180. {
  9181. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9182. }
  9183. //DEBUG_INFO("durationInt: %d\n", durationInt);
  9184. }
  9185. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  9186. {
  9187. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  9188. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9189. {
  9190. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9191. }
  9192. else
  9193. {
  9194. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9195. }
  9196. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  9197. }
  9198. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  9199. {
  9200. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  9201. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9202. {
  9203. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9204. }
  9205. else
  9206. {
  9207. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9208. }
  9209. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  9210. }
  9211. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9212. {
  9213. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  9214. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  9215. if(chargingSchedulePeriodCount <= 10)
  9216. {
  9217. 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++)
  9218. {
  9219. 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)
  9220. {
  9221. 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"));
  9222. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9223. {
  9224. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9225. }
  9226. else
  9227. {
  9228. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9229. }
  9230. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  9231. }
  9232. 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)
  9233. {
  9234. 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"));
  9235. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9236. {
  9237. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9238. }
  9239. else
  9240. {
  9241. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9242. }
  9243. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  9244. }
  9245. 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)
  9246. {
  9247. 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"));
  9248. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9249. {
  9250. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9251. }
  9252. else
  9253. {
  9254. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9255. }
  9256. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  9257. }
  9258. }
  9259. }
  9260. }
  9261. }
  9262. }
  9263. }
  9264. json_object_put(SetChargingProfile);
  9265. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  9266. {
  9267. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9268. goto end;
  9269. }
  9270. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  9271. {
  9272. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  9273. if(connectorIdInt != 0)
  9274. {
  9275. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9276. goto end;
  9277. }
  9278. strcpy(filename, ChargePointMaxProfile_JSON );
  9279. fptr1 = fopen(filename, "r");
  9280. if (!fptr1)
  9281. {
  9282. //file not exist
  9283. DEBUG_INFO("Unable to open the input file!!\n");
  9284. fptr1 = fopen(filename, "w+");
  9285. }
  9286. else
  9287. {
  9288. //Check Charging Profile Count
  9289. while(fscanf(fptr1, "%s", word) != EOF)
  9290. {
  9291. //DEBUG_INFO("word=%s\n",word);
  9292. if(strstr(word, "chargingProfileId")!= NULL)
  9293. {
  9294. //DEBUG_INFO("test chargingProfileId \n");
  9295. n_chargingProfile = n_chargingProfile + 1;
  9296. //DEBUG_INFO("chargingProfileId Found\n");
  9297. }
  9298. }
  9299. }
  9300. fclose(fptr1);
  9301. }
  9302. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  9303. {
  9304. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  9305. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9306. {
  9307. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9308. goto end;
  9309. }
  9310. memset(filename, 0, ARRAY_SIZE(filename));
  9311. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9312. fptr1 = fopen(filename, "r");
  9313. if (!fptr1)
  9314. {
  9315. //file not exist
  9316. //DEBUG_INFO("Unable to open the input file!!\n");
  9317. fptr1 = fopen(filename, "w+");
  9318. }
  9319. else
  9320. {
  9321. //Check Charging Profile Count
  9322. while(fscanf(fptr1, "%s", word) != EOF)
  9323. {
  9324. //DEBUG_INFO("word=%s\n",word);
  9325. if(strstr(word, "chargingProfileId")!= NULL)
  9326. {
  9327. //DEBUG_INFO("test chargingProfileId \n");
  9328. n_chargingProfile = n_chargingProfile + 1;
  9329. //DEBUG_INFO("chargingProfileId Found\n");
  9330. }
  9331. }
  9332. }
  9333. fclose(fptr1);
  9334. }
  9335. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9336. {
  9337. //printf("set chargingProfile 1-4\n");
  9338. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  9339. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  9340. if(connectorIdInt == 0)
  9341. {
  9342. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9343. goto end;
  9344. }
  9345. int tempIndex = 0;
  9346. //check Transaction active
  9347. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9348. {
  9349. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9350. {
  9351. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9352. }
  9353. else
  9354. {
  9355. tempIndex = connectorIdInt -1;
  9356. }
  9357. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9358. {
  9359. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9360. {
  9361. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9362. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9363. {
  9364. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9365. {
  9366. meet = TRUE;
  9367. break;
  9368. }
  9369. }
  9370. }
  9371. }
  9372. }
  9373. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9374. {
  9375. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9376. {
  9377. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9378. }
  9379. else
  9380. {
  9381. tempIndex = connectorIdInt -1;
  9382. }
  9383. for (int index = 0; index < CCS_QUANTITY; index++)
  9384. {
  9385. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9386. {
  9387. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9388. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9389. {
  9390. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9391. {
  9392. meet = TRUE;
  9393. break;
  9394. }
  9395. }
  9396. }
  9397. }
  9398. }
  9399. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9400. {
  9401. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9402. {
  9403. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9404. }
  9405. else
  9406. {
  9407. tempIndex = connectorIdInt -1;
  9408. }
  9409. for (int index = 0; index < GB_QUANTITY; index++)
  9410. {
  9411. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9412. {
  9413. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9414. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9415. {
  9416. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9417. {
  9418. meet = TRUE;
  9419. break;
  9420. }
  9421. }
  9422. }
  9423. }
  9424. }
  9425. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9426. {
  9427. tempIndex = connectorIdInt -1;
  9428. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9429. {
  9430. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9431. {
  9432. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  9433. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9434. {
  9435. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9436. {
  9437. meet = TRUE;
  9438. break;
  9439. }
  9440. }
  9441. }
  9442. }
  9443. }
  9444. else
  9445. {
  9446. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9447. {
  9448. tempIndex = 2;
  9449. }
  9450. else
  9451. {
  9452. tempIndex = (connectorIdInt -1);
  9453. }
  9454. for (int index = 0; index < AC_QUANTITY; index++)
  9455. {
  9456. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9457. {
  9458. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9459. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9460. {
  9461. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9462. {
  9463. meet = TRUE;
  9464. break;
  9465. }
  9466. }
  9467. }
  9468. }
  9469. }
  9470. //check Transaction active
  9471. if(meet == FALSE)
  9472. {
  9473. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9474. goto end;
  9475. }
  9476. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9477. {
  9478. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9479. goto end;
  9480. }
  9481. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9482. fptr1 = fopen(filename, "r");
  9483. if (!fptr1)
  9484. {
  9485. //file not exist
  9486. DEBUG_INFO("Unable to open the input file!!\n");
  9487. fptr1 = fopen(filename, "w+");
  9488. }
  9489. else
  9490. {
  9491. //Check Charging Profile Count
  9492. while(fscanf(fptr1, "%s", word) != EOF)
  9493. {
  9494. //DEBUG_INFO("word=%s\n",word);
  9495. if(strstr(word, "chargingProfileId")!= NULL)
  9496. {
  9497. //DEBUG_INFO("test chargingProfileId \n");
  9498. n_chargingProfile = n_chargingProfile + 1;
  9499. //DEBUG_INFO("chargingProfileId Found\n");
  9500. }
  9501. }
  9502. }
  9503. fclose(fptr1);
  9504. }
  9505. // Check ChargeProfileMaxStackLevel
  9506. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  9507. {
  9508. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9509. goto end;
  9510. }
  9511. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9512. {
  9513. int i = 0;
  9514. char fnametemp[200]={0};
  9515. n_chargingProfile = 0;
  9516. //Check ChargePointMaxProfile.json exit
  9517. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9518. {
  9519. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  9520. //Check Charging Profile Count
  9521. while(fscanf(fptr1, "%s", word) != EOF)
  9522. {
  9523. //DEBUG_INFO("word=%s\n",word);
  9524. if(strstr(word, "chargingProfileId")!= NULL)
  9525. {
  9526. //DEBUG_INFO("test chargingProfileId \n");
  9527. n_chargingProfile = n_chargingProfile + 1;
  9528. i = i + 1;
  9529. //DEBUG_INFO("chargingProfileId Found\n");
  9530. }
  9531. memset(word, 0, ARRAY_SIZE(word));
  9532. }
  9533. fclose(fptr1);
  9534. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  9535. }
  9536. //Check TxDefaultProfile_0.json exit
  9537. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9538. {
  9539. i = 0;
  9540. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  9541. //Check Charging Profile Count
  9542. while(fscanf(fptr1, "%s", word) != EOF)
  9543. {
  9544. //DEBUG_INFO("word=%s\n",word);
  9545. if(strstr(word, "chargingProfileId")!= NULL)
  9546. {
  9547. //DEBUG_INFO("test chargingProfileId \n");
  9548. n_chargingProfile = n_chargingProfile + 1;
  9549. i = i + 1;
  9550. //DEBUG_INFO("chargingProfileId Found\n");
  9551. }
  9552. memset(word, 0, ARRAY_SIZE(word));
  9553. }
  9554. fclose(fptr1);
  9555. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  9556. }
  9557. //Check TxDefaultProfile_%d.json
  9558. for(int j=1; j <= gunTotalNumber; j++)
  9559. {
  9560. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9561. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9562. if((access(fnametemp,F_OK))!=-1)
  9563. {
  9564. i = 0;
  9565. fptr1 = fopen(fnametemp, "r");
  9566. //Check Charging Profile Count
  9567. while(fscanf(fptr1, "%s", word) != EOF)
  9568. {
  9569. //DEBUG_INFO("word=%s\n",word);
  9570. if(strstr(word, "chargingProfileId")!= NULL)
  9571. {
  9572. //DEBUG_INFO("test chargingProfileId \n");
  9573. n_chargingProfile = n_chargingProfile + 1;
  9574. i = i + 1;
  9575. //DEBUG_INFO("chargingProfileId Found\n");
  9576. }
  9577. memset(word, 0, ARRAY_SIZE(word));
  9578. }
  9579. fclose(fptr1);
  9580. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9581. }
  9582. }
  9583. //Check TxProfile_%d.json
  9584. for(int j=1; j <= gunTotalNumber; j++)
  9585. {
  9586. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9587. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9588. if((access(fnametemp,F_OK))!=-1)
  9589. {
  9590. i = 0;
  9591. fptr1 = fopen(fnametemp, "r");
  9592. //Check Charging Profile Count
  9593. while(fscanf(fptr1, "%s", word) != EOF)
  9594. {
  9595. //DEBUG_INFO("word=%s\n",word);
  9596. if(strstr(word, "chargingProfileId")!= NULL)
  9597. {
  9598. //DEBUG_INFO("test chargingProfileId \n");
  9599. n_chargingProfile = n_chargingProfile + 1;
  9600. i = i + 1;
  9601. //DEBUG_INFO("chargingProfileId Found\n");
  9602. }
  9603. memset(word, 0, ARRAY_SIZE(word));
  9604. }
  9605. fclose(fptr1);
  9606. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9607. }
  9608. }
  9609. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  9610. {
  9611. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9612. goto end;
  9613. }
  9614. }
  9615. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9616. //**********************************Write to File********************************************************/
  9617. FILE *infile;
  9618. FILE *outfile;
  9619. infile = fopen (filename, "r");
  9620. outfile = fopen (tempfile, "w");
  9621. int d =0;
  9622. d = fgetc(infile);
  9623. rewind(infile);
  9624. if(d == EOF)
  9625. {
  9626. // Profile is empty
  9627. fprintf(outfile,"%s\n",payload);
  9628. fclose(infile);
  9629. fclose(outfile);
  9630. sprintf(rmFileCmd,"rm -f %s",filename);
  9631. system(rmFileCmd);
  9632. rename(tempfile, filename);
  9633. }
  9634. else
  9635. {
  9636. // Profile is not empty
  9637. char buf[2048]={0};
  9638. int ChargingProfileAdded = FALSE;
  9639. while (fgets(buf, sizeof(buf), infile) != NULL)
  9640. {
  9641. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9642. json_object *tmpChargingProfile;
  9643. tmpChargingProfile = json_tokener_parse(buf);
  9644. if(!is_error(SetChargingProfile))
  9645. {
  9646. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  9647. {
  9648. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  9649. }
  9650. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  9651. {
  9652. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  9653. {
  9654. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  9655. }
  9656. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  9657. {
  9658. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  9659. }
  9660. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9661. {
  9662. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  9663. }
  9664. }
  9665. }
  9666. json_object_put(tmpChargingProfile);
  9667. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  9668. {
  9669. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9670. {
  9671. //DEBUG_INFO("update set chargingProfile to file -0\n");
  9672. if(ChargingProfileAdded == FALSE)
  9673. {
  9674. fprintf(outfile,"%s\n",payload);
  9675. ChargingProfileAdded = TRUE;
  9676. }
  9677. }
  9678. else
  9679. {
  9680. if(tempstackLevelInt < stackLevelInt)
  9681. {
  9682. if(ChargingProfileAdded == FALSE)
  9683. {
  9684. fprintf(outfile,"%s\n",buf);
  9685. fprintf(outfile,"%s\n",payload);
  9686. ChargingProfileAdded = TRUE;
  9687. }
  9688. else
  9689. {
  9690. fprintf(outfile,"%s\n",buf);
  9691. }
  9692. }
  9693. else
  9694. {
  9695. if(ChargingProfileAdded == FALSE)
  9696. {
  9697. fprintf(outfile,"%s\n",buf);
  9698. fprintf(outfile,"%s\n",payload);
  9699. ChargingProfileAdded = TRUE;
  9700. }
  9701. else
  9702. {
  9703. fprintf(outfile,"%s\n",buf);
  9704. }
  9705. }
  9706. }
  9707. }
  9708. else
  9709. {
  9710. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9711. {
  9712. if(ChargingProfileAdded == FALSE)
  9713. {
  9714. fprintf(outfile,"%s\n",buf);
  9715. fprintf(outfile,"%s\n",payload);
  9716. ChargingProfileAdded = TRUE;
  9717. }
  9718. else
  9719. {
  9720. fprintf(outfile,"%s\n",buf);
  9721. }
  9722. }
  9723. else if(tempstackLevelInt < stackLevelInt)
  9724. {
  9725. if(ChargingProfileAdded == FALSE)
  9726. {
  9727. fprintf(outfile,"%s\n",buf);
  9728. fprintf(outfile,"%s\n",payload);
  9729. ChargingProfileAdded = TRUE;
  9730. }
  9731. else
  9732. {
  9733. fprintf(outfile,"%s\n",buf);
  9734. }
  9735. }
  9736. else
  9737. {
  9738. if(ChargingProfileAdded == FALSE)
  9739. {
  9740. fprintf(outfile,"%s\n",buf);
  9741. fprintf(outfile,"%s\n",payload);
  9742. ChargingProfileAdded = TRUE;
  9743. }
  9744. else
  9745. {
  9746. fprintf(outfile,"%s\n",buf);
  9747. }
  9748. }
  9749. }
  9750. } // end of while loop
  9751. fclose(infile);
  9752. fclose(outfile);
  9753. sprintf(rmFileCmd,"rm -f %s",filename);
  9754. system(rmFileCmd);
  9755. rename(tempfile, filename);
  9756. }
  9757. sleep(1);
  9758. result = TRUE;
  9759. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9760. end:
  9761. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  9762. {
  9763. if(connectorIdInt == 0)
  9764. {
  9765. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9766. {
  9767. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  9768. }
  9769. }
  9770. else
  9771. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  9772. }
  9773. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  9774. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9775. return result;
  9776. }
  9777. int handleTriggerMessageRequest(char *uuid, char *payload)
  9778. {
  9779. mtrace();
  9780. int result = FAIL;
  9781. int connectorIdIsNULL = FALSE;
  9782. int connectorIdInt =0;
  9783. char sstr[40]={0},sstrtemp[100]={ 0 };
  9784. char requestedMessagestr[40]={0};
  9785. char comfirmstr[20]={0};
  9786. int c = 0;
  9787. char *loc;
  9788. DEBUG_INFO("handleTriggerMessageRequest\n");
  9789. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  9790. strcpy(sstrtemp, stringtrimspace(payload));
  9791. c = 0;
  9792. loc = strstr(sstrtemp, "requestedMessage");
  9793. while (loc[3+strlen("requestedMessage")+c] != '\"')
  9794. {
  9795. sstr[c] = loc[3+strlen("requestedMessage")+c];
  9796. c++;
  9797. }
  9798. sstr[c] = '\0';
  9799. strcpy(requestedMessagestr, sstr);
  9800. c = 0;
  9801. loc = strstr(sstrtemp, "connectorId");
  9802. if(loc == NULL)
  9803. {
  9804. connectorIdIsNULL = TRUE;
  9805. }
  9806. else
  9807. {
  9808. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9809. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  9810. {
  9811. sstr[c] = loc[strlen("connectorId")+2+c];
  9812. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9813. c++;
  9814. }
  9815. sstr[c] = '\0';
  9816. connectorIdInt = atoi(sstr);
  9817. }
  9818. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  9819. {
  9820. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  9821. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  9822. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  9823. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  9824. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  9825. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  9826. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  9827. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  9828. {
  9829. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  9830. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9831. return TRUE;
  9832. }
  9833. else
  9834. {
  9835. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9836. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9837. }
  9838. }
  9839. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  9840. {
  9841. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  9842. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9843. return TRUE;
  9844. }
  9845. //==========================
  9846. // Trigger message
  9847. //==========================
  9848. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  9849. {
  9850. if((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) &&
  9851. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) &&
  9852. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) &&
  9853. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING) )
  9854. {
  9855. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  9856. }
  9857. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  9858. }
  9859. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  9860. {
  9861. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  9862. }
  9863. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  9864. {
  9865. //sendBootNotificationRequest();
  9866. server_sign = FALSE;
  9867. }
  9868. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  9869. {
  9870. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  9871. }
  9872. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  9873. {
  9874. if(connectorIdIsNULL == FALSE)
  9875. {
  9876. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9877. {
  9878. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  9879. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  9880. }
  9881. }
  9882. else
  9883. {
  9884. for(int idx=0;idx< gunTotalNumber;idx++)
  9885. {
  9886. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  9887. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  9888. }
  9889. }
  9890. }
  9891. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  9892. {
  9893. if(connectorIdIsNULL == FALSE)
  9894. {
  9895. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9896. {
  9897. cpinitateMsg.bits[connectorIdInt -1].StatusNotificationReq = 1;
  9898. }
  9899. }
  9900. else
  9901. {
  9902. for(int idx=0;idx< gunTotalNumber;idx++)
  9903. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  9904. }
  9905. }
  9906. return result;
  9907. }
  9908. int handleUnlockConnectorRequest(char *uuid, char *payload)
  9909. {
  9910. mtrace();
  9911. int result = FAIL;
  9912. int connectorIdInt =0;
  9913. char comfirmstr[20]={0};
  9914. int tempIndex = 0;
  9915. json_object *UnlockConnector;
  9916. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  9917. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  9918. UnlockConnector = json_tokener_parse(payload);
  9919. if(!is_error(UnlockConnector))
  9920. {
  9921. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  9922. {
  9923. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  9924. }
  9925. }
  9926. json_object_put(UnlockConnector);
  9927. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  9928. if(gunTotalNumber == 0)
  9929. {
  9930. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9931. goto end;
  9932. }
  9933. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  9934. {
  9935. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9936. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9937. goto end;
  9938. }
  9939. else
  9940. {
  9941. //check Transaction active
  9942. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  9943. {
  9944. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9945. {
  9946. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9947. }
  9948. else
  9949. {
  9950. tempIndex = connectorIdInt -1;
  9951. }
  9952. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9953. {
  9954. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9955. {
  9956. //stop Transaction
  9957. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9958. }
  9959. }
  9960. }
  9961. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  9962. {
  9963. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9964. {
  9965. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9966. }
  9967. else
  9968. {
  9969. tempIndex = connectorIdInt -1;
  9970. }
  9971. for (int index = 0; index < CCS_QUANTITY; index++)
  9972. {
  9973. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9974. {
  9975. //stop Transaction
  9976. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9977. }
  9978. }
  9979. }
  9980. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  9981. {
  9982. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9983. {
  9984. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9985. }
  9986. else
  9987. {
  9988. tempIndex = connectorIdInt -1;
  9989. }
  9990. for (int index = 0; index < GB_QUANTITY; index++)
  9991. {
  9992. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  9993. {
  9994. //stop Transaction
  9995. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9996. }
  9997. }
  9998. }
  9999. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  10000. {
  10001. tempIndex = connectorIdInt -1;
  10002. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10003. {
  10004. 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)))
  10005. {
  10006. //stop Transaction
  10007. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10008. }
  10009. }
  10010. }
  10011. else
  10012. {
  10013. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10014. {
  10015. tempIndex = 2;
  10016. }
  10017. else
  10018. {
  10019. tempIndex = connectorIdInt-1;
  10020. }
  10021. for (int index = 0; index < AC_QUANTITY; index++)
  10022. {
  10023. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10024. {
  10025. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10026. }
  10027. }
  10028. }
  10029. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  10030. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  10031. result = TRUE;
  10032. return result;
  10033. }
  10034. end:
  10035. //json_object_put(obj); --- remove temporally
  10036. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  10037. return result;
  10038. }
  10039. static char UpdateFirmwarepayloadData[300]={0};
  10040. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  10041. {
  10042. mtrace();
  10043. int result = FAIL;
  10044. pthread_t t;
  10045. sendUpdateFirmwareConfirmation(uuid);
  10046. memset(UpdateFirmwarepayloadData, 0, 300);
  10047. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  10048. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  10049. ////pthread_join(t, NULL); //
  10050. //pthread_detach(t);
  10051. //sendUpdateFirmwareConfirmation(uuid);
  10052. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  10053. return result;
  10054. }
  10055. void *UpdateFirmwareProcess(void *data)
  10056. {
  10057. pthread_detach(pthread_self());
  10058. mtrace();
  10059. int retriesInt =0, retryIntervalInt=0;
  10060. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  10061. int port=0;
  10062. char locationstr[160]={0}, retrieveDatestr[30]={0};
  10063. int isSuccess = 0;
  10064. char ftpbuf[200];
  10065. char temp[100];
  10066. char * pch;
  10067. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  10068. json_object *UpdateFirmware;
  10069. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  10070. if(!is_error(UpdateFirmware))
  10071. {
  10072. // Required data
  10073. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  10074. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  10075. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  10076. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  10077. // Optional data
  10078. if(json_object_object_get(UpdateFirmware, "retries"))
  10079. {
  10080. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  10081. }
  10082. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  10083. {
  10084. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  10085. }
  10086. }
  10087. json_object_put(UpdateFirmware);
  10088. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10089. memset(path, 0, ARRAY_SIZE(path));
  10090. system("rm -f /mnt/*");
  10091. if(strncmp(locationstr,"http", 4) == 0)
  10092. {
  10093. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10094. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  10095. // protocol, user, password, host, path);
  10096. sprintf(ftppath,"/%s", path);
  10097. DEBUG_INFO("locationstr: %s\n", locationstr);
  10098. DEBUG_INFO("protocol: %s\n",protocol);
  10099. DEBUG_INFO("host: %s\n",host);
  10100. DEBUG_INFO("path: %s\n",path);
  10101. DEBUG_INFO("ftppath: %s\n",ftppath);
  10102. int ftppathlen=strlen(ftppath);
  10103. int i=1;
  10104. char filenametemp[50];
  10105. while(i < ftppathlen)
  10106. {
  10107. int len=ftppathlen-i;
  10108. if(ftppath[len]== 47) // '/' ascll code: 47
  10109. {
  10110. DEBUG_INFO("compare '/' all right\n");
  10111. break;
  10112. }
  10113. i=i+1;
  10114. }
  10115. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10116. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10117. filenametemp[i+1] = 0;
  10118. do
  10119. {
  10120. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  10121. sleep(3);
  10122. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  10123. if(!isSuccess)
  10124. {
  10125. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10126. sleep(retryIntervalInt);
  10127. }
  10128. else
  10129. {
  10130. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10131. }
  10132. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  10133. }
  10134. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  10135. {
  10136. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  10137. memset(temp, 0, ARRAY_SIZE(temp));
  10138. //DEBUG_INFO("locationstr=%s\n",locationstr);
  10139. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  10140. int ftppathlen=strlen(ftpbuf);
  10141. int i=1;
  10142. char filenametemp[50];
  10143. while(i < ftppathlen)
  10144. {
  10145. int len=ftppathlen-i;
  10146. if(ftpbuf[len]== 47) // '/' ascll code: 47
  10147. {
  10148. DEBUG_INFO(" compare '/' all right\n");
  10149. break;
  10150. }
  10151. i=i+1;
  10152. }
  10153. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10154. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  10155. filenametemp[i+1] = 0;
  10156. strncpy(temp, ftpbuf, ftppathlen-i+1);
  10157. pch=strchr(temp,'@');
  10158. if(pch==NULL)
  10159. {
  10160. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10161. protocol, host, &port, path);
  10162. strcpy(user,"anonymous");
  10163. strcpy(password,"");
  10164. }
  10165. else
  10166. {
  10167. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10168. protocol, user, password, host, &port, path);
  10169. }
  10170. sscanf(host,"%[^/]%s",host1, path1);
  10171. sprintf(ftppath,"%s", path1);
  10172. //DEBUG_INFO("protocol =%s\n",protocol);
  10173. //DEBUG_INFO("user =%s\n",user);
  10174. //DEBUG_INFO("password =%s\n",password);
  10175. //DEBUG_INFO("host1 =%s\n",host1);
  10176. //DEBUG_INFO("port =%d\n",port);
  10177. //DEBUG_INFO("path1 =%s\n",path1);
  10178. //DEBUG_INFO("ftppath=%s\n",ftppath);
  10179. //ftpFile(host, user, password, port, ftppath, fname);
  10180. //download firmware pthred
  10181. if(port == 0)
  10182. {
  10183. port = 21;
  10184. }
  10185. do
  10186. {
  10187. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  10188. sleep(3);
  10189. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  10190. if(!isSuccess)
  10191. {
  10192. //BulldogUtil.sleepMs(interval*1000);
  10193. DEBUG_INFO("Update firmware request and download file fail.\n");
  10194. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10195. sleep(retryIntervalInt);
  10196. }
  10197. else
  10198. {
  10199. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10200. }
  10201. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  10202. }
  10203. else
  10204. {
  10205. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10206. }
  10207. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  10208. pthread_exit(NULL);
  10209. }
  10210. int handleUnknownRequest(char *uuid, char *payload)
  10211. {
  10212. mtrace();
  10213. int result = FAIL;
  10214. DEBUG_INFO("handleUnknownRequest...\n");
  10215. sendUnknownConfirmation(uuid);
  10216. result = PASS;
  10217. return result;
  10218. }
  10219. //==========================================
  10220. // Handle server response routine
  10221. //==========================================
  10222. void handleAuthorizeResponse(char *payload, int gun_index)
  10223. {
  10224. mtrace();
  10225. char expiryDatestr[30]={0};
  10226. char parentIdTagstr[20]={0};
  10227. char statusstr[20]={0};
  10228. int expiryDateISNULL=FALSE;
  10229. int parentIdTagISNULL=FALSE;
  10230. DEBUG_INFO("handleAuthorizeResponse...\n");
  10231. json_object *Authorize;
  10232. Authorize = json_tokener_parse(payload);
  10233. if(!is_error(Authorize))
  10234. {
  10235. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  10236. {
  10237. // Required data
  10238. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  10239. // Optional data
  10240. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  10241. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  10242. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  10243. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  10244. }
  10245. }
  10246. json_object_put(Authorize);
  10247. if(expiryDateISNULL == FALSE)
  10248. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  10249. if(parentIdTagISNULL == FALSE)
  10250. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  10251. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  10252. //Update idTag information to authorization cache if supproted
  10253. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  10254. {
  10255. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  10256. }
  10257. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  10258. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  10259. authorizeRetryTimes = 0;
  10260. }
  10261. void handleBootNotificationResponse(char *payload, int gun_index)
  10262. {
  10263. mtrace();
  10264. char statusStr[12]={0};
  10265. char currentTimeStr[30]={0};
  10266. int intervalInt = 0;
  10267. DEBUG_INFO("handleBootNotificationResponse...\n");
  10268. json_object *BootNotification;
  10269. BootNotification = json_tokener_parse(payload);
  10270. if(!is_error(BootNotification))
  10271. {
  10272. // Required data
  10273. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  10274. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  10275. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  10276. }
  10277. json_object_put(BootNotification);
  10278. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10279. BootNotificationInterval = intervalInt;
  10280. HeartBeatWaitTime = intervalInt;
  10281. //write back to ShmOCPP16Data->BootNotification
  10282. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  10283. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10284. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  10285. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  10286. {
  10287. server_sign = TRUE;
  10288. server_pending =FALSE;
  10289. }
  10290. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  10291. {
  10292. server_pending = TRUE;
  10293. }
  10294. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  10295. srand(time(NULL));
  10296. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  10297. SetOcppConnStatus(TRUE);
  10298. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  10299. }
  10300. void handleDataTransferResponse(char *payload, int gun_index)
  10301. {
  10302. char sstr[160]={0};//sstr[200]={ 0 };
  10303. int c = 0;
  10304. char *loc;
  10305. DEBUG_INFO("handleDataTransferResponse ...\n");
  10306. loc = strstr(payload, "status");
  10307. printf("loc=%s\n",loc);
  10308. c = 0;
  10309. while (loc[3+strlen("status")+c] != '\"')
  10310. {
  10311. sstr[c] = loc[3+strlen("status")+c];
  10312. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10313. c++;
  10314. }
  10315. sstr[c] = '\0';
  10316. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  10317. }
  10318. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  10319. {
  10320. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  10321. //struct json_object *obj;
  10322. // obj = json_tokener_parse(payload);
  10323. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  10324. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  10325. //No fields are defined.
  10326. }
  10327. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  10328. {
  10329. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  10330. //struct json_object *obj;
  10331. // obj = json_tokener_parse(payload);
  10332. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  10333. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  10334. //No fields are defined.
  10335. }
  10336. void handleHeartbeatResponse(char *payload, int gun_index)
  10337. {
  10338. mtrace();
  10339. DEBUG_INFO("handleHeartbeatResponse...\n");
  10340. json_object *Heartbeat;
  10341. Heartbeat = json_tokener_parse(payload);
  10342. if(!is_error(Heartbeat))
  10343. {
  10344. // Required data
  10345. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  10346. }
  10347. json_object_put(Heartbeat);
  10348. if(FirstHeartBeat == 0)
  10349. {
  10350. FirstHeartBeat = 1;
  10351. DEBUG_INFO("FirstHeartBeat \n");
  10352. }
  10353. HeartBeatWithNOResponse = 0;
  10354. clientTime.Heartbeat=time((time_t*)NULL);
  10355. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  10356. }
  10357. void handleMeterValuesResponse(char *payload, int gun_index)
  10358. {
  10359. mtrace();
  10360. DEBUG_INFO("handleMeterValuesResponse...\n");
  10361. }
  10362. void handleStartTransactionResponse(char *payload, int gun_index)
  10363. {
  10364. mtrace();
  10365. //int transactionIdInt = 0;
  10366. FILE *outfile;
  10367. char data[100]={0};
  10368. DEBUG_INFO("handleStartTransactionResponse...\n");
  10369. json_object *StartTransaction;
  10370. StartTransaction = json_tokener_parse(payload);
  10371. if(!is_error(StartTransaction))
  10372. {
  10373. // Required data
  10374. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  10375. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  10376. // Optional data
  10377. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  10378. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  10379. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  10380. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  10381. }
  10382. json_object_put(StartTransaction);
  10383. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  10384. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  10385. //-----------Start : write to the Queue TransactionId file -----------------//
  10386. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  10387. {}
  10388. else
  10389. {
  10390. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  10391. if(log == NULL)
  10392. {
  10393. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  10394. return ;
  10395. }
  10396. else
  10397. {
  10398. fclose(log);
  10399. }
  10400. }
  10401. // open file for writing
  10402. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  10403. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  10404. {
  10405. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  10406. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  10407. fputs(data, outfile);
  10408. fclose (outfile);
  10409. }
  10410. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10411. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10412. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  10413. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  10414. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10415. }
  10416. void handleStatusNotificationResponse(char *payload, int gun_index)
  10417. {
  10418. mtrace();
  10419. DEBUG_INFO("handleStatusNotificationResponse...\n");
  10420. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  10421. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  10422. }
  10423. void handleStopTransactionnResponse(char *payload, int gun_index)
  10424. {
  10425. mtrace();
  10426. DEBUG_INFO("handleStopTransactionnResponse...\n");
  10427. json_object *StopTransaction;
  10428. StopTransaction = json_tokener_parse(payload);
  10429. if(!is_error(StopTransaction))
  10430. {
  10431. // Optional data
  10432. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  10433. {
  10434. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  10435. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  10436. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  10437. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  10438. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  10439. }
  10440. }
  10441. json_object_put(StopTransaction);
  10442. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  10443. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  10444. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10445. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10446. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  10447. }
  10448. //==========================================
  10449. // Handle Error routine
  10450. //==========================================
  10451. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  10452. {
  10453. mtrace();
  10454. #ifdef SystemLogMessage
  10455. DEBUG_INFO("errorCode: %s\n", errorCode);
  10456. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  10457. DEBUG_INFO("errorDetails: %s\n", payload);
  10458. #endif
  10459. }
  10460. //===============================================
  10461. // Common routine
  10462. //===============================================
  10463. int initialConfigurationTable(void)
  10464. {
  10465. //clock_t start_t, end_t, total_t;
  10466. FILE *fp;
  10467. FILE *outfile;
  10468. char str[512]={0};
  10469. char sstr[256]={0};
  10470. int c = 0;
  10471. char *loc;
  10472. int confVersion = 1;
  10473. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  10474. //start_t = clock();
  10475. //printf("Starting of the program, start_t = %ld\n", start_t);
  10476. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  10477. // Check configuration file size is correct
  10478. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  10479. {
  10480. struct stat st;
  10481. stat("/Storage/OCPP/OCPPConfiguration", &st);
  10482. if(st.st_size < 3100)
  10483. {
  10484. system("rm -f /Storage/OCPP/OCPPConfiguration");
  10485. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  10486. }
  10487. }
  10488. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  10489. {
  10490. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10491. if(outfile == NULL)
  10492. {
  10493. DEBUG_INFO("Error opening file\n");
  10494. return FALSE;
  10495. }
  10496. /*Core Profile*/
  10497. //AllowOfflineTxForUnknownId
  10498. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10499. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10500. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  10501. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10502. //AuthorizationCacheEnabled
  10503. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10504. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10505. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10506. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10507. //AuthorizeRemoteTxRequests
  10508. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10509. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10510. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  10511. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10512. //BlinkRepeat
  10513. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10514. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10515. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10516. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10517. //ClockAlignedDataInterval
  10518. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10519. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10520. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10521. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10522. //ConnectionTimeOut
  10523. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10524. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10525. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10526. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10527. //GetConfigurationMaxKeys
  10528. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10529. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10530. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  10531. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10532. // HeartbeatInterval
  10533. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10534. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10535. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  10536. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10537. // LightIntensity
  10538. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10539. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10540. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10541. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10542. // LocalAuthorizeOffline
  10543. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  10544. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10545. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10546. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10547. // LocalPreAuthorize
  10548. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10549. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10550. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10551. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10552. // MaxEnergyOnInvalidId
  10553. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10554. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10555. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10556. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10557. // MeterValuesAlignedData
  10558. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10559. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10560. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10561. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10562. else
  10563. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10564. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10565. // MeterValuesAlignedDataMaxLength
  10566. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10567. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10568. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10569. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  10570. else
  10571. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "9" );
  10572. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10573. // MeterValuesSampledData
  10574. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10575. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10576. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10577. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10578. else
  10579. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10580. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10581. // MeterValuesSampledDataMaxLength
  10582. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10583. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10584. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10585. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  10586. else
  10587. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "9" );
  10588. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10589. // MeterValueSampleInterval
  10590. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10591. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10592. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  10593. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10594. // MinimumStatusDuration
  10595. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10596. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10597. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  10598. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  10599. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10600. // NumberOfConnectors
  10601. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10602. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10603. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10604. {
  10605. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10606. }
  10607. else
  10608. {
  10609. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10610. }
  10611. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10612. // ResetRetries
  10613. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10614. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10615. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10616. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10617. // ConnectorPhaseRotation
  10618. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10619. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10620. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10621. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10622. // ConnectorPhaseRotationMaxLength
  10623. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10624. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10625. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10626. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10627. // StopTransactionOnEVSideDisconnect
  10628. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10629. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10630. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10631. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10632. // StopTransactionOnInvalidId
  10633. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  10634. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10635. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10636. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10637. // StopTxnAlignedData
  10638. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  10639. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10640. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10641. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10642. // StopTxnAlignedDataMaxLength
  10643. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10644. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10645. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10646. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10647. // StopTxnSampledData
  10648. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10649. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10650. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10651. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10652. else
  10653. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10654. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10655. // StopTxnSampledDataMaxLength
  10656. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10657. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10658. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10659. {
  10660. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  10661. }
  10662. else
  10663. {
  10664. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  10665. }
  10666. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10667. // SupportedFeatureProfiles
  10668. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10669. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10670. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10671. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10672. // SupportedFeatureProfilesMaxLength
  10673. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10674. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10675. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10676. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10677. // TransactionMessageAttempts
  10678. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10679. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10680. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10681. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10682. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10683. // TransactionMessageRetryInterval
  10684. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10685. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10686. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10687. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10688. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10689. // UnlockConnectorOnEVSideDisconnect
  10690. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10691. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10692. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10693. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10694. // WebSocketPingInterval
  10695. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10696. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10697. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10698. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10699. // QueueOffLineStartTransactionMessage
  10700. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  10701. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10702. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10703. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10704. // AuthorizationKey
  10705. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  10706. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  10707. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "" );
  10708. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  10709. // SecurityProfile
  10710. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  10711. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  10712. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "0" );
  10713. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  10714. // DefaultPrice
  10715. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  10716. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  10717. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  10718. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  10719. // CustomDisplayCostAndPrice
  10720. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  10721. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  10722. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  10723. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  10724. // CustomIdleFeeAfterStop
  10725. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  10726. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  10727. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  10728. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  10729. // Configuration Version
  10730. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  10731. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  10732. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  10733. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  10734. //* Local Auth List Management Profile*/
  10735. #if 0
  10736. //For OCTT Test Case
  10737. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10738. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  10739. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10740. #endif
  10741. #if 1
  10742. //LocalAuthListEnabled
  10743. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10744. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10745. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10746. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10747. #endif
  10748. //LocalAuthListMaxLength
  10749. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10750. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10751. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10752. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10753. //SendLocalListMaxLength
  10754. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10755. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10756. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  10757. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10758. //ReserveConnectorZeroSupported
  10759. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10760. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10761. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10762. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10763. //* Smart Charging Profile */
  10764. //ChargeProfileMaxStackLevel
  10765. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10766. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10767. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10768. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10769. // ChargingScheduleAllowedChargingRateUnit
  10770. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10771. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10772. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10773. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10774. // ChargingScheduleMaxPeriods
  10775. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10776. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10777. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10778. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10779. // ConnectorSwitch3to1PhaseSupported
  10780. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10781. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10782. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10783. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10784. // MaxChargingProfilesInstalled
  10785. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10786. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10787. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  10788. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10789. fclose(outfile);
  10790. }
  10791. else
  10792. {
  10793. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10794. char keystr[60]={0};
  10795. char readonlystr[10]={0};
  10796. char valuestr[256]={0};
  10797. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10798. if(fp == NULL) {
  10799. DEBUG_INFO("Error opening file");
  10800. return FALSE;
  10801. }
  10802. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  10803. {
  10804. //DEBUG_INFO("Get Configuration \n");
  10805. if(strlen(str) > 0)
  10806. {
  10807. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10808. //*************************key*********************************/
  10809. if(strstr(str, "key") != NULL)
  10810. {
  10811. loc = strstr(str, "key");
  10812. c = 0;
  10813. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10814. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  10815. {
  10816. sstr[c] = loc[strlen("key")+3+c];
  10817. c++;
  10818. }
  10819. sstr[c] = '\0';
  10820. strcpy(keystr,sstr);
  10821. }
  10822. //*************************readonly*********************************/
  10823. if(strstr(str, "readonly") != NULL)
  10824. {
  10825. loc = strstr(str, "readonly");
  10826. c = 0;
  10827. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10828. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  10829. {
  10830. sstr[c] = loc[strlen("readonly")+2+c];
  10831. c++;
  10832. }
  10833. sstr[c] = '\0';
  10834. strcpy(readonlystr,sstr);
  10835. }
  10836. //*************************value*********************************/
  10837. if(strstr(str, "value") != NULL)
  10838. {
  10839. loc = strstr(str, "value");
  10840. c = 0;
  10841. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10842. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  10843. {
  10844. sstr[c] = loc[strlen("value")+3+c];
  10845. c++;
  10846. }
  10847. sstr[c] = '\0';
  10848. strcpy(valuestr,sstr);
  10849. }
  10850. // DEBUG_INFO("keystr=%s\n",keystr);
  10851. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10852. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10853. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10854. {
  10855. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10856. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10857. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10858. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10859. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10860. }
  10861. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10862. {
  10863. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10864. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10865. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10866. }
  10867. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10868. {
  10869. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10870. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10871. }
  10872. if(strcmp(keystr, "BlinkRepeat") == 0)
  10873. {
  10874. //Charger.BlinkRepeat = Integer.parseInt(value);
  10875. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10876. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10877. }
  10878. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10879. {
  10880. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10881. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10882. }
  10883. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10884. {
  10885. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10886. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10887. }
  10888. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10889. {
  10890. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10891. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  10892. }
  10893. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10894. {
  10895. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10896. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10897. HeartBeatWaitTime = atoi(valuestr);
  10898. }
  10899. if(strcmp(keystr, "LightIntensity") == 0)
  10900. {
  10901. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10902. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10903. }
  10904. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10905. {
  10906. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10907. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10908. }
  10909. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10910. {
  10911. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10912. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10913. }
  10914. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10915. {
  10916. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10917. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10918. }
  10919. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10920. {
  10921. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10922. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10923. }
  10924. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10925. {
  10926. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10927. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10928. }
  10929. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10930. {
  10931. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10932. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10933. }
  10934. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10935. {
  10936. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10937. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10938. }
  10939. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10940. {
  10941. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10942. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10943. }
  10944. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10945. {
  10946. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10947. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10948. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10949. }
  10950. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10951. {
  10952. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10953. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10954. }
  10955. if(strcmp(keystr, "ResetRetries") == 0)
  10956. {
  10957. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10958. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10959. }
  10960. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10961. {
  10962. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10963. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10964. }
  10965. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10966. {
  10967. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10968. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10969. }
  10970. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10971. {
  10972. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10973. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10974. }
  10975. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10976. {
  10977. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10978. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10979. }
  10980. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10981. {
  10982. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10983. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10984. }
  10985. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10986. {
  10987. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10988. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10989. }
  10990. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10991. {
  10992. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10993. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10994. }
  10995. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10996. {
  10997. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10998. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10999. }
  11000. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  11001. {
  11002. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11003. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  11004. }
  11005. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  11006. {
  11007. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11008. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  11009. }
  11010. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  11011. {
  11012. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11013. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  11014. TransactionMessageAttemptsValue = atoi(valuestr);
  11015. }
  11016. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  11017. {
  11018. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11019. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  11020. TransactionMessageRetryIntervalValue = atoi(valuestr);
  11021. }
  11022. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  11023. {
  11024. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11025. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  11026. }
  11027. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  11028. {
  11029. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11030. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  11031. }
  11032. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  11033. {
  11034. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11035. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  11036. }
  11037. if(strcmp(keystr, "AuthorizationKey") == 0)
  11038. {
  11039. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11040. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  11041. }
  11042. if(strcmp(keystr, "SecurityProfile") == 0)
  11043. {
  11044. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11045. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  11046. }
  11047. if(strcmp(keystr, "DefaultPrice") == 0)
  11048. {
  11049. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11050. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  11051. }
  11052. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  11053. {
  11054. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11055. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  11056. }
  11057. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  11058. {
  11059. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11060. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  11061. }
  11062. if(strcmp(keystr, "ConfigurationVersion") == 0)
  11063. {
  11064. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11065. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  11066. }
  11067. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  11068. {
  11069. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11070. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  11071. }
  11072. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  11073. {
  11074. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11075. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  11076. }
  11077. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  11078. {
  11079. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11080. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  11081. }
  11082. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  11083. {
  11084. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11085. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  11086. }
  11087. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  11088. {
  11089. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11090. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  11091. }
  11092. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  11093. {
  11094. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11095. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  11096. }
  11097. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  11098. {
  11099. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11100. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  11101. }
  11102. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  11103. {
  11104. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11105. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  11106. }
  11107. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  11108. {
  11109. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11110. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  11111. }
  11112. }
  11113. }
  11114. fclose(fp);
  11115. }
  11116. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  11117. {
  11118. return PASS;
  11119. }
  11120. else
  11121. {
  11122. return FAIL;
  11123. }
  11124. }
  11125. void StoreConfigurationTable(void)
  11126. {
  11127. FILE *outfile;
  11128. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  11129. if(outfile == NULL)
  11130. {
  11131. DEBUG_INFO("Error opening file");
  11132. return ;
  11133. }
  11134. /*Core Profile*/
  11135. //AllowOfflineTxForUnknownId
  11136. /*
  11137. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11138. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  11139. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11140. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  11141. */
  11142. //DEBUG_INFO("data=%s\n",data);
  11143. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11144. //AuthorizationCacheEnabled
  11145. /*
  11146. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11148. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11149. */
  11150. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11151. //AuthorizeRemoteTxRequests
  11152. /*
  11153. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11154. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11155. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  11156. */
  11157. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11158. //BlinkRepeat
  11159. /*
  11160. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11162. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11163. */
  11164. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11165. //ClockAlignedDataInterval
  11166. /*
  11167. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11168. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11169. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11170. */
  11171. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11172. //ConnectionTimeOut
  11173. /*
  11174. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11175. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11176. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11177. */
  11178. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11179. //GetConfigurationMaxKeys
  11180. /*
  11181. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11182. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11183. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  11184. */
  11185. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11186. // HeartbeatInterval
  11187. /*
  11188. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11189. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11190. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  11191. */
  11192. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11193. // LightIntensity
  11194. /*
  11195. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11196. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11197. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11198. */
  11199. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11200. // LocalAuthorizeOffline
  11201. /*
  11202. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  11203. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  11204. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  11205. */
  11206. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11207. // LocalPreAuthorize
  11208. /*
  11209. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  11210. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  11211. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  11212. */
  11213. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  11214. // MaxEnergyOnInvalidId
  11215. /*
  11216. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  11217. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  11218. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  11219. */
  11220. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  11221. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  11222. // MeterValuesAlignedData
  11223. /*
  11224. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  11225. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  11226. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  11227. */
  11228. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  11229. // MeterValuesAlignedDataMaxLength
  11230. /*
  11231. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  11232. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  11233. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  11234. */
  11235. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  11236. // MeterValuesSampledData
  11237. /*
  11238. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  11239. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  11240. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  11241. */
  11242. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  11243. // MeterValuesSampledDataMaxLength
  11244. /*
  11245. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  11246. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  11247. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  11248. */
  11249. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  11250. // MeterValueSampleInterval
  11251. /*
  11252. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  11253. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  11254. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  11255. */
  11256. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  11257. // MinimumStatusDuration
  11258. /*
  11259. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  11260. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  11261. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  11262. */
  11263. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  11264. // NumberOfConnectors
  11265. /*
  11266. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  11267. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  11268. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11269. {
  11270. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  11271. }
  11272. else
  11273. {
  11274. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  11275. }
  11276. */
  11277. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  11278. // ResetRetries
  11279. /*
  11280. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  11281. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  11282. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  11283. */
  11284. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  11285. // ConnectorPhaseRotation
  11286. /*
  11287. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  11288. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  11289. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  11290. */
  11291. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  11292. // ConnectorPhaseRotationMaxLength
  11293. /*
  11294. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  11295. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  11296. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  11297. */
  11298. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  11299. // StopTransactionOnEVSideDisconnect
  11300. /*
  11301. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  11302. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  11303. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  11304. */
  11305. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  11306. // StopTransactionOnInvalidId
  11307. /*
  11308. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  11309. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  11310. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  11311. */
  11312. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  11313. // StopTxnAlignedData
  11314. /*
  11315. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  11316. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  11317. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  11318. */
  11319. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  11320. // StopTxnAlignedDataMaxLength
  11321. /*
  11322. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  11323. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  11324. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  11325. */
  11326. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  11327. // StopTxnSampledData
  11328. /*
  11329. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  11330. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  11331. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  11332. */
  11333. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  11334. // StopTxnSampledDataMaxLength
  11335. /*
  11336. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  11337. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  11338. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  11339. */
  11340. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  11341. // SupportedFeatureProfiles
  11342. /*
  11343. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  11344. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  11345. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  11346. */
  11347. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  11348. // SupportedFeatureProfilesMaxLength
  11349. /*
  11350. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  11351. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  11352. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  11353. */
  11354. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  11355. // TransactionMessageAttempts
  11356. /*
  11357. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  11358. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  11359. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  11360. */
  11361. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11362. // TransactionMessageRetryInterval
  11363. /*
  11364. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  11365. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  11366. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  11367. */
  11368. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11369. // UnlockConnectorOnEVSideDisconnect
  11370. /*
  11371. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  11372. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  11373. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  11374. */
  11375. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  11376. // WebSocketPingInterval
  11377. /*
  11378. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  11379. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  11380. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  11381. */
  11382. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  11383. // QueueOffLineStartTransactionMessage
  11384. /*
  11385. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  11386. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  11387. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  11388. */
  11389. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  11390. // AuthorizationKey
  11391. /*
  11392. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  11393. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  11394. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  11395. */
  11396. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  11397. // SecurityProfile
  11398. /*
  11399. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  11400. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  11401. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  11402. */
  11403. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  11404. // DefaultPrice
  11405. /*
  11406. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  11407. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  11408. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  11409. */
  11410. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  11411. // CustomDisplayCostAndPrice
  11412. /*
  11413. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  11414. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  11415. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  11416. */
  11417. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  11418. // CustomIdleFeeAfterStop
  11419. /*
  11420. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  11421. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  11422. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  11423. */
  11424. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  11425. // ConfigurationVersion
  11426. /*
  11427. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  11428. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  11429. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  11430. */
  11431. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  11432. //* Local Auth List Management Profile*/
  11433. //LocalAuthListEnabled
  11434. /*
  11435. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11436. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  11437. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11438. */
  11439. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11440. //LocalAuthListMaxLength
  11441. /*
  11442. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  11443. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  11444. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  11445. */
  11446. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  11447. //SendLocalListMaxLength
  11448. /*
  11449. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  11450. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  11451. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  11452. */
  11453. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  11454. //ReserveConnectorZeroSupported
  11455. /*
  11456. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  11457. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  11458. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  11459. */
  11460. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11461. //* Smart Charging Profile */
  11462. //ChargeProfileMaxStackLevel
  11463. /*
  11464. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  11465. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  11466. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  11467. */
  11468. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11469. // ChargingScheduleAllowedChargingRateUnit
  11470. /*
  11471. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  11472. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  11473. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  11474. */
  11475. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11476. // ChargingScheduleMaxPeriods
  11477. /*
  11478. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  11479. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  11480. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  11481. */
  11482. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11483. // ConnectorSwitch3to1PhaseSupported
  11484. /*
  11485. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11486. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11487. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  11488. */
  11489. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11490. // MaxChargingProfilesInstalled
  11491. /*
  11492. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11493. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11494. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  11495. */
  11496. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11497. fclose(outfile);
  11498. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11499. }
  11500. void getKeyValue(char *keyReq)
  11501. {
  11502. int isEmpty = FALSE;
  11503. int isKnowKey = FALSE;
  11504. DEBUG_INFO("keyReq = %s\n", keyReq);
  11505. if((keyReq == NULL) || (strlen(keyReq) == 0))
  11506. isEmpty = TRUE;
  11507. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  11508. {
  11509. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  11510. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  11511. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11512. {
  11513. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  11514. }
  11515. else
  11516. {
  11517. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  11518. }
  11519. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  11520. isKnowKey = TRUE;
  11521. }
  11522. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  11523. {
  11524. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  11525. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  11526. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11527. {
  11528. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  11529. }
  11530. else
  11531. {
  11532. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  11533. }
  11534. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  11535. isKnowKey = TRUE;
  11536. }
  11537. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  11538. {
  11539. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  11540. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  11541. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11542. {
  11543. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  11544. }
  11545. else
  11546. {
  11547. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  11548. }
  11549. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  11550. isKnowKey = TRUE;
  11551. }
  11552. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  11553. {
  11554. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  11555. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  11556. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11557. {
  11558. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  11559. }
  11560. else
  11561. {
  11562. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  11563. }
  11564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  11565. isKnowKey = TRUE;
  11566. }
  11567. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  11568. {
  11569. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  11570. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  11571. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11572. {
  11573. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  11574. }
  11575. else
  11576. {
  11577. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  11578. }
  11579. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  11580. isKnowKey = TRUE;
  11581. }
  11582. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  11583. {
  11584. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  11585. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  11586. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11587. {
  11588. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  11589. }
  11590. else
  11591. {
  11592. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  11593. }
  11594. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  11595. isKnowKey = TRUE;
  11596. }
  11597. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  11598. {
  11599. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  11600. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  11601. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11602. {
  11603. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  11604. }
  11605. else
  11606. {
  11607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  11608. }
  11609. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  11610. isKnowKey = TRUE;
  11611. }
  11612. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  11613. {
  11614. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  11615. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  11616. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11617. {
  11618. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  11619. }
  11620. else
  11621. {
  11622. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  11623. }
  11624. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  11625. isKnowKey = TRUE;
  11626. }
  11627. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  11628. {
  11629. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  11630. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  11631. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11632. {
  11633. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  11634. }
  11635. else
  11636. {
  11637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  11638. }
  11639. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  11640. isKnowKey = TRUE;
  11641. }
  11642. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  11643. {
  11644. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  11645. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  11646. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11647. {
  11648. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  11649. }
  11650. else
  11651. {
  11652. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  11653. }
  11654. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  11655. isKnowKey = TRUE;
  11656. }
  11657. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  11658. {
  11659. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  11660. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  11661. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11662. {
  11663. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  11664. }
  11665. else
  11666. {
  11667. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  11668. }
  11669. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  11670. isKnowKey = TRUE;
  11671. }
  11672. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  11673. {
  11674. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  11675. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  11676. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11677. {
  11678. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11679. }
  11680. else
  11681. {
  11682. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11683. }
  11684. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  11685. isKnowKey = TRUE;
  11686. }
  11687. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  11688. {
  11689. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  11690. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  11691. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11692. {
  11693. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11694. }
  11695. else
  11696. {
  11697. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11698. }
  11699. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  11700. isKnowKey = TRUE;
  11701. }
  11702. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  11703. {
  11704. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  11705. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  11706. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11707. {
  11708. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11709. }
  11710. else
  11711. {
  11712. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11713. }
  11714. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  11715. isKnowKey = TRUE;
  11716. }
  11717. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  11718. {
  11719. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  11720. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  11721. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11722. {
  11723. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  11724. }
  11725. else
  11726. {
  11727. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  11728. }
  11729. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  11730. isKnowKey = TRUE;
  11731. }
  11732. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  11733. {
  11734. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  11735. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  11736. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11737. {
  11738. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11739. }
  11740. else
  11741. {
  11742. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11743. }
  11744. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  11745. isKnowKey = TRUE;
  11746. }
  11747. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  11748. {
  11749. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  11750. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  11751. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11752. {
  11753. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  11754. }
  11755. else
  11756. {
  11757. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  11758. }
  11759. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  11760. isKnowKey = TRUE;
  11761. }
  11762. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  11763. {
  11764. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  11765. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  11766. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11767. {
  11768. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  11769. }
  11770. else
  11771. {
  11772. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  11773. }
  11774. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  11775. isKnowKey = TRUE;
  11776. }
  11777. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  11778. {
  11779. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  11780. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  11781. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11782. {
  11783. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  11784. }
  11785. else
  11786. {
  11787. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  11788. }
  11789. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  11790. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  11791. isKnowKey = TRUE;
  11792. }
  11793. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  11794. {
  11795. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  11796. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11797. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11798. {
  11799. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11800. }
  11801. else
  11802. {
  11803. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11804. }
  11805. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11806. isKnowKey = TRUE;
  11807. }
  11808. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11809. {
  11810. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11811. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11812. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11813. {
  11814. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11815. }
  11816. else
  11817. {
  11818. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11819. }
  11820. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11821. isKnowKey = TRUE;
  11822. }
  11823. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11824. {
  11825. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11826. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11827. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11828. {
  11829. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11830. }
  11831. else
  11832. {
  11833. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11834. }
  11835. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11836. isKnowKey = TRUE;
  11837. }
  11838. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11839. {
  11840. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11841. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11842. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11843. {
  11844. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11845. }
  11846. else
  11847. {
  11848. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11849. }
  11850. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11851. isKnowKey = TRUE;
  11852. }
  11853. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11854. {
  11855. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11856. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11857. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11858. {
  11859. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11860. }
  11861. else
  11862. {
  11863. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11864. }
  11865. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11866. isKnowKey = TRUE;
  11867. }
  11868. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11869. {
  11870. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11871. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11872. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11873. {
  11874. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11875. }
  11876. else
  11877. {
  11878. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11879. }
  11880. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11881. isKnowKey = TRUE;
  11882. }
  11883. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11884. {
  11885. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11886. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11887. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11888. {
  11889. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11890. }
  11891. else
  11892. {
  11893. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11894. }
  11895. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11896. isKnowKey = TRUE;
  11897. }
  11898. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11899. {
  11900. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11901. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11902. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11903. {
  11904. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11905. }
  11906. else
  11907. {
  11908. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11909. }
  11910. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11911. isKnowKey = TRUE;
  11912. }
  11913. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11914. {
  11915. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11916. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11917. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11918. {
  11919. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11920. }
  11921. else
  11922. {
  11923. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11924. }
  11925. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11926. isKnowKey = TRUE;
  11927. }
  11928. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11929. {
  11930. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11931. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11932. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11933. {
  11934. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11935. }
  11936. else
  11937. {
  11938. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11939. }
  11940. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11941. isKnowKey = TRUE;
  11942. }
  11943. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11944. {
  11945. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11946. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11947. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11948. {
  11949. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11950. }
  11951. else
  11952. {
  11953. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11954. }
  11955. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11956. isKnowKey = TRUE;
  11957. }
  11958. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11959. {
  11960. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11961. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11962. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11963. {
  11964. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11965. }
  11966. else
  11967. {
  11968. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11969. }
  11970. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11971. isKnowKey = TRUE;
  11972. }
  11973. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11974. {
  11975. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11976. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11977. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11978. {
  11979. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11980. }
  11981. else
  11982. {
  11983. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11984. }
  11985. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11986. isKnowKey = TRUE;
  11987. }
  11988. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11989. {
  11990. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11991. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11992. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11993. {
  11994. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11995. }
  11996. else
  11997. {
  11998. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11999. }
  12000. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  12001. isKnowKey = TRUE;
  12002. }
  12003. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  12004. {
  12005. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  12006. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  12007. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12008. {
  12009. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  12010. }
  12011. else
  12012. {
  12013. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  12014. }
  12015. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  12016. isKnowKey = TRUE;
  12017. }
  12018. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  12019. {
  12020. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  12021. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  12022. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12023. {
  12024. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  12025. }
  12026. else
  12027. {
  12028. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  12029. }
  12030. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  12031. isKnowKey = TRUE;
  12032. }
  12033. /*
  12034. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  12035. {
  12036. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  12037. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  12038. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  12039. {
  12040. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  12041. }
  12042. else
  12043. {
  12044. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  12045. }
  12046. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  12047. isKnowKey = TRUE;
  12048. }*/
  12049. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  12050. {
  12051. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  12052. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  12053. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  12054. {
  12055. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  12056. }
  12057. else
  12058. {
  12059. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  12060. }
  12061. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  12062. isKnowKey = TRUE;
  12063. }
  12064. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  12065. {
  12066. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  12067. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  12068. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  12069. {
  12070. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  12071. }
  12072. else
  12073. {
  12074. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  12075. }
  12076. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  12077. isKnowKey = TRUE;
  12078. }
  12079. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  12080. {
  12081. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  12082. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  12083. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  12084. {
  12085. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  12086. }
  12087. else
  12088. {
  12089. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  12090. }
  12091. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  12092. isKnowKey = TRUE;
  12093. }
  12094. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  12095. {
  12096. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  12097. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  12098. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  12099. {
  12100. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  12101. }
  12102. else
  12103. {
  12104. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  12105. }
  12106. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  12107. isKnowKey = TRUE;
  12108. }
  12109. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  12110. {
  12111. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  12112. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  12113. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  12114. {
  12115. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  12116. }
  12117. else
  12118. {
  12119. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  12120. }
  12121. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  12122. isKnowKey = TRUE;
  12123. }
  12124. #if 1
  12125. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  12126. {
  12127. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  12128. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  12129. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12130. {
  12131. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  12132. }
  12133. else
  12134. {
  12135. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  12136. }
  12137. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  12138. isKnowKey = TRUE;
  12139. }
  12140. #endif
  12141. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  12142. {
  12143. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  12144. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  12145. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12146. {
  12147. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12148. }
  12149. else
  12150. {
  12151. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12152. }
  12153. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  12154. isKnowKey = TRUE;
  12155. }
  12156. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  12157. {
  12158. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  12159. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  12160. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12161. {
  12162. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12163. }
  12164. else
  12165. {
  12166. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12167. }
  12168. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  12169. isKnowKey = TRUE;
  12170. }
  12171. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  12172. {
  12173. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  12174. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  12175. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12176. {
  12177. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  12178. }
  12179. else
  12180. {
  12181. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  12182. }
  12183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12184. isKnowKey = TRUE;
  12185. }
  12186. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  12187. {
  12188. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  12189. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  12190. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12191. {
  12192. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  12193. }
  12194. else
  12195. {
  12196. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  12197. }
  12198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12199. isKnowKey = TRUE;
  12200. }
  12201. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  12202. {
  12203. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  12204. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  12205. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12206. {
  12207. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  12208. }
  12209. else
  12210. {
  12211. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  12212. }
  12213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12214. isKnowKey = TRUE;
  12215. }
  12216. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  12217. {
  12218. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  12219. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  12220. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12221. {
  12222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  12223. }
  12224. else
  12225. {
  12226. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  12227. }
  12228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12229. isKnowKey = TRUE;
  12230. }
  12231. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  12232. {
  12233. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  12234. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  12235. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12236. {
  12237. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  12238. }
  12239. else
  12240. {
  12241. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  12242. }
  12243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12244. isKnowKey = TRUE;
  12245. }
  12246. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  12247. {
  12248. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  12249. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  12250. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12251. {
  12252. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  12253. }
  12254. else
  12255. {
  12256. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  12257. }
  12258. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12259. isKnowKey = TRUE;
  12260. }
  12261. //=========================================================
  12262. if(!isEmpty && !isKnowKey)
  12263. {
  12264. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  12265. strcpy(unknownkey[UnknownKeynum], keyReq);
  12266. UnknownKeynum = UnknownKeynum + 1;
  12267. }
  12268. }
  12269. void processUnkownKey(void)
  12270. {
  12271. DEBUG_INFO("processUnkownKey...\n");
  12272. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  12273. for(int index=0; index < UnknownKeynum; index++)
  12274. {
  12275. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  12276. {
  12277. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  12278. }
  12279. }
  12280. }
  12281. int setKeyValue(char *key, char *value)
  12282. {
  12283. int isSuccess = NotSupported;
  12284. int check_ascii=0;
  12285. char str[256]={0};
  12286. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  12287. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  12288. {
  12289. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  12290. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  12291. {
  12292. strcpy(str, (const char*)value);
  12293. for(int i = 0; str[i]; i++){
  12294. str[i] = tolower(str[i]);
  12295. }
  12296. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12297. isSuccess = ConfigurationStatus_Accepted;
  12298. }
  12299. else
  12300. {
  12301. isSuccess = ConfigurationStatus_Rejected;
  12302. }
  12303. }
  12304. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  12305. {
  12306. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  12307. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  12308. {
  12309. strcpy(str, (const char*)value);
  12310. for(int i = 0; str[i]; i++){
  12311. str[i] = tolower(str[i]);
  12312. }
  12313. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12314. isSuccess = ConfigurationStatus_Accepted;
  12315. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  12316. }
  12317. else
  12318. {
  12319. isSuccess = ConfigurationStatus_Rejected;
  12320. }
  12321. }
  12322. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  12323. {
  12324. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  12325. {
  12326. strcpy(str, (const char*)value);
  12327. for(int i = 0; str[i]; i++)
  12328. {
  12329. str[i] = tolower(str[i]);
  12330. }
  12331. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  12332. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12333. isSuccess = ConfigurationStatus_Accepted;
  12334. }
  12335. else
  12336. {
  12337. isSuccess = ConfigurationStatus_Rejected;
  12338. }
  12339. }
  12340. if(strcmp(key, "BlinkRepeat") == 0)
  12341. {
  12342. //Charger.BlinkRepeat = Integer.parseInt(value);
  12343. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  12344. {
  12345. check_ascii = value[0];
  12346. if( (check_ascii < 48) || (check_ascii > 57) )
  12347. {
  12348. isSuccess = ConfigurationStatus_Rejected;
  12349. }
  12350. else
  12351. {
  12352. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  12353. isSuccess = ConfigurationStatus_Accepted;
  12354. }
  12355. }
  12356. else
  12357. {
  12358. isSuccess = ConfigurationStatus_Rejected;
  12359. }
  12360. }
  12361. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  12362. {
  12363. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  12364. {
  12365. check_ascii = value[0];
  12366. if( (check_ascii < 48) || (check_ascii > 57) )
  12367. {
  12368. isSuccess = ConfigurationStatus_Rejected;
  12369. }
  12370. else
  12371. {
  12372. if((atoi(value) == 0) || (atoi(value) >= 10))
  12373. {
  12374. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  12375. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  12376. isSuccess = ConfigurationStatus_Accepted;
  12377. }
  12378. else
  12379. isSuccess = ConfigurationStatus_Rejected;
  12380. }
  12381. }
  12382. else
  12383. {
  12384. isSuccess = ConfigurationStatus_Rejected;
  12385. }
  12386. }
  12387. if(strcmp(key, "ConnectionTimeOut") == 0 )
  12388. {
  12389. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  12390. {
  12391. check_ascii = value[0];
  12392. if( (check_ascii < 48) || (check_ascii > 57) )
  12393. {
  12394. isSuccess = ConfigurationStatus_Rejected;
  12395. }
  12396. else
  12397. {
  12398. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  12399. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  12400. isSuccess = ConfigurationStatus_Accepted;
  12401. }
  12402. }
  12403. else
  12404. {
  12405. isSuccess = ConfigurationStatus_Rejected;
  12406. }
  12407. }
  12408. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  12409. {
  12410. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  12411. {
  12412. check_ascii = value[0];
  12413. if( (check_ascii < 48) || (check_ascii > 57) )
  12414. {
  12415. isSuccess = ConfigurationStatus_Rejected;
  12416. }
  12417. else
  12418. {
  12419. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  12420. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  12421. isSuccess = ConfigurationStatus_Accepted;
  12422. }
  12423. }
  12424. else
  12425. {
  12426. isSuccess = ConfigurationStatus_Rejected;
  12427. }
  12428. }
  12429. if(strcmp(key, "HeartbeatInterval") == 0)
  12430. {
  12431. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  12432. {
  12433. check_ascii = value[0];
  12434. if( (check_ascii < 48) || (check_ascii > 57) )
  12435. {
  12436. isSuccess = ConfigurationStatus_Rejected;
  12437. }
  12438. else
  12439. {
  12440. if((atoi(value) == 0) || (atoi(value) >= 10))
  12441. {
  12442. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  12443. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  12444. HeartBeatWaitTime = atoi(value);
  12445. isSuccess = ConfigurationStatus_Accepted;
  12446. }
  12447. else
  12448. {
  12449. isSuccess = ConfigurationStatus_Rejected;
  12450. }
  12451. }
  12452. }
  12453. else
  12454. {
  12455. isSuccess = ConfigurationStatus_Rejected;
  12456. }
  12457. }
  12458. if(strcmp(key, "LightIntensity") == 0)
  12459. {
  12460. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  12461. {
  12462. check_ascii = value[0];
  12463. if( (check_ascii < 48) || (check_ascii > 57) )
  12464. {
  12465. isSuccess = ConfigurationStatus_Rejected;
  12466. }
  12467. else
  12468. {
  12469. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  12470. isSuccess = ConfigurationStatus_Accepted;
  12471. }
  12472. }
  12473. else
  12474. {
  12475. isSuccess = ConfigurationStatus_Rejected;
  12476. }
  12477. }
  12478. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  12479. {
  12480. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  12481. {
  12482. strcpy(str, (const char*)value);
  12483. for(int i = 0; str[i]; i++)
  12484. {
  12485. str[i] = tolower(str[i]);
  12486. }
  12487. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12488. isSuccess = ConfigurationStatus_Accepted;
  12489. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12490. }
  12491. else
  12492. {
  12493. isSuccess = ConfigurationStatus_Rejected;
  12494. }
  12495. }
  12496. if(strcmp(key, "LocalPreAuthorize") == 0)
  12497. {
  12498. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  12499. {
  12500. strcpy(str, (const char*)value);
  12501. for(int i = 0; str[i]; i++)
  12502. {
  12503. str[i] = tolower(str[i]);
  12504. }
  12505. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12506. isSuccess = ConfigurationStatus_Accepted;
  12507. }
  12508. else
  12509. {
  12510. isSuccess = ConfigurationStatus_Rejected;
  12511. }
  12512. }
  12513. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  12514. {
  12515. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  12516. {
  12517. check_ascii = value[0];
  12518. if( (check_ascii < 48) || (check_ascii > 57) )
  12519. {
  12520. isSuccess = ConfigurationStatus_Rejected;
  12521. }
  12522. else
  12523. {
  12524. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  12525. isSuccess = ConfigurationStatus_Accepted;
  12526. }
  12527. }
  12528. else
  12529. {
  12530. isSuccess = ConfigurationStatus_Rejected;
  12531. }
  12532. }
  12533. if(strcmp(key, "MeterValuesAlignedData") == 0)
  12534. {
  12535. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  12536. {
  12537. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  12538. isSuccess = ConfigurationStatus_Accepted;
  12539. }
  12540. else
  12541. {
  12542. isSuccess = ConfigurationStatus_Rejected;
  12543. }
  12544. }
  12545. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  12546. {
  12547. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  12548. {
  12549. check_ascii = value[0];
  12550. if( (check_ascii < 48) || (check_ascii > 57) )
  12551. {
  12552. isSuccess = ConfigurationStatus_Rejected;
  12553. }
  12554. else
  12555. {
  12556. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12557. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  12558. isSuccess = ConfigurationStatus_Accepted;
  12559. }
  12560. }
  12561. else
  12562. {
  12563. isSuccess = ConfigurationStatus_Rejected;
  12564. }
  12565. }
  12566. if(strcmp(key, "MeterValuesSampledData") == 0 )
  12567. {
  12568. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  12569. {
  12570. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  12571. isSuccess = ConfigurationStatus_Accepted;
  12572. }
  12573. else
  12574. {
  12575. isSuccess = ConfigurationStatus_Rejected;
  12576. }
  12577. }
  12578. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  12579. {
  12580. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  12581. {
  12582. check_ascii = value[0];
  12583. if( (check_ascii < 48) || (check_ascii > 57) )
  12584. {
  12585. isSuccess = ConfigurationStatus_Rejected;
  12586. }
  12587. else
  12588. {
  12589. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12590. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  12591. isSuccess = ConfigurationStatus_Accepted;
  12592. }
  12593. }
  12594. else
  12595. {
  12596. isSuccess = ConfigurationStatus_Rejected;
  12597. }
  12598. }
  12599. if(strcmp(key, "MeterValueSampleInterval") == 0)
  12600. {
  12601. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12602. {
  12603. check_ascii = value[0];
  12604. if( (check_ascii < 48) || (check_ascii > 57) )
  12605. {
  12606. isSuccess = ConfigurationStatus_Rejected;
  12607. }
  12608. else
  12609. {
  12610. if((atoi(value) == 0) || (atoi(value) >= 10))
  12611. {
  12612. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12613. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  12614. isSuccess = ConfigurationStatus_Accepted;
  12615. }
  12616. else
  12617. {
  12618. isSuccess = ConfigurationStatus_Rejected;
  12619. }
  12620. }
  12621. }
  12622. else
  12623. {
  12624. isSuccess = ConfigurationStatus_Rejected;
  12625. }
  12626. }
  12627. if(strcmp(key, "MinimumStatusDuration") == 0)
  12628. {
  12629. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12630. {
  12631. check_ascii = value[0];
  12632. if( (check_ascii < 48) || (check_ascii > 57) )
  12633. {
  12634. isSuccess = ConfigurationStatus_Rejected;
  12635. }
  12636. else
  12637. {
  12638. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  12639. {
  12640. isSuccess = ConfigurationStatus_Rejected;
  12641. }
  12642. else
  12643. {
  12644. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  12645. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  12646. server_cycle_Status = atoi(value); //StatusNotification Cycle
  12647. isSuccess = ConfigurationStatus_Accepted;
  12648. }
  12649. }
  12650. }
  12651. else
  12652. {
  12653. isSuccess = ConfigurationStatus_Rejected;
  12654. }
  12655. }
  12656. if(strcmp(key, "NumberOfConnectors") == 0)
  12657. {
  12658. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12659. {
  12660. check_ascii = value[0];
  12661. if( (check_ascii < 48) || (check_ascii > 57) )
  12662. {
  12663. isSuccess = ConfigurationStatus_Rejected;
  12664. }
  12665. else
  12666. {
  12667. //Charger.ResetRetries = Integer.parseInt(value);
  12668. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  12669. isSuccess = ConfigurationStatus_Accepted;
  12670. }
  12671. }
  12672. else
  12673. {
  12674. isSuccess = ConfigurationStatus_Rejected;
  12675. }
  12676. }
  12677. if(strcmp(key, "ResetRetries") == 0)
  12678. {
  12679. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].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. //Charger.ResetRetries = Integer.parseInt(value);
  12689. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  12690. isSuccess = ConfigurationStatus_Accepted;
  12691. }
  12692. }
  12693. else
  12694. {
  12695. isSuccess = ConfigurationStatus_Rejected;
  12696. }
  12697. }
  12698. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  12699. {
  12700. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12701. {
  12702. strcpy(str, (const char*)value);
  12703. for(int i = 0; str[i]; i++)
  12704. {
  12705. str[i] = tolower(str[i]);
  12706. }
  12707. if(strcmp(str, "notapplicable")== 0)
  12708. {
  12709. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  12710. isSuccess = ConfigurationStatus_Accepted;
  12711. }
  12712. else if(strcmp(str, "unknown")== 0)
  12713. {
  12714. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  12715. isSuccess = ConfigurationStatus_Accepted;
  12716. }
  12717. else if(strcmp(str, "rst")== 0)
  12718. {
  12719. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  12720. isSuccess = ConfigurationStatus_Accepted;
  12721. }
  12722. else if(strcmp(str, "rts")== 0)
  12723. {
  12724. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  12725. isSuccess = ConfigurationStatus_Accepted;
  12726. }
  12727. else if(strcmp(str, "srt")== 0)
  12728. {
  12729. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  12730. isSuccess = ConfigurationStatus_Accepted;
  12731. }
  12732. else if(strcmp(str, "str")== 0)
  12733. {
  12734. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  12735. isSuccess = ConfigurationStatus_Accepted;
  12736. }
  12737. else if(strcmp(str, "trs")== 0)
  12738. {
  12739. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  12740. isSuccess = ConfigurationStatus_Accepted;
  12741. }
  12742. else if(strcmp(str, "tsr")== 0)
  12743. {
  12744. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  12745. isSuccess = ConfigurationStatus_Accepted;
  12746. }
  12747. else
  12748. {
  12749. isSuccess = ConfigurationStatus_Rejected;
  12750. }
  12751. }
  12752. else
  12753. {
  12754. isSuccess = ConfigurationStatus_Rejected;
  12755. }
  12756. }
  12757. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  12758. {
  12759. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12760. {
  12761. check_ascii = value[0];
  12762. if( (check_ascii < 48) || (check_ascii > 57) )
  12763. {
  12764. isSuccess = ConfigurationStatus_Rejected;
  12765. }
  12766. else
  12767. {
  12768. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  12769. isSuccess = ConfigurationStatus_Accepted;
  12770. }
  12771. }
  12772. else
  12773. {
  12774. isSuccess = ConfigurationStatus_Rejected;
  12775. }
  12776. }
  12777. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  12778. {
  12779. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12780. {
  12781. strcpy(str, (const char*)value);
  12782. for(int i = 0; str[i]; i++)
  12783. {
  12784. str[i] = tolower(str[i]);
  12785. }
  12786. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12787. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12788. isSuccess = ConfigurationStatus_Accepted;
  12789. }
  12790. else
  12791. {
  12792. isSuccess = ConfigurationStatus_Rejected;
  12793. }
  12794. }
  12795. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  12796. {
  12797. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12798. {
  12799. strcpy(str, (const char*)value);
  12800. for(int i = 0; str[i]; i++)
  12801. {
  12802. str[i] = tolower(str[i]);
  12803. }
  12804. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  12805. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12806. isSuccess = ConfigurationStatus_Accepted;
  12807. }
  12808. else
  12809. {
  12810. isSuccess = ConfigurationStatus_Rejected;
  12811. }
  12812. }
  12813. if(strcmp(key, "StopTxnAlignedData") == 0)
  12814. {
  12815. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12816. {
  12817. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  12818. isSuccess = ConfigurationStatus_Accepted;
  12819. }
  12820. else
  12821. {
  12822. isSuccess = ConfigurationStatus_Rejected;
  12823. }
  12824. }
  12825. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  12826. {
  12827. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12828. {
  12829. check_ascii = value[0];
  12830. if( (check_ascii < 48) || (check_ascii > 57) )
  12831. {
  12832. isSuccess = ConfigurationStatus_Rejected;
  12833. }
  12834. else
  12835. {
  12836. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  12837. isSuccess = ConfigurationStatus_Accepted;
  12838. }
  12839. }
  12840. else
  12841. {
  12842. isSuccess = ConfigurationStatus_Rejected;
  12843. }
  12844. }
  12845. if(strcmp(key, "StopTxnSampledData") == 0)
  12846. {
  12847. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12848. {
  12849. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  12850. isSuccess = ConfigurationStatus_Accepted;
  12851. }
  12852. else
  12853. {
  12854. isSuccess = ConfigurationStatus_Rejected;
  12855. }
  12856. }
  12857. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  12858. {
  12859. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12860. {
  12861. check_ascii = value[0];
  12862. if( (check_ascii < 48) || (check_ascii > 57) )
  12863. {
  12864. isSuccess = ConfigurationStatus_Rejected;
  12865. }
  12866. else
  12867. {
  12868. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  12869. isSuccess = ConfigurationStatus_Accepted;
  12870. }
  12871. }
  12872. else
  12873. {
  12874. isSuccess = ConfigurationStatus_Rejected;
  12875. }
  12876. }
  12877. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  12878. {
  12879. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12880. {
  12881. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  12882. isSuccess = ConfigurationStatus_Accepted;
  12883. }
  12884. else
  12885. {
  12886. isSuccess = ConfigurationStatus_Rejected;
  12887. }
  12888. }
  12889. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  12890. {
  12891. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12892. {
  12893. check_ascii = value[0];
  12894. if( (check_ascii < 48) || (check_ascii > 57) )
  12895. {
  12896. isSuccess = ConfigurationStatus_Rejected;
  12897. }
  12898. else
  12899. {
  12900. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  12901. isSuccess = ConfigurationStatus_Accepted;
  12902. }
  12903. }
  12904. else
  12905. {
  12906. isSuccess = ConfigurationStatus_Rejected;
  12907. }
  12908. }
  12909. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12910. {
  12911. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12912. {
  12913. check_ascii = value[0];
  12914. if( (check_ascii < 48) || (check_ascii > 57) )
  12915. {
  12916. isSuccess = ConfigurationStatus_Rejected;
  12917. }
  12918. else
  12919. {
  12920. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12921. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12922. TransactionMessageAttemptsValue = atoi(value);
  12923. isSuccess = ConfigurationStatus_Accepted;
  12924. }
  12925. }
  12926. else
  12927. {
  12928. isSuccess = ConfigurationStatus_Rejected;
  12929. }
  12930. }
  12931. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12932. {
  12933. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].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. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12943. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12944. TransactionMessageRetryIntervalValue = atoi(value);
  12945. isSuccess = ConfigurationStatus_Accepted;
  12946. }
  12947. }
  12948. else
  12949. {
  12950. isSuccess = ConfigurationStatus_Rejected;
  12951. }
  12952. }
  12953. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12954. {
  12955. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12956. {
  12957. strcpy(str, (const char*)value);
  12958. for(int i = 0; str[i]; i++)
  12959. {
  12960. str[i] = tolower(str[i]);
  12961. }
  12962. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12963. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12964. isSuccess = ConfigurationStatus_Accepted;
  12965. }
  12966. else
  12967. {
  12968. isSuccess = ConfigurationStatus_Rejected;
  12969. }
  12970. }
  12971. if(strcmp(key, "WebSocketPingInterval") == 0)
  12972. {
  12973. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12974. {
  12975. check_ascii = value[0];
  12976. if( (check_ascii < 48) || (check_ascii > 57) )
  12977. {
  12978. isSuccess = ConfigurationStatus_Rejected;
  12979. }
  12980. else
  12981. {
  12982. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12983. isSuccess = ConfigurationStatus_Accepted;
  12984. }
  12985. }
  12986. else
  12987. {
  12988. isSuccess = ConfigurationStatus_Rejected;
  12989. }
  12990. }
  12991. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  12992. {
  12993. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12994. {
  12995. strcpy(str, (const char*)value);
  12996. for(int i = 0; str[i]; i++)
  12997. {
  12998. str[i] = tolower(str[i]);
  12999. }
  13000. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13001. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13002. isSuccess = ConfigurationStatus_Accepted;
  13003. }
  13004. else
  13005. {
  13006. isSuccess = ConfigurationStatus_Rejected;
  13007. }
  13008. }
  13009. if(strcmp(key, "AuthorizationKey") == 0)
  13010. {
  13011. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  13012. {
  13013. strcpy(str, (const char*)value);
  13014. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  13015. isSuccess = ConfigurationStatus_Accepted;
  13016. }
  13017. else
  13018. {
  13019. isSuccess = ConfigurationStatus_Rejected;
  13020. }
  13021. }
  13022. if(strcmp(key, "SecurityProfile") == 0)
  13023. {
  13024. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  13025. {
  13026. check_ascii = value[0];
  13027. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  13028. {
  13029. isSuccess = ConfigurationStatus_Rejected;
  13030. }
  13031. else if(check_ascii == 0x33)
  13032. {
  13033. isSuccess = NotSupported;
  13034. }
  13035. else
  13036. {
  13037. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  13038. {
  13039. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  13040. isSuccess = ConfigurationStatus_Accepted;
  13041. }
  13042. else
  13043. isSuccess = ConfigurationStatus_Rejected;
  13044. }
  13045. }
  13046. else
  13047. {
  13048. isSuccess = ConfigurationStatus_Rejected;
  13049. }
  13050. }
  13051. if(strcmp(key, "DefaultPrice") == 0)
  13052. {
  13053. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  13054. {
  13055. strcpy(str, (const char*)value);
  13056. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  13057. isSuccess = ConfigurationStatus_Accepted;
  13058. }
  13059. else
  13060. {
  13061. isSuccess = ConfigurationStatus_Rejected;
  13062. }
  13063. }
  13064. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  13065. {
  13066. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  13067. {
  13068. strcpy(str, (const char*)value);
  13069. for(int i = 0; str[i]; i++)
  13070. {
  13071. str[i] = tolower(str[i]);
  13072. }
  13073. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13074. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13075. isSuccess = ConfigurationStatus_Accepted;
  13076. }
  13077. else
  13078. {
  13079. isSuccess = ConfigurationStatus_Rejected;
  13080. }
  13081. }
  13082. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  13083. {
  13084. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  13085. {
  13086. strcpy(str, (const char*)value);
  13087. for(int i = 0; str[i]; i++)
  13088. {
  13089. str[i] = tolower(str[i]);
  13090. }
  13091. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13092. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13093. isSuccess = ConfigurationStatus_Accepted;
  13094. }
  13095. else
  13096. {
  13097. isSuccess = ConfigurationStatus_Rejected;
  13098. }
  13099. }
  13100. #if 0
  13101. //For OCPP Test Case
  13102. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  13103. {
  13104. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13105. {
  13106. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  13107. isSuccess = ConfigurationStatus_Accepted;
  13108. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13109. }
  13110. else
  13111. {
  13112. isSuccess = ConfigurationStatus_Rejected;
  13113. }
  13114. }
  13115. #endif
  13116. #if 1
  13117. if(strcmp(key, "LocalAuthListEnabled") == 0)
  13118. {
  13119. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13120. {
  13121. strcpy(str, (const char*)value);
  13122. for(int i = 0; str[i]; i++)
  13123. {
  13124. str[i] = tolower(str[i]);
  13125. }
  13126. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13127. isSuccess = ConfigurationStatus_Accepted;
  13128. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13129. }
  13130. else
  13131. {
  13132. isSuccess = ConfigurationStatus_Rejected;
  13133. }
  13134. }
  13135. #endif
  13136. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  13137. {
  13138. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  13139. {
  13140. check_ascii = value[0];
  13141. if( (check_ascii < 48) || (check_ascii > 57) )
  13142. {
  13143. isSuccess = ConfigurationStatus_Rejected;
  13144. }
  13145. else
  13146. {
  13147. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  13148. isSuccess = ConfigurationStatus_Accepted;
  13149. }
  13150. }
  13151. else
  13152. {
  13153. isSuccess = ConfigurationStatus_Rejected;
  13154. }
  13155. }
  13156. if(strcmp(key, "SendLocalListMaxLength") == 0)
  13157. {
  13158. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  13159. {
  13160. check_ascii = value[0];
  13161. if( (check_ascii < 48) || (check_ascii > 57) )
  13162. {
  13163. isSuccess = ConfigurationStatus_Rejected;
  13164. }
  13165. else
  13166. {
  13167. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  13168. isSuccess = ConfigurationStatus_Accepted;
  13169. }
  13170. }
  13171. else
  13172. {
  13173. isSuccess = ConfigurationStatus_Rejected;
  13174. }
  13175. }
  13176. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  13177. {
  13178. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  13179. {
  13180. strcpy(str, (const char*)value);
  13181. for(int i = 0; str[i]; i++)
  13182. {
  13183. str[i] = tolower(str[i]);
  13184. }
  13185. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13186. isSuccess = ConfigurationStatus_Accepted;
  13187. }
  13188. else
  13189. {
  13190. isSuccess = ConfigurationStatus_Rejected;
  13191. }
  13192. }
  13193. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  13194. {
  13195. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  13196. {
  13197. check_ascii = value[0];
  13198. if( (check_ascii < 48) || (check_ascii > 57) )
  13199. {
  13200. isSuccess = ConfigurationStatus_Rejected;
  13201. }
  13202. else
  13203. {
  13204. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  13205. isSuccess = ConfigurationStatus_Accepted;
  13206. }
  13207. }
  13208. else
  13209. {
  13210. isSuccess = ConfigurationStatus_Rejected;
  13211. }
  13212. }
  13213. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  13214. {
  13215. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  13216. {
  13217. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  13218. isSuccess = ConfigurationStatus_Accepted;
  13219. }
  13220. else
  13221. {
  13222. isSuccess = ConfigurationStatus_Rejected;
  13223. }
  13224. }
  13225. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  13226. {
  13227. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  13228. {
  13229. check_ascii = value[0];
  13230. if( (check_ascii < 48) || (check_ascii > 57) )
  13231. {
  13232. isSuccess = ConfigurationStatus_Rejected;
  13233. }
  13234. else
  13235. {
  13236. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  13237. isSuccess = ConfigurationStatus_Accepted;
  13238. }
  13239. }
  13240. else
  13241. {
  13242. isSuccess = ConfigurationStatus_Rejected;
  13243. }
  13244. }
  13245. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  13246. {
  13247. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  13248. {
  13249. strcpy(str, (const char*)value);
  13250. for(int i = 0; str[i]; i++)
  13251. {
  13252. str[i] = tolower(str[i]);
  13253. }
  13254. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13255. isSuccess = ConfigurationStatus_Accepted;
  13256. }
  13257. else
  13258. {
  13259. isSuccess = ConfigurationStatus_Rejected;
  13260. }
  13261. }
  13262. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  13263. {
  13264. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  13265. {
  13266. check_ascii = value[0];
  13267. if( (check_ascii < 48) || (check_ascii > 57) )
  13268. {
  13269. isSuccess = ConfigurationStatus_Rejected;
  13270. }
  13271. else
  13272. {
  13273. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  13274. isSuccess = ConfigurationStatus_Accepted;
  13275. }
  13276. }
  13277. else
  13278. {
  13279. isSuccess = ConfigurationStatus_Rejected;
  13280. }
  13281. }
  13282. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13283. return isSuccess;
  13284. }
  13285. int TransactionMessageAttemptsGet(void)
  13286. {
  13287. return TransactionMessageAttemptsValue;
  13288. }
  13289. int FirstHeartBeatResponse(void)
  13290. {
  13291. return FirstHeartBeat;
  13292. }
  13293. int TransactionMessageRetryIntervalGet(void)
  13294. {
  13295. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13296. }
  13297. int ReadHttpStatus(int sock)
  13298. {
  13299. //char c;
  13300. char buff[1024]="",*ptr=buff+1;
  13301. int bytes_received, status;
  13302. DEBUG_INFO("Begin Response ..\n");
  13303. while((bytes_received = recv(sock, ptr, 1, 0))){
  13304. if(bytes_received==-1){
  13305. perror("ReadHttpStatus");
  13306. exit(1);
  13307. }
  13308. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  13309. ptr++;
  13310. }
  13311. *ptr=0;
  13312. ptr=buff+1;
  13313. sscanf(ptr,"%*s %d ", &status);
  13314. DEBUG_INFO("%s\n",ptr);
  13315. DEBUG_INFO("status=%d\n",status);
  13316. DEBUG_INFO("End Response ..\n");
  13317. return (bytes_received>0)?status:0;
  13318. }
  13319. //the only filed that it parsed is 'Content-Length'
  13320. int ParseHeader(int sock)
  13321. {
  13322. //char c;
  13323. char buff[1024]="",*ptr=buff+4;
  13324. int bytes_received;
  13325. DEBUG_INFO("Begin HEADER ..\n");
  13326. while((bytes_received = recv(sock, ptr, 1, 0))){
  13327. if(bytes_received==-1){
  13328. perror("Parse Header");
  13329. exit(1);
  13330. }
  13331. if(
  13332. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  13333. (ptr[-1]=='\r') && (*ptr=='\n' )
  13334. ) break;
  13335. ptr++;
  13336. }
  13337. *ptr=0;
  13338. ptr=buff+4;
  13339. //printf("%s",ptr);
  13340. if(bytes_received){
  13341. ptr=strstr(ptr,"Content-Length:");
  13342. if(ptr){
  13343. sscanf(ptr,"%*s %d",&bytes_received);
  13344. }else
  13345. bytes_received=-1; //unknown size
  13346. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  13347. }
  13348. DEBUG_INFO("End HEADER ..\n");
  13349. return bytes_received ;
  13350. }
  13351. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  13352. {
  13353. int result = TRUE;
  13354. char rmFileCmd[100]={0};
  13355. char FilePath[100]={0};
  13356. char ftpbuf[200];
  13357. int systemresult;
  13358. //DEBUG_INFO("filename=%s\n",filename);
  13359. //DEBUG_INFO("url=%s\n",url);
  13360. sprintf(FilePath,"/mnt/%s",filename);
  13361. system("ping 8.8.8.8 &");
  13362. if((access(FilePath,F_OK))!=-1)
  13363. {
  13364. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13365. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13366. system(rmFileCmd);
  13367. }
  13368. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13369. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  13370. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13371. systemresult = system(ftpbuf);
  13372. //DEBUG_INFO("systemresult=%d\n",systemresult);
  13373. if(systemresult != 0)
  13374. {
  13375. DEBUG_INFO("http DownLoad error!\n");
  13376. result = FALSE;
  13377. }
  13378. system("pkill ping");
  13379. return result;
  13380. }
  13381. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  13382. {
  13383. int result = TRUE;
  13384. char rmFileCmd[100]={0};
  13385. char FilePath[100]={0};
  13386. char ftpbuf[200];
  13387. int systemresult;
  13388. //char temp[100];
  13389. sprintf(FilePath,"/mnt/%s",filename);
  13390. system("ping 8.8.8.8 &");
  13391. if((access(FilePath,F_OK))!=-1)
  13392. {
  13393. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13394. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13395. system(rmFileCmd);
  13396. }
  13397. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13398. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  13399. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  13400. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  13401. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13402. systemresult = system(ftpbuf);
  13403. //DEBUG_INFO("systemresult=%d\n",systemresult);
  13404. if(systemresult != 0)
  13405. {
  13406. printf("wget error!\n");
  13407. result = FALSE;
  13408. }
  13409. system("pkill ping");
  13410. return result;
  13411. }
  13412. int httpUploadFile(char *location, char *path, char *filename,char *url)
  13413. {
  13414. char rmFileCmd[100]={0};
  13415. char FilePath[100]={0};
  13416. char buf[512];
  13417. int systemresult = 0;
  13418. //DEBUG_INFO("filename=%s\n",filename);
  13419. //DEBUG_INFO("url=%s\n",url);
  13420. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  13421. if((access(FilePath,F_OK))!=-1)
  13422. {
  13423. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13424. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13425. system(rmFileCmd);
  13426. }
  13427. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  13428. if(fp == NULL)
  13429. {
  13430. DEBUG_INFO("log is NULL\n");
  13431. return FALSE;
  13432. }
  13433. else
  13434. {
  13435. fprintf(fp, "%s\n", url);
  13436. fprintf(fp, "%s\n", filename);
  13437. fclose(fp);
  13438. }
  13439. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  13440. if(phpFP == NULL)
  13441. {
  13442. DEBUG_INFO("PHP upload fail.\n");
  13443. return FALSE;
  13444. }
  13445. else
  13446. {
  13447. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  13448. {
  13449. if(strstr(buf, "result") != NULL)
  13450. {
  13451. sscanf(buf, "result: %d", &systemresult);
  13452. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  13453. }
  13454. }
  13455. pclose(phpFP);
  13456. }
  13457. if(systemresult != 1)
  13458. {
  13459. DEBUG_INFO("HTTP upload error!\n");
  13460. return FALSE;
  13461. }
  13462. return TRUE;
  13463. }
  13464. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  13465. {
  13466. struct hostent* server;
  13467. char *IPbuffer;
  13468. char ftpbuf[200];
  13469. int systemresult;
  13470. // To retrieve host information
  13471. server = gethostbyname(location);
  13472. // To convert an Internet network
  13473. // address into ASCII string
  13474. IPbuffer = inet_ntoa(*((struct in_addr*)
  13475. server->h_addr_list[0]));
  13476. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13477. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  13478. /* format : ftpput -u username -p passwd IP target source*/
  13479. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  13480. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  13481. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13482. systemresult = system(ftpbuf);
  13483. DEBUG_INFO("systemresult=%d\n",systemresult);
  13484. if(systemresult != 0)
  13485. {
  13486. DEBUG_INFO("ftpput error!\n");
  13487. return FALSE;
  13488. }
  13489. return TRUE;
  13490. }
  13491. int GetOcppServerURL()
  13492. {
  13493. int result = FALSE;
  13494. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  13495. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  13496. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  13497. struct yuarel url;
  13498. char urlStr[512];
  13499. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  13500. {
  13501. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  13502. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13503. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  13504. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  13505. if(yuarel_parse(&url, urlStr) != -1)
  13506. {
  13507. sprintf(OcppProtocol, "%s", url.scheme);
  13508. sprintf(OcppHost, "%s", url.host);
  13509. if(url.path == NULL)
  13510. OcppTempPath[0] = '\0';
  13511. else
  13512. {
  13513. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  13514. {
  13515. sprintf(OcppTempPath, "%s/", url.path);
  13516. }
  13517. else
  13518. {
  13519. sprintf(OcppTempPath, "%s", url.path);
  13520. }
  13521. }
  13522. if(url.port == 0)
  13523. {
  13524. if(strcmp(OcppProtocol, "wss") == 0)
  13525. OcppPort = 443;
  13526. else
  13527. OcppPort = 80;
  13528. }
  13529. else
  13530. OcppPort = url.port;
  13531. result = TRUE;
  13532. }
  13533. }
  13534. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  13535. {
  13536. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  13537. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13538. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  13539. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  13540. if(yuarel_parse(&url, urlStr) != -1)
  13541. {
  13542. sprintf(OcppProtocol, "%s", url.scheme);
  13543. sprintf(OcppHost, "%s", url.host);
  13544. if(url.path == NULL)
  13545. OcppTempPath[0] = '\0';
  13546. else
  13547. sprintf(OcppTempPath, "%s", url.path);
  13548. if(url.port == 0)
  13549. {
  13550. if(strcmp(OcppProtocol, "wss") == 0)
  13551. OcppPort = 443;
  13552. else
  13553. OcppPort = 80;
  13554. }
  13555. else
  13556. OcppPort = url.port;
  13557. result = TRUE;
  13558. }
  13559. }
  13560. else
  13561. {
  13562. strcpy(OcppHost,"");
  13563. }
  13564. return result;
  13565. }
  13566. int GetOcppPath()
  13567. {
  13568. int result = FALSE;
  13569. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  13570. {
  13571. if(OcppTempPath == NULL)
  13572. {
  13573. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13574. }
  13575. else
  13576. {
  13577. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13578. }
  13579. result = TRUE;
  13580. goto End;
  13581. }
  13582. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  13583. {
  13584. if(OcppTempPath == NULL)
  13585. {
  13586. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  13587. }
  13588. else
  13589. {
  13590. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  13591. }
  13592. result = TRUE;
  13593. goto End;
  13594. }
  13595. else
  13596. {
  13597. strcpy(OcppPath,"");
  13598. }
  13599. End:
  13600. return result;
  13601. }
  13602. int GetOcppPort()
  13603. {
  13604. return OcppPort;
  13605. }
  13606. int GetOcppConnStatus(void)
  13607. {
  13608. return ShmOCPP16Data->OcppConnStatus;
  13609. }
  13610. void SetOcppConnStatus(uint8_t status)
  13611. {
  13612. ShmOCPP16Data->OcppConnStatus = status;
  13613. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  13614. }
  13615. int GetHeartBeatWithNOResponse(void)
  13616. {
  13617. return HeartBeatWithNOResponse;
  13618. }
  13619. void SetHeartBeatWithNOResponse(void)
  13620. {
  13621. HeartBeatWithNOResponse = 0;
  13622. }
  13623. void GetStartTransactionIdTag(int gun_index)
  13624. {
  13625. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  13626. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13627. }
  13628. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  13629. {
  13630. char ch;
  13631. FILE *fptr1;
  13632. int temptransactionId;
  13633. char str[100]={0};
  13634. temptransactionId = 0;
  13635. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  13636. {
  13637. DEBUG_INFO("IdTag is empty.\n");
  13638. return temptransactionId;
  13639. }
  13640. /*------ Read the file ----------------*/
  13641. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  13642. if (!fptr1)
  13643. {
  13644. DEBUG_INFO("QueueTransactionId file open error.\n");
  13645. //printf(" File not found or unable to open the input file!!\n");
  13646. return temptransactionId;
  13647. }
  13648. ch=fgetc(fptr1);
  13649. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  13650. rewind(fptr1);
  13651. if(ch!=EOF)
  13652. {
  13653. // printf("%c",ch);
  13654. while (fgets(str, 100, fptr1) != NULL)
  13655. {
  13656. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13657. if(str[0]=='\0')
  13658. {
  13659. break;
  13660. }
  13661. char *revbuf[8] = {0}; // Variable store string split
  13662. int num = 0;// Quantity after string split
  13663. DEBUG_INFO("Transaction queue data= %s\n", str);
  13664. splitstring(str,",",revbuf,&num); // String split
  13665. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  13666. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  13667. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  13668. DEBUG_INFO("------------------------------\n");
  13669. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  13670. {
  13671. if(isStopTransaction)
  13672. {
  13673. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  13674. {
  13675. temptransactionId = atoi(revbuf[2]);
  13676. //break;
  13677. }
  13678. }
  13679. else
  13680. {
  13681. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  13682. {
  13683. temptransactionId = atoi(revbuf[2]);
  13684. //break;
  13685. }
  13686. }
  13687. }
  13688. }
  13689. }
  13690. else
  13691. DEBUG_INFO("EOF\n");
  13692. fclose(fptr1);
  13693. /*------- End of reading ---------------*/
  13694. return temptransactionId;
  13695. }
  13696. void SetTransactionIdZero(int transactionId)
  13697. {
  13698. char ch;
  13699. FILE *fptr1, *fptr2;
  13700. int temptransactionId = 0;
  13701. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  13702. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  13703. if (!fptr1)
  13704. {
  13705. //printf(" File not found or unable to open the input file!!\n");
  13706. return ;
  13707. }
  13708. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13709. if (!fptr2)
  13710. {
  13711. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  13712. fclose(fptr1);
  13713. return ;
  13714. }
  13715. ch=fgetc(fptr1);
  13716. rewind(fptr1);
  13717. if(ch!=EOF)
  13718. {
  13719. // copy all contents to the temporary file except the specific line
  13720. while (fgets(str, 100, fptr1) != NULL)
  13721. {
  13722. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13723. if(str[0]=='\0')
  13724. {
  13725. break;
  13726. }
  13727. char *revbuf[8] = {0};
  13728. int num = 0;
  13729. strcpy(strtemp, str);
  13730. splitstring(str,",",revbuf,&num);
  13731. if(revbuf[2][0] != '\0')
  13732. {
  13733. temptransactionId = atoi(revbuf[2]);
  13734. if(transactionId != temptransactionId)
  13735. {
  13736. fprintf(fptr2, "%s\n", strtemp);
  13737. }
  13738. }
  13739. }
  13740. }
  13741. fclose(fptr1);
  13742. fclose(fptr2);
  13743. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13744. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13745. /*------ Read the file ----------------*/
  13746. }
  13747. int InternetDisconnect(void)
  13748. {
  13749. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13750. }
  13751. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  13752. void storeTempStopTransaction(int gun_index)
  13753. {
  13754. char guid[37]={0};
  13755. int tempIndex = 0;
  13756. char TempStopTransaction[256];
  13757. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  13758. DEBUG_INFO("storeTempStopTransaction...\n");
  13759. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  13760. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  13761. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  13762. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13763. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  13764. {
  13765. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13766. {
  13767. tempIndex = ((gun_index==2) ? 1: 0);
  13768. }
  13769. else
  13770. {
  13771. tempIndex = gun_index;
  13772. }
  13773. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13774. {
  13775. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13776. {
  13777. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  13778. }
  13779. }// END OF CHAdeMO_QUANTITY
  13780. }
  13781. else if(gunType[gun_index] == GUN_TYPE_CCS)
  13782. {
  13783. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13784. {
  13785. tempIndex = ((gun_index==2) ? 1: 0);
  13786. }
  13787. else
  13788. {
  13789. tempIndex = gun_index;
  13790. }
  13791. for (int index = 0; index < CCS_QUANTITY; index++)
  13792. {
  13793. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13794. {
  13795. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  13796. }
  13797. }// END OF CCS_QUANTITY
  13798. }
  13799. else if(gunType[gun_index] == GUN_TYPE_GBT)
  13800. {
  13801. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13802. {
  13803. tempIndex = ((gun_index==2) ? 1: 0);
  13804. }
  13805. else
  13806. {
  13807. tempIndex = gun_index;
  13808. }
  13809. for (int index = 0; index < GB_QUANTITY; index++)
  13810. {
  13811. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13812. {
  13813. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  13814. }
  13815. }// END OF GB_QUANTITY
  13816. }
  13817. else if(gunType[gun_index] == GUN_TYPE_DO)
  13818. {
  13819. tempIndex = gun_index;
  13820. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13821. {
  13822. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13823. {
  13824. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  13825. }
  13826. }
  13827. }
  13828. else
  13829. {
  13830. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13831. {
  13832. tempIndex = 2;
  13833. }
  13834. else
  13835. {
  13836. tempIndex = gun_index;
  13837. }
  13838. for (int index = 0; index < AC_QUANTITY; index++)
  13839. {
  13840. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13841. {
  13842. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  13843. }
  13844. }// END OF AC_QUANTITY
  13845. }
  13846. //Stop Transaction Time
  13847. struct timeval tmnow;
  13848. struct tm *tm;
  13849. char buf[28];//, usec_buf[6];
  13850. gettimeofday(&tmnow, NULL);
  13851. time_t t;
  13852. t = time(NULL);
  13853. /*UTC time and date*/
  13854. tm = gmtime(&t);
  13855. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  13856. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  13857. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  13858. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13859. random_uuid(guid);
  13860. /***********************************transactionData******************************************************/
  13861. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  13862. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  13863. //=================================
  13864. //1. Transaction_Begin
  13865. //=================================
  13866. //============================== Energy.Active.Import.Interval ===========================================
  13867. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  13868. {
  13869. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  13870. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  13871. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  13872. 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*/]);
  13873. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13874. 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))
  13875. {
  13876. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  13877. }
  13878. else
  13879. {
  13880. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  13881. }
  13882. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  13883. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13884. }
  13885. //=================================
  13886. //2. Transaction_End
  13887. //=================================
  13888. //2.1====================================== Current.Import L1 ==============================================
  13889. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  13890. {
  13891. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  13892. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  13893. {
  13894. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13895. {
  13896. tempIndex = ((gun_index==2) ? 1: 0);
  13897. }
  13898. else
  13899. {
  13900. tempIndex = gun_index;
  13901. }
  13902. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13903. {
  13904. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13905. {
  13906. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13907. }
  13908. }// End of for CHAdeMO_QUANTITY
  13909. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13910. }
  13911. else if(gunType[gun_index] == GUN_TYPE_CCS)
  13912. {
  13913. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13914. {
  13915. tempIndex = ((gun_index==2) ? 1: 0);
  13916. }
  13917. else
  13918. {
  13919. tempIndex = gun_index;
  13920. }
  13921. for (int index = 0; index < CCS_QUANTITY; index++)
  13922. {
  13923. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13924. {
  13925. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13926. }
  13927. }// End of for CCS_QUANTITY
  13928. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13929. }
  13930. else if(gunType[gun_index] == GUN_TYPE_GBT)
  13931. {
  13932. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13933. {
  13934. tempIndex = ((gun_index==2) ? 1: 0);
  13935. }
  13936. else
  13937. {
  13938. tempIndex = gun_index;
  13939. }
  13940. for (int index = 0; index < GB_QUANTITY; index++)
  13941. {
  13942. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13943. {
  13944. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13945. }
  13946. }// End of for GB_QUANTITY
  13947. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13948. }
  13949. else if(gunType[gun_index] == GUN_TYPE_DO)
  13950. {
  13951. tempIndex = gun_index;
  13952. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13953. {
  13954. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13955. {
  13956. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13957. }
  13958. }
  13959. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13960. }
  13961. else
  13962. {
  13963. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13964. {
  13965. tempIndex = 2;
  13966. }
  13967. else
  13968. {
  13969. tempIndex = gun_index;
  13970. }
  13971. for (int index = 0; index < AC_QUANTITY; index++)
  13972. {
  13973. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13974. {
  13975. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  13976. }
  13977. }// End of for AC_QUANTITY
  13978. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13979. }
  13980. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13981. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  13982. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  13983. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13984. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  13985. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13986. }
  13987. //2.2===================================== Energy.Active.Import.Interval ==========================================
  13988. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  13989. {
  13990. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13991. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  13992. {
  13993. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13994. {
  13995. tempIndex = ((gun_index==2) ? 1: 0);
  13996. }
  13997. else
  13998. {
  13999. tempIndex = gun_index;
  14000. }
  14001. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14002. {
  14003. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14004. {
  14005. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14006. }
  14007. }// END OF CHAdeMO_QUANTITY
  14008. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14009. }
  14010. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14011. {
  14012. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14013. {
  14014. tempIndex = ((gun_index==2) ? 1: 0);
  14015. }
  14016. else
  14017. {
  14018. tempIndex = gun_index;
  14019. }
  14020. for (int index = 0; index < CCS_QUANTITY; index++)
  14021. {
  14022. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14023. {
  14024. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14025. }
  14026. }// END OF CCS_QUANTITY
  14027. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14028. }
  14029. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14030. {
  14031. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14032. {
  14033. tempIndex = ((gun_index==2) ? 1: 0);
  14034. }
  14035. else
  14036. {
  14037. tempIndex = gun_index;
  14038. }
  14039. for (int index = 0; index < GB_QUANTITY; index++)
  14040. {
  14041. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14042. {
  14043. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14044. }
  14045. }// END OF GB_QUANTITY
  14046. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14047. }
  14048. else if(gunType[gun_index] == GUN_TYPE_DO)
  14049. {
  14050. tempIndex = gun_index;
  14051. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14052. {
  14053. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14054. {
  14055. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14056. }
  14057. }
  14058. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14059. }
  14060. else
  14061. {
  14062. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14063. {
  14064. tempIndex = 2;
  14065. }
  14066. else
  14067. {
  14068. tempIndex = gun_index;
  14069. }
  14070. for (int index = 0; index < AC_QUANTITY; index++)
  14071. {
  14072. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14073. {
  14074. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14075. }
  14076. }// END OF AC_QUANTITY
  14077. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  14078. }
  14079. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14080. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  14081. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  14082. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  14083. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  14084. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  14085. }
  14086. //2.3====================================== Power.Active.Import =========================================
  14087. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  14088. {
  14089. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14090. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14091. {
  14092. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14093. {
  14094. tempIndex = ((gun_index==2) ? 1: 0);
  14095. }
  14096. else
  14097. {
  14098. tempIndex = gun_index;
  14099. }
  14100. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14101. {
  14102. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14103. {
  14104. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14105. }
  14106. } // End for CHAdeMO_QUANTITY
  14107. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14108. }
  14109. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14110. {
  14111. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14112. {
  14113. tempIndex = ((gun_index==2) ? 1: 0);
  14114. }
  14115. else
  14116. {
  14117. tempIndex = gun_index;
  14118. }
  14119. for (int index = 0; index < CCS_QUANTITY; index++)
  14120. {
  14121. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14122. {
  14123. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14124. }
  14125. } // END for CCS_QUANTITY
  14126. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14127. }
  14128. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14129. {
  14130. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14131. {
  14132. tempIndex = ((gun_index==2) ? 1: 0);
  14133. }
  14134. else
  14135. {
  14136. tempIndex = gun_index;
  14137. }
  14138. for (int index = 0; index < GB_QUANTITY; index++)
  14139. {
  14140. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14141. {
  14142. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14143. }
  14144. }// END for GB_QUANTITY
  14145. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14146. }
  14147. else if(gunType[gun_index] == GUN_TYPE_DO)
  14148. {
  14149. tempIndex = gun_index;
  14150. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14151. {
  14152. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14153. {
  14154. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14155. }
  14156. }
  14157. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14158. }
  14159. else
  14160. {
  14161. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14162. {
  14163. tempIndex = 2;
  14164. }
  14165. else
  14166. {
  14167. tempIndex = gun_index;
  14168. }
  14169. for (int index = 0; index < AC_QUANTITY; index++)
  14170. {
  14171. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14172. {
  14173. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14174. }
  14175. } // END for AC_QUANTITY
  14176. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  14177. }
  14178. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14179. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  14180. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  14181. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  14182. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  14183. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  14184. }
  14185. //2.4====================================== Voltage L1 ====================================================
  14186. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  14187. {
  14188. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14189. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14190. {
  14191. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14192. {
  14193. tempIndex = ((gun_index==2) ? 1: 0);
  14194. }
  14195. else
  14196. {
  14197. tempIndex = gun_index;
  14198. }
  14199. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14200. {
  14201. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14202. {
  14203. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14204. }
  14205. } // END OF FOR CHAdeMO_QUANTITY
  14206. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14207. }
  14208. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14209. {
  14210. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14211. {
  14212. tempIndex = ((gun_index==2) ? 1: 0);
  14213. }
  14214. else
  14215. {
  14216. tempIndex = gun_index;
  14217. }
  14218. for (int index = 0; index < CCS_QUANTITY; index++)
  14219. {
  14220. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14221. {
  14222. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14223. }
  14224. } // END OF FOR CCS_QUANTITY
  14225. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14226. }
  14227. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14228. {
  14229. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14230. {
  14231. tempIndex = ((gun_index==2) ? 1: 0);
  14232. }
  14233. else
  14234. {
  14235. tempIndex = gun_index;
  14236. }
  14237. for (int index = 0; index < GB_QUANTITY; index++)
  14238. {
  14239. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14240. {
  14241. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14242. }
  14243. } // END OF FOR GB_QUANTITY
  14244. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14245. }
  14246. else if(gunType[gun_index] == GUN_TYPE_DO)
  14247. {
  14248. tempIndex = gun_index;
  14249. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14250. {
  14251. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14252. {
  14253. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14254. }
  14255. }
  14256. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14257. }
  14258. else
  14259. {
  14260. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14261. {
  14262. tempIndex = 2;
  14263. }
  14264. else
  14265. {
  14266. tempIndex = gun_index;
  14267. }
  14268. for (int index = 0; index < AC_QUANTITY; index++)
  14269. {
  14270. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14271. {
  14272. 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
  14273. }
  14274. } // END OF FOR AC_QUANTITY
  14275. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  14276. }
  14277. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14278. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  14279. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  14280. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  14281. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  14282. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  14283. }
  14284. //2.5============================================== End SoC =========================================================
  14285. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  14286. {
  14287. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14288. 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))
  14289. {
  14290. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  14291. {
  14292. tempIndex = ((gun_index==2) ? 1: 0);
  14293. }
  14294. else
  14295. {
  14296. tempIndex = gun_index;
  14297. }
  14298. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14299. {
  14300. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14301. {
  14302. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14303. {
  14304. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  14305. }
  14306. }
  14307. }
  14308. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14309. {
  14310. for (int index = 0; index < CCS_QUANTITY; index++)
  14311. {
  14312. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14313. {
  14314. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  14315. }
  14316. }
  14317. }
  14318. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14319. {
  14320. for (int index = 0; index < GB_QUANTITY; index++)
  14321. {
  14322. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14323. {
  14324. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  14325. }
  14326. }
  14327. }
  14328. else if(gunType[gun_index] == GUN_TYPE_DO)
  14329. {
  14330. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14331. {
  14332. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14333. {
  14334. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  14335. }
  14336. }
  14337. }
  14338. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14339. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  14340. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  14341. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  14342. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  14343. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  14344. } // END FOR DC CASE
  14345. }
  14346. //2.6====================================== Current.Import L2 ==============================================
  14347. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  14348. {
  14349. // AC 3 phase L2 current
  14350. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  14351. {
  14352. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14353. {
  14354. tempIndex = 2;
  14355. }
  14356. else
  14357. {
  14358. tempIndex = gun_index;
  14359. }
  14360. for (int index = 0; index < AC_QUANTITY; index++)
  14361. {
  14362. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14363. {
  14364. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  14365. }
  14366. }// End of for AC_QUANTITY
  14367. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  14368. }
  14369. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14370. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  14371. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  14372. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  14373. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14374. }
  14375. //2.7====================================== Current.Import L3 ==============================================
  14376. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  14377. {
  14378. // AC 3 phase L3 current
  14379. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  14380. {
  14381. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14382. {
  14383. tempIndex = 2;
  14384. }
  14385. else
  14386. {
  14387. tempIndex = gun_index;
  14388. }
  14389. for (int index = 0; index < AC_QUANTITY; index++)
  14390. {
  14391. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14392. {
  14393. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  14394. }
  14395. }// End of for AC_QUANTITY
  14396. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  14397. }
  14398. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14399. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  14400. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  14401. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  14402. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14403. }
  14404. //2.9====================================== Voltage L2 ====================================================
  14405. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  14406. {
  14407. // AC 3 phase L2 volatge
  14408. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  14409. {
  14410. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14411. {
  14412. tempIndex = 2;
  14413. }
  14414. else
  14415. {
  14416. tempIndex = gun_index;
  14417. }
  14418. for (int index = 0; index < AC_QUANTITY; index++)
  14419. {
  14420. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14421. {
  14422. 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
  14423. }
  14424. } // END OF FOR AC_QUANTITY
  14425. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  14426. }
  14427. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14428. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  14429. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  14430. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  14431. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  14432. }
  14433. //2.10====================================== Voltage L3 ====================================================
  14434. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  14435. {
  14436. // AC 3 phase L3 volatge
  14437. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  14438. {
  14439. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14440. {
  14441. tempIndex = 2;
  14442. }
  14443. else
  14444. {
  14445. tempIndex = gun_index;
  14446. }
  14447. for (int index = 0; index < AC_QUANTITY; index++)
  14448. {
  14449. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14450. {
  14451. 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
  14452. }
  14453. } // END OF FOR AC_QUANTITY
  14454. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  14455. }
  14456. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14457. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  14458. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  14459. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  14460. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  14461. }
  14462. //====================== Start SoC ================================
  14463. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  14464. {
  14465. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14466. 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))
  14467. {
  14468. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  14469. {
  14470. tempIndex = ((gun_index==2) ? 1: 0);
  14471. }
  14472. else
  14473. {
  14474. tempIndex = gun_index;
  14475. }
  14476. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14477. {
  14478. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14479. {
  14480. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14481. {
  14482. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  14483. }
  14484. }
  14485. }
  14486. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14487. {
  14488. for (int index = 0; index < CCS_QUANTITY; index++)
  14489. {
  14490. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14491. {
  14492. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  14493. }
  14494. }
  14495. }
  14496. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14497. {
  14498. for (int index = 0; index < GB_QUANTITY; index++)
  14499. {
  14500. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14501. {
  14502. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  14503. }
  14504. }
  14505. }
  14506. else if(gunType[gun_index] == GUN_TYPE_DO)
  14507. {
  14508. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14509. {
  14510. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14511. {
  14512. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  14513. }
  14514. }
  14515. }
  14516. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  14517. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  14518. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  14519. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  14520. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  14521. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  14522. } // END FOR DC CASE
  14523. }
  14524. //======================================== Message create ==============================================
  14525. json_object *StopTransaction = json_object_new_object();
  14526. json_object *transactionDatas = json_object_new_array();
  14527. json_object *sampledValues = json_object_new_array();
  14528. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  14529. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  14530. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  14531. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  14532. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  14533. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  14534. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  14535. {
  14536. json_object *transactionData = json_object_new_object();
  14537. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  14538. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  14539. {
  14540. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  14541. {
  14542. json_object *sampledValue = json_object_new_object();
  14543. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  14544. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  14545. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  14546. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  14547. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  14548. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  14549. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  14550. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  14551. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  14552. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  14553. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  14554. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  14555. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  14556. json_object_array_add(sampledValues, sampledValue);
  14557. }
  14558. }
  14559. json_object_object_add(transactionData, "sampledValue", sampledValues);
  14560. json_object_array_add(transactionDatas, transactionData);
  14561. }
  14562. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  14563. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  14564. ,MESSAGE_TYPE_CALL
  14565. ,guid
  14566. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  14567. json_object_put(StopTransaction);
  14568. // Check File "TempStopTransaction" Exist
  14569. if((access(TempStopTransaction,F_OK))!=-1)
  14570. {
  14571. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  14572. fclose(fopen(TempStopTransaction, "w"));
  14573. }
  14574. else
  14575. {
  14576. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  14577. FILE *log = fopen(TempStopTransaction, "w+");
  14578. if(log == NULL)
  14579. {
  14580. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  14581. return ;
  14582. }
  14583. else
  14584. {
  14585. fclose(log);
  14586. }
  14587. }
  14588. //Add TempStopTransaction | Update TempStopTransaction
  14589. // open file for writing
  14590. FILE *outfile;
  14591. outfile = fopen (TempStopTransaction, "a");
  14592. //DEBUG_INFO("data = %s\n", queuedata);
  14593. fputs(queuedata, outfile);
  14594. fputs("\n", outfile);
  14595. fclose (outfile);
  14596. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14597. }
  14598. void checkTempStopTransaction(int gun_index)
  14599. {
  14600. FILE *fptr1;
  14601. char ch;
  14602. char str[QUEUE_MESSAGE_LENGTH]={0};
  14603. char guid[37]={0};
  14604. char tempdata[65]={0};
  14605. char connectorStr[2]={0};
  14606. char TempStopTransaction[256];
  14607. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  14608. fptr1 = fopen(TempStopTransaction, "r");
  14609. //TempStopTransaction格式: 槍號,StopTransaction封包
  14610. if (!fptr1)
  14611. {
  14612. //printf(" File not found or unable to open the input file!!\n");
  14613. return ;
  14614. }
  14615. ch=fgetc(fptr1);
  14616. //printf(" Now the content of the file %s is : \n",fname);
  14617. rewind(fptr1);
  14618. if(ch!=EOF)
  14619. {
  14620. // copy all contents to the temporary file except the specific line
  14621. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  14622. {
  14623. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14624. if(str[0]=='\0')
  14625. {
  14626. break;
  14627. }
  14628. //TempStopTransaction格式: 槍號,StopTransaction封包
  14629. strncpy(connectorStr, str, 1);
  14630. if(atoi(connectorStr) != (gun_index+1))
  14631. {
  14632. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  14633. fclose(fptr1);
  14634. return ;
  14635. }
  14636. //random_uuid(guid);
  14637. strncpy(guid, str+6, 36); //copy guid
  14638. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  14639. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  14640. {
  14641. //DEBUG_INFO("StopTransaction mapitem pass\n");
  14642. }
  14643. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  14644. OCPP_insert_transaction_msg(NO, str);
  14645. memset(str,0,ARRAY_SIZE(str));
  14646. }
  14647. }
  14648. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  14649. fclose(fptr1);
  14650. remove(TempStopTransaction); // remove the original file
  14651. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14652. }
  14653. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  14654. {
  14655. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  14656. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  14657. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  14658. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  14659. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  14660. }
  14661. int GetWebSocketPingInterval(void)
  14662. {
  14663. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14664. }
  14665. int GetServerSign(void)
  14666. {
  14667. return server_sign;
  14668. }
  14669. uint8_t GetOcppSecurityProfile()
  14670. {
  14671. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14672. }
  14673. void GetOcppChargerBoxId(uint8_t *data)
  14674. {
  14675. sprintf((char*)data, "%s", ShmOCPP16Data->ChargeBoxId);
  14676. }
  14677. void GetOcppSecurityPassword(uint8_t *data)
  14678. {
  14679. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14680. }
  14681. void SetOcppVersion(uint8_t *version)
  14682. {
  14683. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  14684. DEBUG_INFO("ocpp version: %s\n", version);
  14685. if(strstr((char*)version, "ocpp1.6") != NULL)
  14686. {
  14687. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  14688. }
  14689. else if(strstr((char*)version, "ocpp2.0") != NULL)
  14690. {
  14691. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  14692. system("pkill OcppBackend");
  14693. }
  14694. }
  14695. void SetServerSign(int value)
  14696. {
  14697. server_sign = value;
  14698. }
  14699. int GetBootNotificationInterval(void)
  14700. {
  14701. return BootNotificationInterval;
  14702. }
  14703. int GetInternetConn(void)
  14704. {
  14705. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  14706. }
  14707. int isConnectorInitMode(int gun_index)
  14708. {
  14709. int tempIndex = 0;
  14710. int result = TRUE;
  14711. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14712. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14713. {
  14714. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14715. {
  14716. tempIndex = ((gun_index==2) ? 1: 0);
  14717. }
  14718. else
  14719. {
  14720. tempIndex = gun_index;
  14721. }
  14722. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14723. {
  14724. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  14725. {
  14726. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  14727. } //end of the same index
  14728. }//end of for CHAdeMO_QUANTITY
  14729. }
  14730. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14731. {
  14732. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14733. {
  14734. tempIndex = ((gun_index==2) ? 1: 0);
  14735. }
  14736. else
  14737. {
  14738. tempIndex = gun_index;
  14739. }
  14740. for (int index = 0; index < CCS_QUANTITY; index++)
  14741. {
  14742. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14743. {
  14744. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  14745. } //end of the same index
  14746. } // end of for CCS_QUANTITY
  14747. }
  14748. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14749. {
  14750. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14751. {
  14752. tempIndex = ((gun_index==2) ? 1: 0);
  14753. }
  14754. else
  14755. {
  14756. tempIndex = gun_index;
  14757. }
  14758. for (int index = 0; index < GB_QUANTITY; index++)
  14759. {
  14760. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14761. {
  14762. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  14763. } //end of the same index
  14764. } // end of for GB_QUANTITY
  14765. }
  14766. else if(gunType[gun_index] == GUN_TYPE_DO)
  14767. {
  14768. tempIndex = gun_index;
  14769. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14770. {
  14771. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14772. {
  14773. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  14774. } //end of the same index
  14775. }
  14776. }
  14777. else
  14778. {
  14779. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14780. {
  14781. tempIndex = 2;
  14782. }
  14783. else
  14784. {
  14785. tempIndex = gun_index;
  14786. }
  14787. for (int index = 0; index < AC_QUANTITY; index++)
  14788. {
  14789. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14790. {
  14791. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  14792. }//end of the same index
  14793. }//end of for AC_QUANTITY
  14794. }
  14795. return result;
  14796. }
  14797. void refreshProcDogTimer()
  14798. {
  14799. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  14800. }
  14801. void InitialSystemValue(void)
  14802. {
  14803. int connectorIndex = 0;
  14804. //int valueASCII = 0;
  14805. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14806. gunTotalNumber=0;
  14807. SystemInitial = 0;
  14808. localversion=0;
  14809. BootNotificationInterval = 0;
  14810. authorizeRetryTimes = 0;
  14811. GunStatusInterval = 10;
  14812. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14813. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14814. //Hear Beat
  14815. HeartBeatWithNOResponse = 0;
  14816. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  14817. FirstHeartBeat = 0;
  14818. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  14819. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  14820. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  14821. memset(statusModeChage, 0, ARRAY_SIZE(statusModeChage));
  14822. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  14823. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  14824. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  14825. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  14826. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  14827. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  14828. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  14829. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  14830. memset(gunType, 0, ARRAY_SIZE(gunType));
  14831. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14832. {
  14833. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O')
  14834. {
  14835. // DO series
  14836. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  14837. {
  14838. SystemInitial = SystemInitial + 1;
  14839. gunTotalNumber = gunTotalNumber + 1;
  14840. gunType[connectorIndex] = GUN_TYPE_DO;
  14841. connectorIndex = connectorIndex + 1;
  14842. }
  14843. }
  14844. else
  14845. {
  14846. // DM, DW, DS series
  14847. //check connector / socket type (index: 8, 9, 10)
  14848. for(int index=7; index <10 ; index++)
  14849. {
  14850. if(index != 8)
  14851. {
  14852. // DC Connector
  14853. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  14854. {
  14855. SystemInitial = SystemInitial + 1;
  14856. gunTotalNumber = gunTotalNumber + 1;
  14857. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  14858. connectorIndex = connectorIndex + 1;
  14859. }
  14860. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  14861. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  14862. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  14863. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  14864. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  14865. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  14866. {
  14867. SystemInitial = SystemInitial + 1;
  14868. gunTotalNumber = gunTotalNumber + 1;
  14869. gunType[connectorIndex] = GUN_TYPE_CCS;
  14870. connectorIndex = connectorIndex + 1;
  14871. }
  14872. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  14873. {
  14874. SystemInitial = SystemInitial + 1;
  14875. gunTotalNumber = gunTotalNumber + 1;
  14876. gunType[connectorIndex] = GUN_TYPE_GBT;
  14877. connectorIndex = connectorIndex + 1;
  14878. }
  14879. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  14880. {
  14881. SystemInitial = SystemInitial + 1;
  14882. gunTotalNumber = gunTotalNumber + 1;
  14883. gunType[connectorIndex] = GUN_TYPE_DO;
  14884. connectorIndex = connectorIndex + 1;
  14885. }
  14886. }
  14887. else
  14888. {
  14889. // AC Connector
  14890. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14891. {
  14892. SystemInitial = SystemInitial + 1;
  14893. gunTotalNumber = gunTotalNumber + 1;
  14894. gunType[connectorIndex] = GUN_TYPE_AC;
  14895. connectorIndex = connectorIndex + 1;
  14896. }
  14897. }
  14898. }
  14899. }
  14900. //DEBUG_INFO("DC ...\n");
  14901. }
  14902. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  14903. {
  14904. //check connector / socket type (index: 8, 9, 10)
  14905. for(int index=7; index <10 ; index++)
  14906. {
  14907. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14908. {
  14909. SystemInitial = SystemInitial + 1;
  14910. gunTotalNumber = gunTotalNumber + 1;
  14911. gunType[connectorIndex] = GUN_TYPE_AC;
  14912. connectorIndex = connectorIndex + 1;
  14913. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  14914. }
  14915. }
  14916. }
  14917. //Status && ConnectorPlugIn Setting
  14918. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14919. {
  14920. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  14921. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  14922. }
  14923. for (int index = 0; index < CCS_QUANTITY; index++)
  14924. {
  14925. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  14926. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  14927. }
  14928. for (int index = 0; index < GB_QUANTITY; index++)
  14929. {
  14930. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  14931. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  14932. }
  14933. for (int index = 0; index < AC_QUANTITY; index++)
  14934. {
  14935. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  14936. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  14937. }
  14938. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14939. {
  14940. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  14941. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  14942. }
  14943. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  14944. {
  14945. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  14946. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  14947. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  14948. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  14949. }
  14950. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  14951. clientTime.Heartbeat=time((time_t*)NULL);
  14952. sleep(1);
  14953. }
  14954. void LWS_Send(char * str)
  14955. {
  14956. //=====================================================
  14957. // Check InternetConn 0: disconnected, 1: connected
  14958. //====================================================
  14959. if(GetOcppConnStatus() == 0)
  14960. {
  14961. DEBUG_INFO("offline now !!!\n");
  14962. return;
  14963. }
  14964. pthread_mutex_lock(&lock_send);
  14965. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14966. sprintf((char *)SendBuffer, "%s", str);
  14967. SendBufLen = strlen(str);
  14968. pthread_mutex_unlock(&lock_send);
  14969. lws_callback_on_writable(wsi_client);
  14970. //lws_service(context, 0);
  14971. //sleep(1);
  14972. }
  14973. void LWS_SendNow(char * str)
  14974. {
  14975. //=====================================================
  14976. // Check InternetConn 0: disconnected, 1: connected
  14977. //====================================================
  14978. if(GetOcppConnStatus() == 0)
  14979. {
  14980. DEBUG_INFO("offline now !!!\n");
  14981. return;
  14982. }
  14983. pthread_mutex_lock(&lock_send);
  14984. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14985. sprintf((char *)SendBuffer, "%s", str);
  14986. SendBufLen = strlen(str);
  14987. pthread_mutex_unlock(&lock_send);
  14988. lws_callback_on_writable(wsi_client);
  14989. lws_service(context, 0);
  14990. //sleep(1);
  14991. }