MessageHandler.c 729 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107
  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. //==========================================
  633. // GetCompositeSchedule logic related function
  634. //==========================================
  635. int DiffTimebSec(struct timeb ST, struct timeb ET)
  636. {
  637. //return milli-second
  638. unsigned int StartTime,StopTime;
  639. StartTime=(unsigned int)ST.time;
  640. StopTime=(unsigned int)ET.time;
  641. return (StopTime-StartTime);
  642. }
  643. int DiffTimebWithNowSec(struct timeb ST)
  644. {
  645. //return milli-second
  646. struct timeb ET;
  647. unsigned int StartTime,StopTime;
  648. ftime(&ET);
  649. StartTime=(unsigned int)ST.time;
  650. StopTime=(unsigned int)ET.time;
  651. return (StopTime-StartTime);
  652. }
  653. int getStartStop(uint8_t *start, uint8_t *stop)
  654. {
  655. int result = -1;
  656. struct tm tmStart;
  657. struct timeb tbStart;
  658. struct tm tmStop;
  659. struct timeb tbStop;
  660. 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) &&
  661. (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))
  662. {
  663. //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);
  664. //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);
  665. tmStart.tm_year -= 1900;
  666. tmStart.tm_mon -= 1;
  667. tbStart.time = mktime(&tmStart);
  668. tbStart.millitm = 0;
  669. tmStop.tm_year -= 1900;
  670. tmStop.tm_mon -= 1;
  671. tbStop.time = mktime(&tmStop);
  672. tbStop.millitm = 0;
  673. result = DiffTimebSec(tbStart, tbStop);
  674. //DEBUG_INFO("getStartStop(): %d\n", result);
  675. }
  676. else
  677. {
  678. DEBUG_WARN("Start or stop date parsing error.\r\n");
  679. }
  680. return result;
  681. }
  682. int isOvertNow(uint8_t *start)
  683. {
  684. int result = NO;
  685. struct tm tmStart;
  686. struct timeb tbStart;
  687. 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))
  688. {
  689. //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);
  690. tmStart.tm_year -= 1900;
  691. tmStart.tm_mon -= 1;
  692. tbStart.time = mktime(&tmStart);
  693. tbStart.millitm = 0;
  694. if(DiffTimebWithNowSec(tbStart) <= 0)
  695. result = NO;
  696. else
  697. result = YES;
  698. }
  699. else
  700. {
  701. DEBUG_WARN("Start date parsing error.\n");
  702. }
  703. return result;
  704. }
  705. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  706. {
  707. int result = -1;
  708. struct tm tmStart;
  709. struct timeb tbStart;
  710. struct tm tmStop;
  711. struct timeb tbStop;
  712. 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) &&
  713. (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))
  714. {
  715. tmStart.tm_year -= 1900;
  716. tmStart.tm_mon -= 1;
  717. tbStart.time = mktime(&tmStart);
  718. tbStart.millitm = 0;
  719. tmStop.tm_year -= 1900;
  720. tmStop.tm_mon -= 1;
  721. tbStop.time = mktime(&tmStop);
  722. tbStop.millitm = 0;
  723. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  724. }
  725. return result;
  726. }
  727. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  728. {
  729. FILE *fp;
  730. char profileFileName[128];
  731. char *line = NULL;
  732. size_t len = 0;
  733. time_t CurrentTime;
  734. struct tm *tmComposite;
  735. struct StructChargingProfile maxProfile;
  736. struct StructChargingProfile defaultTxProfile;
  737. struct StructChargingProfile txProfile;
  738. struct StructChargingSchedulePeriod tmpPeriod;
  739. uint8_t limitMax=0;
  740. uint8_t limitDef=0;
  741. uint8_t limitTx=0;
  742. int compositePeriodIdx = 0;
  743. CurrentTime = time(NULL);
  744. tmComposite=localtime(&CurrentTime);
  745. 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);
  746. if(isUnitA)
  747. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  748. else
  749. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  750. compositeProfile->ChargingSchedule.Duration = durationReq;
  751. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  752. {
  753. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  754. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  755. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  756. }
  757. compositeProfile->ChargingProfileId = 0;
  758. compositeProfile->StackLevel = 99 ;
  759. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  760. maxProfile.ChargingProfileId = -1;
  761. defaultTxProfile.ChargingProfileId = -1;
  762. txProfile.ChargingProfileId = -1;
  763. maxProfile.ChargingSchedule.Duration = -1;
  764. defaultTxProfile.ChargingSchedule.Duration = -1;
  765. txProfile.ChargingSchedule.Duration = -1;
  766. system("yes|rm /tmp/*.json");
  767. system("cp /Storage/OCPP/*.json /tmp");
  768. /*
  769. * Search valid charging profile
  770. */
  771. //DEBUG_INFO("====================================\n");
  772. // Search tx profile
  773. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  774. if((access(profileFileName, F_OK))!=-1)
  775. {
  776. fp = fopen(profileFileName, "r");
  777. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  778. {
  779. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  780. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  781. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  782. }
  783. txProfile.ChargingProfileId = -1;
  784. txProfile.StackLevel = -1;
  785. while(getline(&line, &len, fp) != -1)
  786. {
  787. json_object *obj = NULL;
  788. obj = json_tokener_parse(line);
  789. if(is_error(obj))
  790. {
  791. DEBUG_ERROR("Parse txProfile from file error.\n");
  792. }
  793. else
  794. {
  795. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  796. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  797. )
  798. {
  799. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  800. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  801. )
  802. {
  803. struct tm tmFrom, tmTo;
  804. struct timeb tbFrom, tbTo;
  805. 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) &&
  806. (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))
  807. {
  808. tmFrom.tm_year -= 1900;
  809. tmFrom.tm_mon -= 1;
  810. tbFrom.time = mktime(&tmFrom);
  811. tmTo.tm_year -= 1900;
  812. tmTo.tm_mon -= 1;
  813. tbTo.time = mktime(&tmTo);
  814. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  815. {
  816. if(txProfile.ChargingProfileId == -1)
  817. DEBUG_INFO("TxProfile found.\n");
  818. else
  819. DEBUG_INFO("TxProfile updated.\n");
  820. // Required item
  821. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  822. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  823. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  824. if(isUnitA)
  825. {
  826. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  827. 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++)
  828. {
  829. 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"));
  830. 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?
  831. 3:
  832. 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")));
  833. 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")));
  834. }
  835. }
  836. else
  837. {
  838. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  839. 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++)
  840. {
  841. 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"));
  842. 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?
  843. 3:
  844. 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")));
  845. 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));
  846. }
  847. }
  848. // Optional item
  849. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  850. {
  851. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  852. }
  853. else
  854. {
  855. sprintf((char*)txProfile.ValidFrom, " ");
  856. }
  857. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  858. {
  859. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  860. }
  861. else
  862. {
  863. sprintf((char*)txProfile.ValidTo, " ");
  864. }
  865. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  866. {
  867. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  868. }
  869. else
  870. {
  871. sprintf((char*)txProfile.RecurrencyKind, " ");
  872. }
  873. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  874. {
  875. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  876. }
  877. else
  878. {
  879. txProfile.TransactionId = -1;
  880. }
  881. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  882. {
  883. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  884. }
  885. else
  886. {
  887. txProfile.ChargingSchedule.Duration = 86400;
  888. }
  889. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  890. {
  891. 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")));
  892. }
  893. else
  894. {
  895. 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));
  896. }
  897. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  898. {
  899. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  900. }
  901. else
  902. {
  903. txProfile.ChargingSchedule.MinChargingRate = -1;
  904. }
  905. }
  906. }
  907. }
  908. else
  909. {
  910. if(txProfile.ChargingProfileId == -1)
  911. DEBUG_INFO("TxProfile found.\n");
  912. else
  913. DEBUG_INFO("TxProfile updated.\n");
  914. // Required item
  915. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  916. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  917. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  918. if(isUnitA)
  919. {
  920. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  921. 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++)
  922. {
  923. 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"));
  924. 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?
  925. 3:
  926. 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")));
  927. 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")));
  928. }
  929. }
  930. else
  931. {
  932. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  933. 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++)
  934. {
  935. 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"));
  936. 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?
  937. 3:
  938. 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")));
  939. 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));
  940. }
  941. }
  942. // Optional item
  943. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  944. {
  945. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  946. }
  947. else
  948. {
  949. sprintf((char*)txProfile.ValidFrom, " ");
  950. }
  951. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  952. {
  953. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  954. }
  955. else
  956. {
  957. sprintf((char*)txProfile.ValidTo, " ");
  958. }
  959. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  960. {
  961. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  962. }
  963. else
  964. {
  965. sprintf((char*)txProfile.RecurrencyKind, " ");
  966. }
  967. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  968. {
  969. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  970. }
  971. else
  972. {
  973. txProfile.TransactionId = -1;
  974. }
  975. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  976. {
  977. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  978. }
  979. else
  980. {
  981. txProfile.ChargingSchedule.Duration = 86400;
  982. }
  983. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  984. {
  985. 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")));
  986. }
  987. else
  988. {
  989. 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));
  990. }
  991. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  992. {
  993. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  994. }
  995. else
  996. {
  997. txProfile.ChargingSchedule.MinChargingRate = -1;
  998. }
  999. }
  1000. }
  1001. }
  1002. json_object_put(obj);
  1003. }
  1004. fclose(fp);
  1005. /*
  1006. if(txProfile.ChargingProfileId != -1)
  1007. {
  1008. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1009. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1010. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1011. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1012. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1013. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1014. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1015. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1016. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1017. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1018. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1019. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1020. {
  1021. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1022. {
  1023. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1024. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1025. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1026. }
  1027. }
  1028. }
  1029. else
  1030. DEBUG_INFO("TxProfile not found.\n");*/
  1031. }
  1032. // Search default tx profile
  1033. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1034. if((access(profileFileName, F_OK))==-1)
  1035. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1036. if((access(profileFileName, F_OK))!=-1)
  1037. {
  1038. fp = fopen(profileFileName, "r");
  1039. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1040. {
  1041. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1042. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1043. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1044. }
  1045. defaultTxProfile.ChargingProfileId = -1;
  1046. defaultTxProfile.StackLevel = -1;
  1047. while(getline(&line, &len, fp) != -1)
  1048. {
  1049. json_object *obj = NULL;
  1050. obj = json_tokener_parse(line);
  1051. if(is_error(obj))
  1052. {
  1053. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1054. }
  1055. else
  1056. {
  1057. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1058. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1059. )
  1060. {
  1061. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1062. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1063. )
  1064. {
  1065. struct tm tmFrom, tmTo;
  1066. struct timeb tbFrom, tbTo;
  1067. 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) &&
  1068. (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))
  1069. {
  1070. tmFrom.tm_year -= 1900;
  1071. tmFrom.tm_mon -= 1;
  1072. tbFrom.time = mktime(&tmFrom);
  1073. tmTo.tm_year -= 1900;
  1074. tmTo.tm_mon -= 1;
  1075. tbTo.time = mktime(&tmTo);
  1076. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1077. {
  1078. if(defaultTxProfile.ChargingProfileId == -1)
  1079. DEBUG_INFO("TxDefaultProfile found.\n");
  1080. else
  1081. DEBUG_INFO("TxDefaultProfile updated.\n");
  1082. // Required item
  1083. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1084. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1085. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1086. if(isUnitA)
  1087. {
  1088. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1089. 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++)
  1090. {
  1091. 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"));
  1092. 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?
  1093. 3:
  1094. 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")));
  1095. 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")));
  1096. }
  1097. }
  1098. else
  1099. {
  1100. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1101. 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++)
  1102. {
  1103. 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"));
  1104. 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?
  1105. 3:
  1106. 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")));
  1107. 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));
  1108. }
  1109. }
  1110. // Optional item
  1111. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1112. {
  1113. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1114. }
  1115. else
  1116. {
  1117. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1118. }
  1119. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1120. {
  1121. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1122. }
  1123. else
  1124. {
  1125. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1126. }
  1127. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1128. {
  1129. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1130. }
  1131. else
  1132. {
  1133. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1134. }
  1135. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1136. {
  1137. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1138. }
  1139. else
  1140. {
  1141. defaultTxProfile.TransactionId = -1;
  1142. }
  1143. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1144. {
  1145. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1146. }
  1147. else
  1148. {
  1149. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1150. }
  1151. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1152. {
  1153. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1154. }
  1155. else
  1156. {
  1157. sprintf((char*)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));
  1158. }
  1159. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1160. {
  1161. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1162. }
  1163. else
  1164. {
  1165. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1166. }
  1167. }
  1168. }
  1169. }
  1170. else
  1171. {
  1172. if(defaultTxProfile.ChargingProfileId == -1)
  1173. DEBUG_INFO("TxDefaultProfile found.\n");
  1174. else
  1175. DEBUG_INFO("TxDefaultProfile updated.\n");
  1176. // Required item
  1177. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1178. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1179. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1180. if(isUnitA)
  1181. {
  1182. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1183. 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++)
  1184. {
  1185. 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"));
  1186. 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?
  1187. 3:
  1188. 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")));
  1189. 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")));
  1190. }
  1191. }
  1192. else
  1193. {
  1194. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1195. 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++)
  1196. {
  1197. 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"));
  1198. 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?
  1199. 3:
  1200. 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")));
  1201. 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));
  1202. }
  1203. }
  1204. // Optional item
  1205. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1206. {
  1207. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1208. }
  1209. else
  1210. {
  1211. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1212. }
  1213. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1214. {
  1215. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1216. }
  1217. else
  1218. {
  1219. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1220. }
  1221. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1222. {
  1223. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1224. }
  1225. else
  1226. {
  1227. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1228. }
  1229. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1230. {
  1231. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1232. }
  1233. else
  1234. {
  1235. defaultTxProfile.TransactionId = -1;
  1236. }
  1237. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1238. {
  1239. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1240. }
  1241. else
  1242. {
  1243. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1244. }
  1245. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1246. {
  1247. 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")));
  1248. }
  1249. else
  1250. {
  1251. 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));
  1252. }
  1253. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1254. {
  1255. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1256. }
  1257. else
  1258. {
  1259. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1260. }
  1261. }
  1262. }
  1263. }
  1264. json_object_put(obj);
  1265. }
  1266. fclose(fp);
  1267. /*
  1268. if(defaultTxProfile.ChargingProfileId != -1)
  1269. {
  1270. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1271. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1272. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1273. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1274. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1275. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1276. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1277. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  1278. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1279. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1280. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1281. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1282. {
  1283. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1284. {
  1285. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1286. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1287. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1288. }
  1289. }
  1290. }
  1291. else
  1292. DEBUG_INFO("TxDefaultProfile not found.\n");
  1293. DEBUG_INFO("------------------------------------\n");*/
  1294. }
  1295. // Search max profile
  1296. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1297. if((access(profileFileName, F_OK))!=-1)
  1298. {
  1299. fp = fopen(profileFileName, "r");
  1300. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1301. {
  1302. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1303. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1304. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1305. }
  1306. maxProfile.ChargingProfileId = -1;
  1307. maxProfile.StackLevel = -1;
  1308. while(getline(&line, &len, fp) != -1)
  1309. {
  1310. json_object *obj = NULL;
  1311. obj = json_tokener_parse(line);
  1312. if(is_error(obj))
  1313. {
  1314. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1315. }
  1316. else
  1317. {
  1318. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  1319. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1320. )
  1321. {
  1322. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1323. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1324. )
  1325. {
  1326. struct tm tmFrom, tmTo;
  1327. struct timeb tbFrom, tbTo;
  1328. 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) &&
  1329. (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))
  1330. {
  1331. tmFrom.tm_year -= 1900;
  1332. tmFrom.tm_mon -= 1;
  1333. tbFrom.time = mktime(&tmFrom);
  1334. tmTo.tm_year -= 1900;
  1335. tmTo.tm_mon -= 1;
  1336. tbTo.time = mktime(&tmTo);
  1337. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1338. {
  1339. if(maxProfile.ChargingProfileId == -1)
  1340. DEBUG_INFO("MaxProfile found.\n");
  1341. else
  1342. DEBUG_INFO("MaxProfile updated.\n");
  1343. // Required item
  1344. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1345. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1346. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1347. if(isUnitA)
  1348. {
  1349. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1350. 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++)
  1351. {
  1352. 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"));
  1353. 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?
  1354. 3:
  1355. 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")));
  1356. 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")));
  1357. }
  1358. }
  1359. else
  1360. {
  1361. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1362. 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++)
  1363. {
  1364. 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"));
  1365. 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?
  1366. 3:
  1367. 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")));
  1368. 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));
  1369. }
  1370. }
  1371. // Optional item
  1372. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1373. {
  1374. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1375. }
  1376. else
  1377. {
  1378. sprintf((char*)maxProfile.ValidFrom, " ");
  1379. }
  1380. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1381. {
  1382. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1383. }
  1384. else
  1385. {
  1386. sprintf((char*)maxProfile.ValidTo, " ");
  1387. }
  1388. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1389. {
  1390. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1391. }
  1392. else
  1393. {
  1394. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1395. }
  1396. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1397. {
  1398. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1399. }
  1400. else
  1401. {
  1402. maxProfile.TransactionId = -1;
  1403. }
  1404. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1405. {
  1406. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1407. }
  1408. else
  1409. {
  1410. maxProfile.ChargingSchedule.Duration = 86400;
  1411. }
  1412. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1413. {
  1414. 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")));
  1415. }
  1416. else
  1417. {
  1418. 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));
  1419. }
  1420. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1421. {
  1422. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1423. }
  1424. else
  1425. {
  1426. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1427. }
  1428. }
  1429. }
  1430. }
  1431. else
  1432. {
  1433. if(maxProfile.ChargingProfileId == -1)
  1434. DEBUG_INFO("MaxProfile found.\n");
  1435. else
  1436. DEBUG_INFO("MaxProfile updated.\n");
  1437. // Required item
  1438. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1439. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1440. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1441. if(isUnitA)
  1442. {
  1443. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1444. 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++)
  1445. {
  1446. 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"));
  1447. 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?
  1448. 3:
  1449. 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")));
  1450. 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")));
  1451. }
  1452. }
  1453. else
  1454. {
  1455. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1456. 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++)
  1457. {
  1458. 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"));
  1459. 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?
  1460. 3:
  1461. 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")));
  1462. 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));
  1463. }
  1464. }
  1465. // Optional item
  1466. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1467. {
  1468. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1469. }
  1470. else
  1471. {
  1472. sprintf((char*)maxProfile.ValidFrom, " ");
  1473. }
  1474. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1475. {
  1476. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1477. }
  1478. else
  1479. {
  1480. sprintf((char*)maxProfile.ValidTo, " ");
  1481. }
  1482. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1483. {
  1484. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1485. }
  1486. else
  1487. {
  1488. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1489. }
  1490. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1491. {
  1492. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1493. }
  1494. else
  1495. {
  1496. maxProfile.TransactionId = -1;
  1497. }
  1498. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1499. {
  1500. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1501. }
  1502. else
  1503. {
  1504. maxProfile.ChargingSchedule.Duration = 86400;
  1505. }
  1506. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1507. {
  1508. 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")));
  1509. }
  1510. else
  1511. {
  1512. 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));
  1513. }
  1514. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1515. {
  1516. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1517. }
  1518. else
  1519. {
  1520. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1521. }
  1522. }
  1523. }
  1524. }
  1525. json_object_put(obj);
  1526. }
  1527. fclose(fp);
  1528. /*
  1529. if(maxProfile.ChargingProfileId !=-1)
  1530. {
  1531. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1532. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1533. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1534. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1535. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1536. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1537. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1538. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1539. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1540. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1541. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1542. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1543. {
  1544. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1545. {
  1546. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1547. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1548. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1549. }
  1550. }
  1551. }
  1552. else
  1553. DEBUG_INFO("MaxProfile not found.\n");
  1554. DEBUG_INFO("------------------------------------\n");*/
  1555. }
  1556. /*
  1557. * Align found profile start schedule & periods
  1558. */
  1559. //DEBUG_INFO("====================================\n");
  1560. /*
  1561. // For local test usage, force modify found profile start schedule info
  1562. 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);
  1563. 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);
  1564. 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);
  1565. */
  1566. if(txProfile.ChargingProfileId != -1)
  1567. {
  1568. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  1569. {
  1570. if(txProfile.ChargingSchedule.Duration != -1)
  1571. {
  1572. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1573. 0:
  1574. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1575. }
  1576. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1577. {
  1578. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1579. {
  1580. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1581. 0:
  1582. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1583. if(idxPeriod > 0)
  1584. {
  1585. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1586. {
  1587. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1588. }
  1589. }
  1590. }
  1591. }
  1592. }
  1593. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  1594. {
  1595. if(txProfile.ChargingSchedule.Duration != -1)
  1596. {
  1597. 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?
  1598. 0:
  1599. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1600. }
  1601. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1602. {
  1603. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1604. {
  1605. 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?
  1606. 0:
  1607. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1608. if(idxPeriod > 0)
  1609. {
  1610. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1611. {
  1612. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1613. }
  1614. }
  1615. }
  1616. }
  1617. }
  1618. else
  1619. {
  1620. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  1621. {
  1622. if(txProfile.ChargingSchedule.Duration != -1)
  1623. {
  1624. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1625. 0:
  1626. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1627. }
  1628. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1629. {
  1630. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1631. {
  1632. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1633. 0:
  1634. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1635. if(idxPeriod > 0)
  1636. {
  1637. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1638. {
  1639. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1640. }
  1641. }
  1642. }
  1643. }
  1644. }
  1645. else
  1646. {
  1647. if(txProfile.ChargingSchedule.Duration != -1)
  1648. {
  1649. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1650. 0:
  1651. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1652. }
  1653. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1654. {
  1655. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1656. {
  1657. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1658. 0:
  1659. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1660. if(idxPeriod > 0)
  1661. {
  1662. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1663. {
  1664. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1665. }
  1666. }
  1667. }
  1668. }
  1669. }
  1670. }
  1671. /*
  1672. DEBUG_INFO("txProfile after align.\n");
  1673. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1674. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1675. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1676. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1677. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1678. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1679. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1680. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1681. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1682. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1683. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1684. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1685. {
  1686. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1687. {
  1688. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1689. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1690. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1691. }
  1692. }*/
  1693. }
  1694. if(defaultTxProfile.ChargingProfileId != -1)
  1695. {
  1696. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  1697. {
  1698. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1699. {
  1700. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1701. 0:
  1702. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1703. }
  1704. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1705. {
  1706. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1707. {
  1708. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1709. 0:
  1710. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1711. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1712. {
  1713. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1714. }
  1715. if(idxPeriod > 0)
  1716. {
  1717. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1718. {
  1719. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1720. }
  1721. }
  1722. }
  1723. }
  1724. }
  1725. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  1726. {
  1727. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1728. {
  1729. 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?
  1730. 0:
  1731. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1732. }
  1733. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1734. {
  1735. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1736. {
  1737. 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?
  1738. 0:
  1739. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1740. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1741. {
  1742. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1743. }
  1744. if(idxPeriod > 0)
  1745. {
  1746. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1747. {
  1748. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1749. }
  1750. }
  1751. }
  1752. }
  1753. }
  1754. else
  1755. {
  1756. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  1757. {
  1758. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1759. {
  1760. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1761. 0:
  1762. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1763. }
  1764. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1765. {
  1766. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1767. {
  1768. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1769. 0:
  1770. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1771. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1772. {
  1773. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1774. }
  1775. if(idxPeriod > 0)
  1776. {
  1777. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1778. {
  1779. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1780. }
  1781. }
  1782. }
  1783. }
  1784. }
  1785. else
  1786. {
  1787. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1788. {
  1789. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1790. 0:
  1791. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1792. }
  1793. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1794. {
  1795. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1796. {
  1797. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1798. 0:
  1799. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1800. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1801. {
  1802. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1803. }
  1804. if(idxPeriod > 0)
  1805. {
  1806. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1807. {
  1808. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1809. }
  1810. }
  1811. }
  1812. }
  1813. }
  1814. }
  1815. /*
  1816. DEBUG_INFO("defaultTxProfile after align.\n");
  1817. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1818. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1819. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1820. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1821. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1822. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1823. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1824. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1825. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1826. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1827. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1828. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1829. {
  1830. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1831. {
  1832. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1833. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1834. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1835. }
  1836. }
  1837. DEBUG_INFO("------------------------------------\n");*/
  1838. }
  1839. if(maxProfile.ChargingProfileId != -1)
  1840. {
  1841. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1842. {
  1843. if(maxProfile.ChargingSchedule.Duration != -1)
  1844. {
  1845. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1846. 0:
  1847. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1848. }
  1849. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1850. {
  1851. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1852. {
  1853. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1854. 0:
  1855. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1856. if(idxPeriod > 0)
  1857. {
  1858. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1859. {
  1860. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1861. }
  1862. }
  1863. }
  1864. }
  1865. }
  1866. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1867. {
  1868. if(maxProfile.ChargingSchedule.Duration != -1)
  1869. {
  1870. 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?
  1871. 0:
  1872. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1873. }
  1874. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1875. {
  1876. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1877. {
  1878. 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?
  1879. 0:
  1880. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1881. if(idxPeriod > 0)
  1882. {
  1883. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1884. {
  1885. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1886. }
  1887. }
  1888. }
  1889. }
  1890. }
  1891. else
  1892. {
  1893. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1894. {
  1895. if(maxProfile.ChargingSchedule.Duration != -1)
  1896. {
  1897. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1898. 0:
  1899. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1900. }
  1901. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1902. {
  1903. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1904. {
  1905. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1906. 0:
  1907. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1908. if(idxPeriod > 0)
  1909. {
  1910. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1911. {
  1912. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1913. }
  1914. }
  1915. }
  1916. }
  1917. }
  1918. else
  1919. {
  1920. if(maxProfile.ChargingSchedule.Duration != -1)
  1921. {
  1922. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1923. 0:
  1924. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1925. }
  1926. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1927. {
  1928. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1929. {
  1930. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1931. 0:
  1932. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1933. if(idxPeriod > 0)
  1934. {
  1935. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1936. {
  1937. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1938. }
  1939. }
  1940. }
  1941. }
  1942. }
  1943. }
  1944. /*
  1945. DEBUG_INFO("MaxProfile after align.\n");
  1946. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1947. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1948. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1949. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1950. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1951. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1952. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1953. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1954. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1955. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1956. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1957. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1958. {
  1959. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1960. {
  1961. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1962. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1963. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1964. }
  1965. }
  1966. DEBUG_INFO("------------------------------------\n");*/
  1967. }
  1968. /*
  1969. * Merge to conposite schedule
  1970. */
  1971. //DEBUG_INFO("====================================\n");
  1972. // Find each profile period quantity
  1973. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1974. {
  1975. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1976. limitMax = idx+1;
  1977. }
  1978. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1979. {
  1980. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1981. limitDef = idx+1;
  1982. }
  1983. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1984. {
  1985. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1986. limitTx = idx+1;
  1987. }
  1988. // TxProfile found, composite schedule based on it
  1989. if(txProfile.ChargingProfileId != -1)
  1990. {
  1991. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  1992. {
  1993. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  1994. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  1995. (txProfile.ChargingSchedule.Duration > 0))
  1996. {
  1997. if(maxProfile.ChargingProfileId != -1)
  1998. {
  1999. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2000. {
  2001. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2002. {
  2003. if((maxProfile.ChargingSchedule.Duration > 0))
  2004. {
  2005. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2006. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2007. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2008. }
  2009. else
  2010. {
  2011. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2012. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2013. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2014. }
  2015. }
  2016. if(idxMaxPeriod == (limitMax-1))
  2017. {
  2018. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2019. {
  2020. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2021. {
  2022. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2023. compositePeriodIdx++;
  2024. }
  2025. else
  2026. {
  2027. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2028. }
  2029. }
  2030. }
  2031. }
  2032. }
  2033. else
  2034. {
  2035. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2036. {
  2037. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2038. compositePeriodIdx++;
  2039. }
  2040. else
  2041. {
  2042. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2043. }
  2044. }
  2045. }
  2046. if(idxTxPeriod == (limitTx-1))
  2047. {
  2048. if(defaultTxProfile.ChargingProfileId != -1)
  2049. {
  2050. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2051. {
  2052. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  2053. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2054. (defaultTxProfile.ChargingSchedule.Duration>0))
  2055. {
  2056. if(maxProfile.ChargingProfileId != -1)
  2057. {
  2058. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2059. {
  2060. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2061. {
  2062. if((maxProfile.ChargingSchedule.Duration > 0))
  2063. {
  2064. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2065. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2066. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2067. }
  2068. else
  2069. {
  2070. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2071. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2072. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2073. }
  2074. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2075. {
  2076. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2077. {
  2078. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2079. compositePeriodIdx++;
  2080. }
  2081. else
  2082. {
  2083. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2084. }
  2085. }
  2086. break;
  2087. }
  2088. }
  2089. }
  2090. else
  2091. {
  2092. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2093. {
  2094. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2095. compositePeriodIdx++;
  2096. }
  2097. else
  2098. {
  2099. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2100. }
  2101. }
  2102. }
  2103. }
  2104. }
  2105. }
  2106. }
  2107. }
  2108. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  2109. else if(defaultTxProfile.ChargingProfileId != -1)
  2110. {
  2111. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2112. {
  2113. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  2114. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2115. (defaultTxProfile.ChargingSchedule.Duration > 0))
  2116. {
  2117. if(maxProfile.ChargingProfileId != -1)
  2118. {
  2119. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2120. {
  2121. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2122. {
  2123. if((maxProfile.ChargingSchedule.Duration > 0))
  2124. {
  2125. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2126. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2127. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  2128. }
  2129. else
  2130. {
  2131. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2132. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2133. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2134. }
  2135. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2136. {
  2137. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2138. {
  2139. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2140. compositePeriodIdx++;
  2141. }
  2142. else
  2143. {
  2144. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2145. }
  2146. }
  2147. break;
  2148. }
  2149. }
  2150. }
  2151. else
  2152. {
  2153. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2154. {
  2155. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2156. compositePeriodIdx++;
  2157. }
  2158. else
  2159. {
  2160. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2161. }
  2162. }
  2163. }
  2164. }
  2165. }
  2166. // Fill other period by MaxProfile
  2167. if(maxProfile.ChargingProfileId != -1)
  2168. {
  2169. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2170. {
  2171. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2172. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2173. (maxProfile.ChargingSchedule.Duration > 0))
  2174. {
  2175. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  2176. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2177. {
  2178. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  2179. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  2180. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2181. }
  2182. if((maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2183. {
  2184. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.Duration;
  2185. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  2186. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2187. }
  2188. if(tmpPeriod.Limit != -1)
  2189. {
  2190. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2191. {
  2192. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2193. {
  2194. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2195. compositePeriodIdx++;
  2196. }
  2197. else
  2198. {
  2199. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2200. }
  2201. }
  2202. }
  2203. }
  2204. }
  2205. }
  2206. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  2207. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2208. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  2209. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  2210. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2211. {
  2212. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2213. {
  2214. compositeProfile->ChargingProfileId = 1;
  2215. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2216. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2217. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2218. }
  2219. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2220. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2221. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2222. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2223. }
  2224. if(line)
  2225. free(line);
  2226. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  2227. }
  2228. //==========================================
  2229. // Init all share memory
  2230. //==========================================
  2231. int InitShareMemory()
  2232. {
  2233. int result = PASS;
  2234. int MeterSMId;
  2235. //creat ShmSysConfigAndInfo
  2236. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  2237. {
  2238. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  2239. result = FAIL;
  2240. }
  2241. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2242. {
  2243. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  2244. result = FAIL;
  2245. }
  2246. else
  2247. {}
  2248. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  2249. {
  2250. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  2251. result = FAIL;
  2252. }
  2253. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2254. {
  2255. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  2256. result = FAIL;
  2257. }
  2258. else
  2259. {}
  2260. //creat ShmPsuData
  2261. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  2262. {
  2263. DEBUG_ERROR("shmget ShmPsuData NG\n");
  2264. result = FAIL;
  2265. }
  2266. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2267. {
  2268. DEBUG_ERROR("shmat ShmPsuData NG\n");
  2269. result = FAIL;
  2270. }
  2271. else
  2272. {}
  2273. //creat ShmOCPP16Data
  2274. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  2275. {
  2276. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  2277. result = FAIL;
  2278. }
  2279. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2280. {
  2281. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  2282. result = FAIL;
  2283. }
  2284. else
  2285. {}
  2286. /****************************** For Initial Settings************************************************/
  2287. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  2288. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  2289. // allocate Configuration memory address
  2290. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  2291. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  2292. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  2293. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  2294. //offline MeterValue Interval
  2295. TempMeterValueInterval = 0;
  2296. return result;
  2297. }
  2298. int ProcessShareMemory()
  2299. {
  2300. if(InitShareMemory() == FAIL)
  2301. {
  2302. DEBUG_ERROR("InitShareMemory NG\n");
  2303. if(ShmStatusCodeData!=NULL)
  2304. {
  2305. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  2306. }
  2307. sleep(5);
  2308. return FAIL;
  2309. }
  2310. return PASS;
  2311. }
  2312. void CheckSystemValue(void)
  2313. {
  2314. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  2315. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  2316. char filenmae[100]={0};
  2317. char str[100]={0};
  2318. int tempIndex = 0;
  2319. //===============================
  2320. // send Heartbeat
  2321. //===============================
  2322. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2323. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  2324. {
  2325. clientTime.Heartbeat=time((time_t*)NULL);
  2326. if(server_sign == TRUE)
  2327. {
  2328. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2329. }
  2330. else
  2331. {
  2332. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  2333. }
  2334. }
  2335. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  2336. {
  2337. //parameter for test
  2338. sendHeartbeatRequest(0);
  2339. //==============================================
  2340. // Reset Waiting Time
  2341. //==============================================
  2342. HeartBeatWithNOResponse += 1;
  2343. }
  2344. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  2345. {
  2346. //==========================================
  2347. // csu trigger DataTransferReq
  2348. //==========================================
  2349. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  2350. {
  2351. sendDataTransferRequest(gun_index);
  2352. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  2353. }
  2354. //===============================
  2355. // CSU Trigger Reset Conf
  2356. //===============================
  2357. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  2358. {
  2359. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  2360. }
  2361. //===============================
  2362. // CSU Trigger Authorize Request
  2363. //===============================
  2364. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  2365. {
  2366. sendAuthorizeRequest(0);
  2367. authorizeRetryTimes = authorizeRetryTimes + 1;
  2368. if(authorizeRetryTimes < 3)
  2369. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2370. }
  2371. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  2372. {
  2373. authorizeRetryTimes = 0;
  2374. SetOcppConnStatus(FALSE);
  2375. server_sign = FALSE;
  2376. }
  2377. 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))
  2378. {
  2379. sendAuthorizeRequest(0);
  2380. }
  2381. //==============================================
  2382. // CSU Trigger Smart Charging Profilw
  2383. //==============================================
  2384. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  2385. {
  2386. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  2387. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  2388. }
  2389. //==============================================
  2390. // Charger start transaction
  2391. //==============================================
  2392. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2393. {
  2394. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  2395. sendStartTransactionRequest(gun_index);
  2396. clientTime.StartTransaction = time((time_t*)NULL);
  2397. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2398. storeTempStopTransaction(gun_index);
  2399. }
  2400. //==============================================
  2401. // Charger stop transaction
  2402. //==============================================
  2403. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2404. {
  2405. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2406. sendStopTransactionRequest(gun_index);
  2407. clientTime.StopTransaction = time((time_t*)NULL);
  2408. }
  2409. //==============================================
  2410. // Charger status report
  2411. //==============================================
  2412. //--- Check Mode Change ---//
  2413. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2414. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2415. {
  2416. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2417. {
  2418. tempIndex = ((gun_index==2) ? 1: 0);
  2419. }
  2420. else
  2421. {
  2422. tempIndex = gun_index;
  2423. }
  2424. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2425. {
  2426. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2427. {
  2428. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  2429. {
  2430. // Sent unplug message for California pricing logic
  2431. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  2432. {
  2433. uint8_t ts[20];
  2434. getNowDatetime(ts);
  2435. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2436. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2437. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2438. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2439. }
  2440. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2441. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2442. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2443. statusModeChage[gun_index] = TRUE;
  2444. }
  2445. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2446. {
  2447. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2448. if((access(filenmae,F_OK))!=-1)
  2449. {
  2450. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2451. sprintf(str,"rm -f %s",filenmae);
  2452. system(str);
  2453. }
  2454. }
  2455. #if 1 // for TempStopTransaction
  2456. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2457. {
  2458. checkTempStopTransaction(gun_index);
  2459. }
  2460. #endif
  2461. }
  2462. }
  2463. }
  2464. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2465. {
  2466. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2467. {
  2468. tempIndex = ((gun_index==2) ? 1: 0);
  2469. }
  2470. else
  2471. {
  2472. tempIndex = gun_index;
  2473. }
  2474. for (int index = 0; index < CCS_QUANTITY; index++)
  2475. {
  2476. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2477. {
  2478. 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]*/ )
  2479. {
  2480. // Sent unplug message for California pricing logic
  2481. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  2482. {
  2483. uint8_t ts[20];
  2484. getNowDatetime(ts);
  2485. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2486. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2487. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2488. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2489. }
  2490. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2491. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2492. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2493. statusModeChage[gun_index] = TRUE;
  2494. }
  2495. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2496. {
  2497. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2498. if((access(filenmae,F_OK))!=-1)
  2499. {
  2500. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2501. sprintf(str,"rm -f %s",filenmae);
  2502. system(str);
  2503. }
  2504. }
  2505. #if 1 // for TempStopTransaction
  2506. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2507. {
  2508. checkTempStopTransaction(gun_index);
  2509. }
  2510. #endif
  2511. }
  2512. }
  2513. }
  2514. else if(gunType[gun_index] == GUN_TYPE_GBT)
  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 < GB_QUANTITY; index++)
  2525. {
  2526. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2527. {
  2528. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  2529. {
  2530. // Sent unplug message for California pricing logic
  2531. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[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. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2541. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2542. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2543. statusModeChage[gun_index] = TRUE;
  2544. }
  2545. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[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.GbChargingData[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_DO)
  2565. {
  2566. tempIndex = gun_index;
  2567. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2568. {
  2569. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2570. {
  2571. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  2572. {
  2573. // Sent unplug message for California pricing logic
  2574. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  2575. {
  2576. uint8_t ts[20];
  2577. getNowDatetime(ts);
  2578. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2579. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2580. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2581. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2582. }
  2583. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  2584. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  2585. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2586. statusModeChage[gun_index] = TRUE;
  2587. }
  2588. 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
  2589. {
  2590. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2591. if((access(filenmae,F_OK))!=-1)
  2592. {
  2593. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2594. sprintf(str,"rm -f %s",filenmae);
  2595. system(str);
  2596. }
  2597. }
  2598. #if 1 // for TempStopTransaction
  2599. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2600. {
  2601. checkTempStopTransaction(gun_index);
  2602. }
  2603. #endif
  2604. }
  2605. }
  2606. }
  2607. else
  2608. {
  2609. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2610. {
  2611. tempIndex = 2;
  2612. }
  2613. else
  2614. {
  2615. tempIndex = gun_index;
  2616. }
  2617. for (int index = 0; index < AC_QUANTITY; index++)
  2618. {
  2619. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2620. {
  2621. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  2622. {
  2623. // Sent unplug message for California pricing logic
  2624. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)
  2625. {
  2626. uint8_t ts[20];
  2627. getNowDatetime(ts);
  2628. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2629. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2630. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2631. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2632. }
  2633. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2634. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2635. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2636. statusModeChage[gun_index] = TRUE;
  2637. }
  2638. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2639. {
  2640. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2641. if((access(filenmae,F_OK))!=-1)
  2642. {
  2643. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2644. sprintf(str,"rm -f %s",filenmae);
  2645. system(str);
  2646. }
  2647. }
  2648. #if 1 // for TempStopTransaction
  2649. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2650. {
  2651. checkTempStopTransaction(gun_index);
  2652. }
  2653. #endif
  2654. }
  2655. }// END
  2656. }
  2657. if(isWebsocketSendable && (server_sign == TRUE) &&
  2658. (
  2659. (statusModeChage[gun_index] == TRUE) ||
  2660. //((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index))) ||
  2661. ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 10))
  2662. )
  2663. )
  2664. {
  2665. if(SystemInitial > 0)
  2666. SystemInitial -= 1;
  2667. sendStatusNotificationRequest(gun_index);
  2668. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2669. statusModeChage[gun_index] = FALSE;
  2670. }
  2671. //==============================================
  2672. // Meter report
  2673. //==============================================
  2674. // Trigger MeterValue
  2675. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  2676. {
  2677. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  2678. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  2679. }
  2680. // ClockAlign MeterValue
  2681. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  2682. {
  2683. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2684. {
  2685. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2686. {
  2687. tempIndex = ((gun_index==2) ? 1: 0);
  2688. }
  2689. else
  2690. {
  2691. tempIndex = gun_index;
  2692. }
  2693. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2694. {
  2695. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2696. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2697. {
  2698. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2699. {
  2700. reqClockAlignMeter[gun_index] = 1;
  2701. }
  2702. }
  2703. }// End for CHAdeMO
  2704. }
  2705. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2706. {
  2707. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2708. {
  2709. tempIndex = ((gun_index==2) ? 1: 0);
  2710. }
  2711. else
  2712. {
  2713. tempIndex = gun_index;
  2714. }
  2715. for (int index = 0; index < CCS_QUANTITY; index++)
  2716. {
  2717. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2718. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2719. {
  2720. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2721. {
  2722. reqClockAlignMeter[gun_index] = 1;
  2723. }
  2724. }
  2725. } // End for CCS
  2726. }
  2727. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2728. {
  2729. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2730. {
  2731. tempIndex = ((gun_index==2) ? 1: 0);
  2732. }
  2733. else
  2734. {
  2735. tempIndex = gun_index;
  2736. }
  2737. for (int index = 0; index < GB_QUANTITY; index++)
  2738. {
  2739. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2740. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2741. {
  2742. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2743. {
  2744. reqClockAlignMeter[gun_index] = 1;
  2745. }
  2746. }
  2747. }// End for GB
  2748. }
  2749. else if(gunType[gun_index] == GUN_TYPE_DO)
  2750. {
  2751. tempIndex = gun_index;
  2752. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2753. {
  2754. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2755. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2756. {
  2757. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_CHARGING)
  2758. {
  2759. reqClockAlignMeter[gun_index] = 1;
  2760. }
  2761. }
  2762. }
  2763. }
  2764. else
  2765. {
  2766. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2767. {
  2768. tempIndex = 2;
  2769. }
  2770. else
  2771. {
  2772. tempIndex = gun_index;
  2773. }
  2774. for (int index = 0; index < AC_QUANTITY; index++)
  2775. {
  2776. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2777. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2778. {
  2779. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2780. {
  2781. reqClockAlignMeter[gun_index] = 1;
  2782. }
  2783. }
  2784. }//End for AC
  2785. }
  2786. if(reqClockAlignMeter[gun_index] == 1)
  2787. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  2788. }
  2789. // Sample period MeterValue
  2790. if((((time((time_t*)NULL) - clientTime.MeterValues[gun_index]) > (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1))))
  2791. {
  2792. //check Transaction active
  2793. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2794. {
  2795. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2796. {
  2797. tempIndex = ((gun_index==2) ? 1: 0);
  2798. }
  2799. else
  2800. {
  2801. tempIndex = gun_index;
  2802. }
  2803. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2804. {
  2805. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2806. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2807. {
  2808. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2809. {
  2810. reqSampleMeter[gun_index] = 1;
  2811. }
  2812. }
  2813. }// End for CHAdeMO
  2814. }
  2815. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2816. {
  2817. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2818. {
  2819. tempIndex = ((gun_index==2) ? 1: 0);
  2820. }
  2821. else
  2822. {
  2823. tempIndex = gun_index;
  2824. }
  2825. for (int index = 0; index < CCS_QUANTITY; index++)
  2826. {
  2827. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2828. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2829. {
  2830. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2831. {
  2832. reqSampleMeter[gun_index] = 1;
  2833. }
  2834. }
  2835. } // End for CCS
  2836. }
  2837. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2838. {
  2839. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2840. {
  2841. tempIndex = ((gun_index==2) ? 1: 0);
  2842. }
  2843. else
  2844. {
  2845. tempIndex = gun_index;
  2846. }
  2847. for (int index = 0; index < GB_QUANTITY; index++)
  2848. {
  2849. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2850. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2851. {
  2852. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2853. {
  2854. reqSampleMeter[gun_index] = 1;
  2855. }
  2856. }
  2857. }// End for GB
  2858. }
  2859. else if(gunType[gun_index] == GUN_TYPE_DO)
  2860. {
  2861. tempIndex = gun_index;
  2862. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2863. {
  2864. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2865. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2866. {
  2867. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  2868. {
  2869. reqSampleMeter[gun_index] = 1;
  2870. }
  2871. }
  2872. }
  2873. }
  2874. else
  2875. {
  2876. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2877. {
  2878. tempIndex = 2;
  2879. }
  2880. else
  2881. {
  2882. tempIndex = gun_index;
  2883. }
  2884. for (int index = 0; index < AC_QUANTITY; index++)
  2885. {
  2886. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2887. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2888. {
  2889. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  2890. {
  2891. reqSampleMeter[gun_index] = 1;
  2892. }
  2893. }
  2894. }//End for AC
  2895. }
  2896. if(reqSampleMeter[gun_index] == 1)
  2897. {
  2898. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  2899. storeTempStopTransaction(gun_index);
  2900. }
  2901. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2902. }
  2903. //==============================================
  2904. // Check Connector reserved
  2905. //==============================================
  2906. //===============================
  2907. // Check if Reserve is expired
  2908. //===============================
  2909. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  2910. {
  2911. double diff_t;
  2912. struct tm tp;
  2913. // current time
  2914. time_t t = time(NULL);
  2915. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  2916. tp.tm_isdst = -1;
  2917. time_t utc = mktime(&tp);
  2918. diff_t = difftime(utc, t);
  2919. if(diff_t <= 0)
  2920. {
  2921. DEBUG_INFO("reserve expired.\n");
  2922. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  2923. }
  2924. }//END OF Check if Reserve is expired
  2925. //==========================================
  2926. // csu trigger FirmwareStatusNotificationReq
  2927. //==========================================
  2928. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  2929. {
  2930. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  2931. }
  2932. //==========================================
  2933. // csu trigger CancelReservationConf
  2934. //==========================================
  2935. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  2936. {
  2937. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  2938. }
  2939. //==========================================
  2940. // csu trigger ChangeAvailabilityConf
  2941. //==========================================
  2942. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  2943. {
  2944. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  2945. }
  2946. //==========================================
  2947. // csu trigger UnlockConnectorConf
  2948. //==========================================
  2949. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  2950. {
  2951. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  2952. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  2953. }
  2954. //==========================================
  2955. // csu trigger ReserveNowConf
  2956. //==========================================
  2957. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  2958. {
  2959. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  2960. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  2961. }
  2962. }
  2963. }
  2964. //==========================================
  2965. // send request routine
  2966. //==========================================
  2967. int sendAuthorizeRequest(int gun_index)
  2968. {
  2969. mtrace();
  2970. int result = FAIL;
  2971. char message[100]={0};
  2972. char guid[37];
  2973. char tempdata[65]={0};
  2974. DEBUG_INFO("sendAuthorizeRequest...\n");
  2975. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  2976. //Local Authorize
  2977. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  2978. {
  2979. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  2980. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2981. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  2982. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  2983. result = PASS;
  2984. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2985. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2986. authorizeRetryTimes = 0;
  2987. return result;
  2988. }
  2989. 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))||
  2990. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  2991. {
  2992. // Query from cache
  2993. DEBUG_INFO("Authorize from cache.\n");
  2994. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2995. // Query from list
  2996. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  2997. {
  2998. DEBUG_INFO("Authorize from list.\n");
  2999. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3000. }
  3001. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3002. {
  3003. if(strcmp(idTagQuery.idTagstr,"") == 0)
  3004. {
  3005. DEBUG_INFO("off-line Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  3006. }
  3007. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  3008. {
  3009. DEBUG_INFO("off-line Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  3010. }
  3011. DEBUG_INFO("off-line Local Authorization Fail !!!!\n");
  3012. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  3013. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3014. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  3015. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  3016. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3017. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3018. authorizeRetryTimes = 0;
  3019. return result;
  3020. }
  3021. else
  3022. {
  3023. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  3024. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3025. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3026. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  3027. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  3028. else
  3029. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  3030. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  3031. result = PASS;
  3032. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3033. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3034. authorizeRetryTimes = 0;
  3035. return result;
  3036. }
  3037. }
  3038. //initialize struct Authorize
  3039. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  3040. //get data from shared memory
  3041. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3042. random_uuid(guid);
  3043. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  3044. LWS_Send(message);
  3045. sprintf(tempdata, "Authorize,%d", gun_index);
  3046. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3047. {
  3048. result = PASS;
  3049. DEBUG_INFO("Authorize mapItem pass\n");
  3050. }
  3051. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3052. return result;
  3053. }
  3054. int sendBootNotificationRequest(void)
  3055. {
  3056. mtrace();
  3057. int result = FAIL;
  3058. char message[500]={0}, payload[700]={0};
  3059. char guid[37]={0};
  3060. char tempdata[65]={0};
  3061. // Fill BootNotification fields
  3062. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  3063. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  3064. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  3065. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3066. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  3067. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  3068. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  3069. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  3070. ShmOCPP16Data->ChargeBoxId
  3071. ,ShmSysConfigAndInfo->SysConfig.ModelName
  3072. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  3073. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  3074. ,ShmOCPP16Data->BootNotification.CpFwVersion
  3075. ,ShmOCPP16Data->BootNotification.CpIccid
  3076. ,ShmOCPP16Data->BootNotification.CpImsi);
  3077. random_uuid(guid);
  3078. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  3079. LWS_Send(message);
  3080. sprintf(tempdata, "BootNotification,0");
  3081. 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*/)
  3082. {
  3083. result = PASS;
  3084. }
  3085. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3086. strcpy(queuedata,message);
  3087. return result;
  3088. }
  3089. int sendDataTransferRequest(int gun_index)
  3090. {
  3091. mtrace();
  3092. char message[1000]={0};
  3093. char guid[37]={0};
  3094. char tempdata[65]={0};
  3095. int result = FAIL;
  3096. random_uuid(guid);
  3097. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  3098. MESSAGE_TYPE_CALL,
  3099. guid,
  3100. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  3101. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  3102. ShmOCPP16Data->DataTransfer[gun_index].Data);
  3103. LWS_Send(message);
  3104. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  3105. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3106. {
  3107. result = PASS;
  3108. DEBUG_INFO("DataTransfer mapItem pass\n");
  3109. }
  3110. return result;
  3111. }
  3112. int sendDiagnosticsStatusNotificationRequest(char *status)
  3113. {
  3114. mtrace();
  3115. int result = FAIL;
  3116. char message[110]={0};
  3117. char guid[37]={0};
  3118. char tempdata[65]={0};
  3119. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  3120. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  3121. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  3122. random_uuid(guid);
  3123. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  3124. LWS_SendNow(message);
  3125. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  3126. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3127. {
  3128. result = PASS;
  3129. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  3130. }
  3131. //#ifdef SystemLogMessage
  3132. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  3133. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3134. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  3135. //#endif
  3136. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  3137. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  3138. //record status
  3139. if(strcmp(status,"Idle")==0)
  3140. {
  3141. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  3142. }
  3143. else if(strcmp(status,"Uploaded")==0)
  3144. {
  3145. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  3146. }
  3147. else if(strcmp(status,"UploadFailed")==0)
  3148. {
  3149. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  3150. }
  3151. else if(strcmp(status,"Uploading")==0)
  3152. {
  3153. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  3154. }
  3155. return result;
  3156. }
  3157. int sendFirmwareStatusNotificationRequest(char *status)
  3158. {
  3159. mtrace();
  3160. int result = FAIL;
  3161. char message[110]={0};
  3162. char guid[37]={0};
  3163. char tempdata[65]={0};
  3164. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  3165. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  3166. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  3167. random_uuid(guid);
  3168. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  3169. LWS_SendNow(message);
  3170. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  3171. 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*/)
  3172. {
  3173. result = PASS;
  3174. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  3175. }
  3176. //#ifdef SystemLogMessage
  3177. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  3178. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3179. //#endif
  3180. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  3181. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  3182. //record status
  3183. if(strcmp(status,"Downloaded")==0)
  3184. {
  3185. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  3186. }
  3187. else if(strcmp(status,"DownloadFailed")==0)
  3188. {
  3189. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  3190. }
  3191. else if(strcmp(status,"Downloading")==0)
  3192. {
  3193. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  3194. }
  3195. else if(strcmp(status,"Idle")==0)
  3196. {
  3197. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  3198. }
  3199. else if(strcmp(status,"InstallationFailed")==0)
  3200. {
  3201. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  3202. }
  3203. else if(strcmp(status,"Installing")==0)
  3204. {
  3205. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  3206. }
  3207. else if(strcmp(status,"Installed")==0)
  3208. {
  3209. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  3210. }
  3211. return result;
  3212. }
  3213. int sendHeartbeatRequest(int gun_index)
  3214. {
  3215. mtrace();
  3216. int result = FAIL;
  3217. char message[80]={0};
  3218. char guid[37]={0};
  3219. char tempdata[65]={0};
  3220. random_uuid(guid);
  3221. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  3222. , MESSAGE_TYPE_CALL
  3223. , guid );
  3224. LWS_Send(message);
  3225. sprintf(tempdata, "Heartbeat,%d", 0);
  3226. 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*/)
  3227. {
  3228. result = PASS;
  3229. }
  3230. return result;
  3231. }
  3232. int sendStartTransactionRequest(int gun_index)
  3233. {
  3234. mtrace();
  3235. int result = FAIL;
  3236. char message[250]={0};
  3237. char guid[37]={0};
  3238. struct timeval tmnow;
  3239. struct tm *tm;
  3240. char buf[28];//, usec_buf[6];
  3241. char tempdata[65]={0};
  3242. int tempIndex = 0;
  3243. DEBUG_INFO("sendStartTransactionRequest...\n");
  3244. gettimeofday(&tmnow, NULL);
  3245. time_t t;
  3246. t = time(NULL);
  3247. /*UTC time and date*/
  3248. tm = gmtime(&t);
  3249. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3250. #if 0 // remove temporally
  3251. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3252. strcat(buf,".");
  3253. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3254. strcat(buf,usec_buf);
  3255. #endif
  3256. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  3257. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  3258. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3259. // clear StartTransaction Response
  3260. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  3261. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  3262. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  3263. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  3264. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3265. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3266. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3267. {
  3268. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3269. {
  3270. tempIndex = ((gun_index==2) ? 1: 0);
  3271. }
  3272. else
  3273. {
  3274. tempIndex = gun_index;
  3275. }
  3276. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3277. {
  3278. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3279. {
  3280. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3281. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  3282. }
  3283. }
  3284. }
  3285. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3286. {
  3287. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3288. {
  3289. tempIndex = ((gun_index==2) ? 1: 0);
  3290. }
  3291. else
  3292. {
  3293. tempIndex = gun_index;
  3294. }
  3295. for (int index = 0; index < CCS_QUANTITY; index++)
  3296. {
  3297. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3298. {
  3299. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3300. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  3301. }
  3302. }
  3303. }
  3304. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3305. {
  3306. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3307. {
  3308. tempIndex = ((gun_index==2) ? 1: 0);
  3309. }
  3310. else
  3311. {
  3312. tempIndex = gun_index;
  3313. }
  3314. for (int index = 0; index < GB_QUANTITY; index++)
  3315. {
  3316. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3317. {
  3318. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3319. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  3320. }
  3321. }
  3322. }
  3323. else if(gunType[gun_index] == GUN_TYPE_DO)
  3324. {
  3325. tempIndex = gun_index;
  3326. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3327. {
  3328. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3329. {
  3330. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3331. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  3332. }
  3333. }
  3334. }
  3335. else
  3336. {
  3337. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3338. {
  3339. tempIndex = 2;
  3340. }
  3341. else
  3342. {
  3343. tempIndex = gun_index;
  3344. }
  3345. for (int index = 0; index < AC_QUANTITY; index++)
  3346. {
  3347. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3348. {
  3349. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3350. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  3351. }
  3352. }
  3353. }
  3354. random_uuid(guid);
  3355. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  3356. {
  3357. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  3358. , gun_index +1
  3359. , MESSAGE_TYPE_CALL
  3360. , guid
  3361. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3362. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3363. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3364. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3365. }
  3366. else
  3367. {
  3368. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  3369. , gun_index +1
  3370. , MESSAGE_TYPE_CALL
  3371. , guid
  3372. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3373. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3374. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3375. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  3376. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3377. }
  3378. #if 1
  3379. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  3380. 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*/)
  3381. {
  3382. result = PASS;
  3383. }
  3384. #endif
  3385. strcpy(queuedata, message);
  3386. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3387. OCPP_insert_transaction_msg(YES, queuedata);
  3388. return result;
  3389. }
  3390. int sendStatusNotificationRequest(int gun_index)
  3391. {
  3392. mtrace();
  3393. int result = FAIL;
  3394. char message[600]={0};
  3395. char guid[37];
  3396. int currentStatus = 0;
  3397. struct timeval tmnow;
  3398. struct tm *tm;
  3399. char buf[28];//, usec_buf[6];
  3400. char tempdata[65]={0};
  3401. int tempIndex = 0;
  3402. DEBUG_INFO("sendStatusNotificationRequest...\n");
  3403. gettimeofday(&tmnow, NULL);
  3404. time_t t;
  3405. t = time(NULL);
  3406. /*UTC time and date*/
  3407. tm = gmtime(&t);
  3408. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3409. #if 0 // remove temporally
  3410. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3411. strcat(buf,".");
  3412. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3413. strcat(buf,usec_buf);
  3414. #endif
  3415. printf("%s",buf);
  3416. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  3417. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  3418. // it's option
  3419. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  3420. /*
  3421. enum _SYSTEM_STATUS
  3422. {
  3423. S_BOOTING = 0,
  3424. S_IDLE, = 1
  3425. S_AUTHORIZING, =2
  3426. S_REASSIGN_CHECK, =3
  3427. S_REASSIGN, =4
  3428. S_PRECHARGE, =5
  3429. S_PREPARING_FOR_EV, =6
  3430. S_PREPARING_FOR_EVSE, =7
  3431. S_CHARGING, =8
  3432. S_TERMINATING, =9
  3433. S_COMPLETE, =10
  3434. S_ALARM, =11
  3435. S_FAULT =12
  3436. }
  3437. */
  3438. //check Transaction active
  3439. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3440. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3441. {
  3442. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3443. {
  3444. tempIndex = ((gun_index==2) ? 1: 0);
  3445. }
  3446. else
  3447. {
  3448. tempIndex = gun_index;
  3449. }
  3450. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3451. {
  3452. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  3453. {
  3454. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  3455. {
  3456. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3457. {
  3458. currentStatus = Preparing; //OCPP Status: Preparing
  3459. }
  3460. else
  3461. {
  3462. currentStatus = Available; //OCPP Status: Available
  3463. }
  3464. }
  3465. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3466. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3467. ) //S_PRECHARGE
  3468. {
  3469. currentStatus = Preparing; //OCPP Status: Preparing
  3470. }
  3471. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3472. {
  3473. currentStatus = Charging; //OCPP Status: Charging
  3474. }
  3475. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3476. {
  3477. currentStatus = Finishing; //OCPP Status: Finishing
  3478. }
  3479. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3480. {
  3481. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3482. }
  3483. 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
  3484. {
  3485. currentStatus = Unavailable; //OCPP Status: Unavailable
  3486. }
  3487. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3488. {
  3489. currentStatus = Faulted; //OCPP Status: Faulted
  3490. }
  3491. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3492. {
  3493. currentStatus = Reserved; //OCPP Status: Reserved
  3494. }
  3495. } //end of the same index
  3496. }//end of for CHAdeMO_QUANTITY
  3497. }
  3498. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3499. {
  3500. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3501. {
  3502. tempIndex = ((gun_index==2) ? 1: 0);
  3503. }
  3504. else
  3505. {
  3506. tempIndex = gun_index;
  3507. }
  3508. for (int index = 0; index < CCS_QUANTITY; index++)
  3509. {
  3510. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3511. {
  3512. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3513. {
  3514. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3515. {
  3516. currentStatus = Preparing; //OCPP Status: Preparing
  3517. }
  3518. else
  3519. {
  3520. currentStatus = Available; //OCPP Status: Available
  3521. }
  3522. }
  3523. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3524. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3525. ) //S_PRECHARGE
  3526. {
  3527. currentStatus = Preparing; //OCPP Status: Preparing
  3528. }
  3529. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3530. {
  3531. currentStatus = Charging; //OCPP Status: Charging
  3532. }
  3533. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3534. {
  3535. currentStatus = Finishing; //OCPP Status: Finishing
  3536. }
  3537. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3538. {
  3539. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3540. }
  3541. 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
  3542. {
  3543. currentStatus = Unavailable; //OCPP Status : Unavailable
  3544. }
  3545. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3546. {
  3547. currentStatus = Faulted; //OCPP Status: Faulted
  3548. }
  3549. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3550. {
  3551. currentStatus = Reserved; //OCPP Status: Reserved
  3552. }
  3553. } //end of the same index
  3554. } // end of for CCS_QUANTITY
  3555. }
  3556. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3557. {
  3558. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3559. {
  3560. tempIndex = ((gun_index==2) ? 1: 0);
  3561. }
  3562. else
  3563. {
  3564. tempIndex = gun_index;
  3565. }
  3566. for (int index = 0; index < GB_QUANTITY; index++)
  3567. {
  3568. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3569. {
  3570. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3571. {
  3572. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3573. {
  3574. currentStatus = Preparing; //OCPP Status: Preparing
  3575. }
  3576. else
  3577. {
  3578. currentStatus = Available; //OCPP Status: Available
  3579. }
  3580. }
  3581. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3582. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3583. ) //S_PRECHARGE
  3584. {
  3585. currentStatus = Preparing; //OCPP Status: Preparing
  3586. }
  3587. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3588. {
  3589. currentStatus = Charging; //OCPP Status: Charging
  3590. }
  3591. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3592. {
  3593. currentStatus = Finishing; //OCPP Status: Finishing
  3594. }
  3595. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3596. {
  3597. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3598. }
  3599. 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
  3600. {
  3601. currentStatus = Unavailable; //OCPP Status: Unavailable
  3602. }
  3603. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3604. {
  3605. currentStatus = Faulted; //OCPP Status: Faulted
  3606. }
  3607. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3608. {
  3609. currentStatus = Reserved; //OCPP Status: Reserved
  3610. }
  3611. } //end of the same index
  3612. } // end of for GB_QUANTITY
  3613. }
  3614. else if(gunType[gun_index] == GUN_TYPE_DO)
  3615. {
  3616. tempIndex = gun_index;
  3617. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3618. {
  3619. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3620. {
  3621. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3622. {
  3623. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3624. {
  3625. currentStatus = Preparing; //OCPP Status: Preparing
  3626. }
  3627. else
  3628. {
  3629. currentStatus = Available; //OCPP Status: Available
  3630. }
  3631. }
  3632. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3633. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3634. ) //S_PRECHARGE
  3635. {
  3636. currentStatus = Preparing; //OCPP Status: Preparing
  3637. }
  3638. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3639. {
  3640. currentStatus = Charging; //OCPP Status: Charging
  3641. }
  3642. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3643. {
  3644. currentStatus = Finishing; //OCPP Status: Finishing
  3645. }
  3646. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3647. {
  3648. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3649. }
  3650. 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
  3651. {
  3652. currentStatus = Unavailable; //OCPP Status: Unavailable
  3653. }
  3654. 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
  3655. {
  3656. currentStatus = Faulted; //OCPP Status: Faulted
  3657. }
  3658. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3659. {
  3660. currentStatus = Reserved; //OCPP Status: Reserved
  3661. }
  3662. } //end of the same index
  3663. }
  3664. }
  3665. else
  3666. {
  3667. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3668. {
  3669. tempIndex = 2;
  3670. }
  3671. else
  3672. {
  3673. tempIndex = gun_index;
  3674. }
  3675. for (int index = 0; index < AC_QUANTITY; index++)
  3676. {
  3677. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3678. {
  3679. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3680. {
  3681. 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))
  3682. {
  3683. currentStatus = Preparing; //OCPP Status: Preparing
  3684. }
  3685. else
  3686. {
  3687. currentStatus = Available; //OCPP Status: Available
  3688. }
  3689. }
  3690. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  3691. {
  3692. currentStatus = Preparing; //OCPP Status: Preparing
  3693. }
  3694. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3695. {
  3696. currentStatus = Charging; //OCPP Status: Charging
  3697. }
  3698. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3699. {
  3700. currentStatus = Finishing; //OCPP Status: Finishing
  3701. }
  3702. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3703. {
  3704. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3705. }
  3706. 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
  3707. {
  3708. currentStatus = Unavailable; //OCPP Status: Unavailable
  3709. }
  3710. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3711. {
  3712. currentStatus = Faulted; //OCPP Status: Faulted
  3713. }
  3714. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3715. {
  3716. currentStatus = Reserved; //OCPP Status: Reserved
  3717. }
  3718. }//end of the same index
  3719. }//end of for AC_QUANTITY
  3720. }
  3721. //it's option
  3722. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3723. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3724. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3725. random_uuid(guid);
  3726. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3727. , MESSAGE_TYPE_CALL
  3728. , guid
  3729. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3730. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3731. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3732. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3733. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3734. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3735. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3736. if((server_sign == TRUE))
  3737. {
  3738. LWS_Send(message);
  3739. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3740. 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*/)
  3741. {
  3742. //DEBUG_ERROR("statusNotification mapitem pass");
  3743. result = PASS;
  3744. }
  3745. }
  3746. else
  3747. {
  3748. result = PASS;
  3749. }
  3750. return result;
  3751. }
  3752. int sendStopTransactionRequest(int gun_index)
  3753. {
  3754. mtrace();
  3755. int result = FAIL;
  3756. //char message[1500]={0};
  3757. char guid[37]={0};
  3758. char tempdata[65]={0};
  3759. int tempIndex = 0;
  3760. char TempStopTransaction[256];
  3761. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  3762. //int idx_sample=0;
  3763. DEBUG_INFO("sendStopTransactionRequest \n");
  3764. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3765. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  3766. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  3767. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3768. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3769. {
  3770. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3771. {
  3772. tempIndex = ((gun_index==2) ? 1: 0);
  3773. }
  3774. else
  3775. {
  3776. tempIndex = gun_index;
  3777. }
  3778. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3779. {
  3780. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3781. {
  3782. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3783. }
  3784. }// END OF CHAdeMO_QUANTITY
  3785. }
  3786. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3787. {
  3788. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3789. {
  3790. tempIndex = ((gun_index==2) ? 1: 0);
  3791. }
  3792. else
  3793. {
  3794. tempIndex = gun_index;
  3795. }
  3796. for (int index = 0; index < CCS_QUANTITY; index++)
  3797. {
  3798. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3799. {
  3800. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3801. }
  3802. }// END OF CCS_QUANTITY
  3803. }
  3804. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3805. {
  3806. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3807. {
  3808. tempIndex = ((gun_index==2) ? 1: 0);
  3809. }
  3810. else
  3811. {
  3812. tempIndex = gun_index;
  3813. }
  3814. for (int index = 0; index < GB_QUANTITY; index++)
  3815. {
  3816. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3817. {
  3818. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3819. }
  3820. }// END OF GB_QUANTITY
  3821. }
  3822. else if(gunType[gun_index] == GUN_TYPE_DO)
  3823. {
  3824. tempIndex = gun_index;
  3825. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3826. {
  3827. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3828. {
  3829. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3830. }
  3831. }// END OF GB_QUANTITY
  3832. }
  3833. else
  3834. {
  3835. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3836. {
  3837. tempIndex = 2;
  3838. }
  3839. else
  3840. {
  3841. tempIndex = gun_index;
  3842. }
  3843. for (int index = 0; index < AC_QUANTITY; index++)
  3844. {
  3845. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3846. {
  3847. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3848. }
  3849. }// END OF AC_QUANTITY
  3850. }
  3851. //====================================== Stop Transaction Time =====================================================
  3852. struct timeval tmnow;
  3853. struct tm *tm;
  3854. char buf[28];//, usec_buf[6];
  3855. gettimeofday(&tmnow, NULL);
  3856. time_t t;
  3857. t = time(NULL);
  3858. /*UTC time and date*/
  3859. tm = gmtime(&t);
  3860. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3861. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  3862. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  3863. random_uuid(guid);
  3864. /***********************************transactionData******************************************************/
  3865. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  3866. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  3867. //=================================
  3868. // Transaction_Begin
  3869. //=================================
  3870. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  3871. {
  3872. //============================================ Energy.Active.Import.Interval ================================
  3873. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  3874. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  3875. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  3876. 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*/]);
  3877. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3878. 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))
  3879. {
  3880. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  3881. }
  3882. else
  3883. {
  3884. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  3885. }
  3886. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  3887. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3888. }
  3889. //=================================
  3890. // Transaction_End
  3891. //=================================
  3892. // ================================= Current.Import L1 ===============================================
  3893. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  3894. {
  3895. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  3896. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3897. {
  3898. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3899. {
  3900. tempIndex = ((gun_index==2) ? 1: 0);
  3901. }
  3902. else
  3903. {
  3904. tempIndex = gun_index;
  3905. }
  3906. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3907. {
  3908. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3909. {
  3910. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3911. }
  3912. }// End of for CHAdeMO_QUANTITY
  3913. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3914. }
  3915. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3916. {
  3917. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3918. {
  3919. tempIndex = ((gun_index==2) ? 1: 0);
  3920. }
  3921. else
  3922. {
  3923. tempIndex = gun_index;
  3924. }
  3925. for (int index = 0; index < CCS_QUANTITY; index++)
  3926. {
  3927. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3928. {
  3929. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3930. }
  3931. }// End of for CCS_QUANTITY
  3932. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3933. }
  3934. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3935. {
  3936. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3937. {
  3938. tempIndex = ((gun_index==2) ? 1: 0);
  3939. }
  3940. else
  3941. {
  3942. tempIndex = gun_index;
  3943. }
  3944. for (int index = 0; index < GB_QUANTITY; index++)
  3945. {
  3946. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3947. {
  3948. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3949. }
  3950. }// End of for GB_QUANTITY
  3951. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3952. }
  3953. else if(gunType[gun_index] == GUN_TYPE_DO)
  3954. {
  3955. tempIndex = gun_index;
  3956. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3957. {
  3958. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3959. {
  3960. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3961. }
  3962. }
  3963. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3964. }
  3965. else
  3966. {
  3967. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3968. {
  3969. tempIndex = 2;
  3970. }
  3971. else
  3972. {
  3973. tempIndex = gun_index;
  3974. }
  3975. for (int index = 0; index < AC_QUANTITY; index++)
  3976. {
  3977. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3978. {
  3979. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  3980. }
  3981. }// End of for AC_QUANTITY
  3982. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  3983. }
  3984. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3985. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  3986. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  3987. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  3988. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3989. }
  3990. // ================================= Energy.Active.Import.Interval ==============================================
  3991. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  3992. {
  3993. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3994. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3995. {
  3996. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3997. {
  3998. tempIndex = ((gun_index==2) ? 1: 0);
  3999. }
  4000. else
  4001. {
  4002. tempIndex = gun_index;
  4003. }
  4004. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4005. {
  4006. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4007. {
  4008. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4009. }
  4010. }// END OF CHAdeMO_QUANTITY
  4011. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4012. }
  4013. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4014. {
  4015. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4016. {
  4017. tempIndex = ((gun_index==2) ? 1: 0);
  4018. }
  4019. else
  4020. {
  4021. tempIndex = gun_index;
  4022. }
  4023. for (int index = 0; index < CCS_QUANTITY; index++)
  4024. {
  4025. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4026. {
  4027. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4028. }
  4029. }// END OF CCS_QUANTITY
  4030. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4031. }
  4032. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4033. {
  4034. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4035. {
  4036. tempIndex = ((gun_index==2) ? 1: 0);
  4037. }
  4038. else
  4039. {
  4040. tempIndex = gun_index;
  4041. }
  4042. for (int index = 0; index < GB_QUANTITY; index++)
  4043. {
  4044. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4045. {
  4046. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4047. }
  4048. }// END OF GB_QUANTITY
  4049. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4050. }
  4051. else if(gunType[gun_index] == GUN_TYPE_DO)
  4052. {
  4053. tempIndex = gun_index;
  4054. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4055. {
  4056. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4057. {
  4058. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4059. }
  4060. }
  4061. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4062. }
  4063. else
  4064. {
  4065. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4066. {
  4067. tempIndex = 2;
  4068. }
  4069. else
  4070. {
  4071. tempIndex = gun_index;
  4072. }
  4073. for (int index = 0; index < AC_QUANTITY; index++)
  4074. {
  4075. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4076. {
  4077. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4078. }
  4079. }// END OF AC_QUANTITY
  4080. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  4081. }
  4082. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4083. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  4084. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  4085. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  4086. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4087. }
  4088. //=================================== Power.Active.Import ==================================================
  4089. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  4090. {
  4091. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4092. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4093. {
  4094. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4095. {
  4096. tempIndex = ((gun_index==2) ? 1: 0);
  4097. }
  4098. else
  4099. {
  4100. tempIndex = gun_index;
  4101. }
  4102. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4103. {
  4104. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4105. {
  4106. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4107. }
  4108. } // End for CHAdeMO_QUANTITY
  4109. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4110. }
  4111. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4112. {
  4113. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4114. {
  4115. tempIndex = ((gun_index==2) ? 1: 0);
  4116. }
  4117. else
  4118. {
  4119. tempIndex = gun_index;
  4120. }
  4121. for (int index = 0; index < CCS_QUANTITY; index++)
  4122. {
  4123. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4124. {
  4125. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4126. }
  4127. } // END for CCS_QUANTITY
  4128. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4129. }
  4130. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4131. {
  4132. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4133. {
  4134. tempIndex = ((gun_index==2) ? 1: 0);
  4135. }
  4136. else
  4137. {
  4138. tempIndex = gun_index;
  4139. }
  4140. for (int index = 0; index < GB_QUANTITY; index++)
  4141. {
  4142. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4143. {
  4144. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4145. }
  4146. }// END for GB_QUANTITY
  4147. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4148. }
  4149. else if(gunType[gun_index] == GUN_TYPE_DO)
  4150. {
  4151. tempIndex = gun_index;
  4152. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4153. {
  4154. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4155. {
  4156. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4157. }
  4158. }
  4159. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4160. }
  4161. else
  4162. {
  4163. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4164. {
  4165. tempIndex = 2;
  4166. }
  4167. else
  4168. {
  4169. tempIndex = gun_index;
  4170. }
  4171. for (int index = 0; index < AC_QUANTITY; index++)
  4172. {
  4173. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4174. {
  4175. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4176. }
  4177. } // END for AC_QUANTITY
  4178. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  4179. }
  4180. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4181. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  4182. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  4183. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  4184. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  4185. }
  4186. //============================ Voltage L1 ====================================
  4187. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4188. {
  4189. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4190. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4191. {
  4192. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4193. {
  4194. tempIndex = ((gun_index==2) ? 1: 0);
  4195. }
  4196. else
  4197. {
  4198. tempIndex = gun_index;
  4199. }
  4200. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4201. {
  4202. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4203. {
  4204. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4205. }
  4206. } // END OF FOR CHAdeMO_QUANTITY
  4207. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4208. }
  4209. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4210. {
  4211. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4212. {
  4213. tempIndex = ((gun_index==2) ? 1: 0);
  4214. }
  4215. else
  4216. {
  4217. tempIndex = gun_index;
  4218. }
  4219. for (int index = 0; index < CCS_QUANTITY; index++)
  4220. {
  4221. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4222. {
  4223. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4224. }
  4225. } // END OF FOR CCS_QUANTITY
  4226. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4227. }
  4228. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4229. {
  4230. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4231. {
  4232. tempIndex = ((gun_index==2) ? 1: 0);
  4233. }
  4234. else
  4235. {
  4236. tempIndex = gun_index;
  4237. }
  4238. for (int index = 0; index < GB_QUANTITY; index++)
  4239. {
  4240. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4241. {
  4242. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4243. }
  4244. } // END OF FOR GB_QUANTITY
  4245. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4246. }
  4247. else if(gunType[gun_index] == GUN_TYPE_DO)
  4248. {
  4249. tempIndex = gun_index;
  4250. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4251. {
  4252. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4253. {
  4254. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4255. }
  4256. }
  4257. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4258. }
  4259. else
  4260. {
  4261. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4262. {
  4263. tempIndex = 2;
  4264. }
  4265. else
  4266. {
  4267. tempIndex = gun_index;
  4268. }
  4269. for (int index = 0; index < AC_QUANTITY; index++)
  4270. {
  4271. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4272. {
  4273. 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
  4274. }
  4275. } // END OF FOR AC_QUANTITY
  4276. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  4277. }
  4278. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4279. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  4280. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  4281. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  4282. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4283. }
  4284. //====================== End SoC ================================
  4285. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4286. {
  4287. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4288. 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))
  4289. {
  4290. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4291. {
  4292. tempIndex = ((gun_index==2) ? 1: 0);
  4293. }
  4294. else
  4295. {
  4296. tempIndex = gun_index;
  4297. }
  4298. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  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[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  4305. }
  4306. }
  4307. }
  4308. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4309. {
  4310. for (int index = 0; index < CCS_QUANTITY; index++)
  4311. {
  4312. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4313. {
  4314. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  4315. }
  4316. }
  4317. }
  4318. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4319. {
  4320. for (int index = 0; index < GB_QUANTITY; index++)
  4321. {
  4322. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4323. {
  4324. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  4325. }
  4326. }
  4327. }
  4328. else if(gunType[gun_index] == GUN_TYPE_DO)
  4329. {
  4330. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4331. {
  4332. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4333. {
  4334. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  4335. }
  4336. }
  4337. }
  4338. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4339. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  4340. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4341. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  4342. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  4343. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4344. } // END FOR DC CASE
  4345. }
  4346. // ================================= Current.Import L2 ===============================================
  4347. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4348. {
  4349. // AC 3 phse L2 current
  4350. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4351. {
  4352. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4353. {
  4354. tempIndex = 2;
  4355. }
  4356. else
  4357. {
  4358. tempIndex = gun_index;
  4359. }
  4360. for (int index = 0; index < AC_QUANTITY; index++)
  4361. {
  4362. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4363. {
  4364. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  4365. }
  4366. }// End of for AC_QUANTITY
  4367. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  4368. }
  4369. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4370. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  4371. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  4372. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  4373. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4374. }
  4375. // ================================= Current.Import L3 ===============================================
  4376. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4377. {
  4378. // AC 3 phse L3 current
  4379. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4380. {
  4381. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4382. {
  4383. tempIndex = 2;
  4384. }
  4385. else
  4386. {
  4387. tempIndex = gun_index;
  4388. }
  4389. for (int index = 0; index < AC_QUANTITY; index++)
  4390. {
  4391. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4392. {
  4393. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  4394. }
  4395. }// End of for AC_QUANTITY
  4396. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  4397. }
  4398. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4399. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  4400. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  4401. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  4402. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4403. }
  4404. //============================ Voltage L2 ====================================
  4405. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4406. {
  4407. // AC 3 phse L2 voltage
  4408. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4409. {
  4410. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4411. {
  4412. tempIndex = 2;
  4413. }
  4414. else
  4415. {
  4416. tempIndex = gun_index;
  4417. }
  4418. for (int index = 0; index < AC_QUANTITY; index++)
  4419. {
  4420. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4421. {
  4422. 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
  4423. }
  4424. } // END OF FOR AC_QUANTITY
  4425. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  4426. }
  4427. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4428. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  4429. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  4430. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  4431. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4432. }
  4433. //============================ Voltage L3 ====================================
  4434. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4435. {
  4436. // AC 3 phse L3 voltage
  4437. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4438. {
  4439. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4440. {
  4441. tempIndex = 2;
  4442. }
  4443. else
  4444. {
  4445. tempIndex = gun_index;
  4446. }
  4447. for (int index = 0; index < AC_QUANTITY; index++)
  4448. {
  4449. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4450. {
  4451. 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
  4452. }
  4453. } // END OF FOR AC_QUANTITY
  4454. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  4455. }
  4456. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4457. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  4458. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  4459. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  4460. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4461. }
  4462. //====================== Start SoC ================================
  4463. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4464. {
  4465. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4466. 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))
  4467. {
  4468. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4469. {
  4470. tempIndex = ((gun_index==2) ? 1: 0);
  4471. }
  4472. else
  4473. {
  4474. tempIndex = gun_index;
  4475. }
  4476. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4477. {
  4478. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4479. {
  4480. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4481. {
  4482. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  4483. }
  4484. }
  4485. }
  4486. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4487. {
  4488. for (int index = 0; index < CCS_QUANTITY; index++)
  4489. {
  4490. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4491. {
  4492. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  4493. }
  4494. }
  4495. }
  4496. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4497. {
  4498. for (int index = 0; index < GB_QUANTITY; index++)
  4499. {
  4500. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4501. {
  4502. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  4503. }
  4504. }
  4505. }
  4506. else if(gunType[gun_index] == GUN_TYPE_DO)
  4507. {
  4508. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4509. {
  4510. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4511. {
  4512. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  4513. }
  4514. }
  4515. }
  4516. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4517. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  4518. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4519. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  4520. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  4521. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4522. } // END FOR DC CASE
  4523. }
  4524. //================================================ Message create ====================================================
  4525. json_object *StopTransaction = json_object_new_object();
  4526. json_object *transactionDatas = json_object_new_array();
  4527. json_object *sampledValues = json_object_new_array();
  4528. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  4529. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  4530. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  4531. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  4532. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  4533. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  4534. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  4535. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  4536. {
  4537. json_object *transactionData = json_object_new_object();
  4538. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  4539. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  4540. {
  4541. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  4542. {
  4543. json_object *sampledValue = json_object_new_object();
  4544. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  4545. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  4546. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  4547. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  4548. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  4549. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  4550. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  4551. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  4552. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  4553. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  4554. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  4555. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  4556. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  4557. json_object_array_add(sampledValues, sampledValue);
  4558. }
  4559. }
  4560. json_object_object_add(transactionData, "sampledValue", sampledValues);
  4561. json_object_array_add(transactionDatas, transactionData);
  4562. }
  4563. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  4564. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  4565. ,MESSAGE_TYPE_CALL
  4566. ,guid
  4567. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  4568. json_object_put(StopTransaction);
  4569. #if 1 // for TempStopTransaction
  4570. //Delete TempStopTransaction
  4571. if((access(TempStopTransaction,F_OK))!=-1)
  4572. {
  4573. remove(TempStopTransaction); // remove file "TempStopTransaction"
  4574. }
  4575. #endif
  4576. #if 1
  4577. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4578. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4579. {
  4580. result = PASS;
  4581. //DEBUG_INFO("StopTransaction mapitem pass\n");
  4582. }
  4583. #endif
  4584. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4585. OCPP_insert_transaction_msg(NO, queuedata);
  4586. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4587. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  4588. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  4589. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4590. {
  4591. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  4592. }
  4593. //for test
  4594. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4595. return result;
  4596. }
  4597. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  4598. {
  4599. mtrace();
  4600. int result = FAIL;
  4601. char guid[37]={0};
  4602. char tempdata[65]={0};
  4603. int tempIndex = 0;
  4604. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4605. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4606. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  4607. //set value
  4608. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4609. 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) )?
  4610. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  4611. -1);
  4612. random_uuid(guid);
  4613. //UTC Date time
  4614. struct timeval tmnow;
  4615. struct tm *tm;
  4616. char buf[28];//, usec_buf[6];
  4617. gettimeofday(&tmnow, NULL);
  4618. time_t t;
  4619. t = time(NULL);
  4620. /*UTC time and date*/
  4621. tm = gmtime(&t);
  4622. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4623. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4624. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4625. //********************************(1)Current.Import L1************************************************/
  4626. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  4627. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  4628. (dataType == ReadingContext_Trigger))
  4629. {
  4630. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4631. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4632. {
  4633. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4634. {
  4635. tempIndex = ((gun_index==2) ? 1: 0);
  4636. }
  4637. else
  4638. {
  4639. tempIndex = gun_index;
  4640. }
  4641. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4642. {
  4643. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4644. {
  4645. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4646. }
  4647. }
  4648. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4649. }
  4650. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4651. {
  4652. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4653. {
  4654. tempIndex = ((gun_index==2) ? 1: 0);
  4655. }
  4656. else
  4657. {
  4658. tempIndex = gun_index;
  4659. }
  4660. for (int index = 0; index < CCS_QUANTITY; index++)
  4661. {
  4662. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4663. {
  4664. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4665. }
  4666. }
  4667. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4668. }
  4669. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4670. {
  4671. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4672. {
  4673. tempIndex = ((gun_index==2) ? 1: 0);
  4674. }
  4675. else
  4676. {
  4677. tempIndex = gun_index;
  4678. }
  4679. for (int index = 0; index < GB_QUANTITY; index++)
  4680. {
  4681. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4682. {
  4683. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4684. }
  4685. }
  4686. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4687. }
  4688. else if(gunType[gun_index] == GUN_TYPE_DO)
  4689. {
  4690. tempIndex = gun_index;
  4691. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4692. {
  4693. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4694. {
  4695. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  4696. }
  4697. }
  4698. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4699. }
  4700. else
  4701. {
  4702. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4703. {
  4704. tempIndex = 2;
  4705. }
  4706. else
  4707. {
  4708. tempIndex = gun_index;
  4709. }
  4710. for (int index = 0; index < AC_QUANTITY; index++)
  4711. {
  4712. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4713. {
  4714. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4715. }
  4716. }
  4717. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4718. }
  4719. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4720. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4721. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4722. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4723. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4724. }
  4725. //********************************(2)Energy.Active.Import.Register ************************************************/
  4726. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4727. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Register") != 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[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4746. }
  4747. }
  4748. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].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[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4765. }
  4766. }
  4767. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].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[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4784. }
  4785. }
  4786. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].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[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  4796. }
  4797. }
  4798. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].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[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  4815. }
  4816. }
  4817. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4818. }
  4819. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  4820. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  4821. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  4822. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  4823. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4824. }
  4825. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  4826. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  4827. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Interval") != 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[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  4846. }
  4847. } // END OF FOR CHAdeMO_QUANTITY
  4848. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].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[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  4865. }
  4866. } // END OF CCS_QUANTITY
  4867. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].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[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  4884. }
  4885. } // END OF GB_QUANTITY
  4886. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].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[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  4896. }
  4897. }
  4898. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].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[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  4915. }
  4916. }
  4917. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  4918. }
  4919. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  4920. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  4921. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  4922. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  4923. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4924. }
  4925. //********************************(4)Power.Active.Import************************************************/
  4926. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Power.Active.Import") != NULL)) ||
  4927. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Power.Active.Import") != 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[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  4946. }
  4947. } // END OF FOR
  4948. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].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[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  4965. }
  4966. }
  4967. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].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. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4984. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  4985. }
  4986. }
  4987. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4988. }
  4989. else if(gunType[gun_index] == GUN_TYPE_DO)
  4990. {
  4991. tempIndex = gun_index;
  4992. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4993. {
  4994. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4995. {
  4996. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4997. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  4998. }
  4999. }
  5000. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5001. }
  5002. else
  5003. {
  5004. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5005. {
  5006. tempIndex = 2;
  5007. }
  5008. else
  5009. {
  5010. tempIndex = gun_index;
  5011. }
  5012. for (int index = 0; index < AC_QUANTITY; index++)
  5013. {
  5014. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5015. {
  5016. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  5017. }
  5018. }
  5019. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  5020. }
  5021. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  5022. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  5023. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  5024. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  5025. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  5026. }
  5027. //***********************************************(5)VOLTAGE L1******************************************************/
  5028. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5029. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5030. (dataType == ReadingContext_Trigger))
  5031. {
  5032. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5033. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5034. {
  5035. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5036. {
  5037. tempIndex = ((gun_index==2) ? 1: 0);
  5038. }
  5039. else
  5040. {
  5041. tempIndex = gun_index;
  5042. }
  5043. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5044. {
  5045. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5046. {
  5047. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  5048. }
  5049. }
  5050. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5051. }
  5052. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5053. {
  5054. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5055. {
  5056. tempIndex = ((gun_index==2) ? 1: 0);
  5057. }
  5058. else
  5059. {
  5060. tempIndex = gun_index;
  5061. }
  5062. for (int index = 0; index < CCS_QUANTITY; index++)
  5063. {
  5064. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5065. {
  5066. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  5067. }
  5068. }
  5069. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5070. }
  5071. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5072. {
  5073. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5074. {
  5075. tempIndex = ((gun_index==2) ? 1: 0);
  5076. }
  5077. else
  5078. {
  5079. tempIndex = gun_index;
  5080. }
  5081. for (int index = 0; index < GB_QUANTITY; index++)
  5082. {
  5083. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5084. {
  5085. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  5086. }
  5087. }
  5088. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5089. }
  5090. else if(gunType[gun_index] == GUN_TYPE_DO)
  5091. {
  5092. tempIndex = gun_index;
  5093. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5094. {
  5095. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5096. {
  5097. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  5098. }
  5099. }
  5100. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].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[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  5117. }
  5118. }
  5119. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  5120. }
  5121. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  5122. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  5123. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  5124. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  5125. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5126. }
  5127. //***********************************************(6)SOC******************************************************/
  5128. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "SOC") != NULL)) ||
  5129. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "SOC") != NULL)) ||
  5130. (dataType == ReadingContext_Trigger))
  5131. {
  5132. 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))
  5133. {
  5134. //idx_sample=5;
  5135. //sampledValue = NULL;
  5136. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5137. {
  5138. tempIndex = ((gun_index==2) ? 1: 0);
  5139. }
  5140. else
  5141. {
  5142. tempIndex = gun_index;
  5143. }
  5144. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5145. {
  5146. //tempIndex = ((gun_index==2) ? 1: 0);
  5147. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5148. {
  5149. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5150. {
  5151. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  5152. }
  5153. }
  5154. }
  5155. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5156. {
  5157. //tempIndex = ((gun_index==2) ? 1: 0);
  5158. for (int index = 0; index < CCS_QUANTITY; index++)
  5159. {
  5160. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5161. {
  5162. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  5163. }
  5164. }
  5165. }
  5166. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5167. {
  5168. //tempIndex = ((gun_index==2) ? 1: 0);
  5169. for (int index = 0; index < GB_QUANTITY; index++)
  5170. {
  5171. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5172. {
  5173. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  5174. }
  5175. }
  5176. }
  5177. else if(gunType[gun_index] == GUN_TYPE_DO)
  5178. {
  5179. //tempIndex = ((gun_index==2) ? 1: 0);
  5180. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5181. {
  5182. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5183. {
  5184. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  5185. }
  5186. }
  5187. }
  5188. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  5189. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  5190. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  5191. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  5192. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  5193. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  5194. }
  5195. }
  5196. //********************************(7)Current.Import L2************************************************/
  5197. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5198. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5199. (dataType == ReadingContext_Trigger))
  5200. {
  5201. // Only for AC 3 phase
  5202. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  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[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  5217. }
  5218. }
  5219. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  5220. }
  5221. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  5222. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  5223. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  5224. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  5225. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5226. }
  5227. //********************************(8)Current.Import L3************************************************/
  5228. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5229. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5230. (dataType == ReadingContext_Trigger))
  5231. {
  5232. // Only for AC 3 phase
  5233. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5234. {
  5235. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5236. {
  5237. tempIndex = 2;
  5238. }
  5239. else
  5240. {
  5241. tempIndex = gun_index;
  5242. }
  5243. for (int index = 0; index < AC_QUANTITY; index++)
  5244. {
  5245. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5246. {
  5247. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  5248. }
  5249. }
  5250. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  5251. }
  5252. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  5253. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  5254. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  5255. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  5256. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5257. }
  5258. //***********************************************(9)VOLTAGE L2******************************************************/
  5259. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5260. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5261. (dataType == ReadingContext_Trigger))
  5262. {
  5263. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5264. {
  5265. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5266. {
  5267. tempIndex = 2;
  5268. }
  5269. else
  5270. {
  5271. tempIndex = gun_index;
  5272. }
  5273. for (int index = 0; index < AC_QUANTITY; index++)
  5274. {
  5275. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5276. {
  5277. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  5278. }
  5279. }
  5280. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  5281. }
  5282. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  5283. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  5284. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  5285. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  5286. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5287. }
  5288. //***********************************************(10)VOLTAGE L3******************************************************/
  5289. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5290. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5291. (dataType == ReadingContext_Trigger))
  5292. {
  5293. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5294. {
  5295. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5296. {
  5297. tempIndex = 2;
  5298. }
  5299. else
  5300. {
  5301. tempIndex = gun_index;
  5302. }
  5303. for (int index = 0; index < AC_QUANTITY; index++)
  5304. {
  5305. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5306. {
  5307. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  5308. }
  5309. }
  5310. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  5311. }
  5312. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  5313. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  5314. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  5315. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  5316. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5317. }
  5318. // Message create ====================================================================================================
  5319. if(TRUE)
  5320. {
  5321. json_object *MeterValueReq = json_object_new_object();
  5322. json_object *MeterValues = json_object_new_array();
  5323. json_object *sampledValues = json_object_new_array();
  5324. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  5325. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  5326. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  5327. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  5328. {
  5329. json_object *MeterValue = json_object_new_object();
  5330. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  5331. {
  5332. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  5333. {
  5334. json_object *sampledValue = json_object_new_object();
  5335. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  5336. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  5337. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  5338. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  5339. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  5340. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  5341. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  5342. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  5343. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  5344. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  5345. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  5346. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  5347. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  5348. json_object_array_add(sampledValues, sampledValue);
  5349. }
  5350. }
  5351. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  5352. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  5353. json_object_array_add(MeterValues, MeterValue);
  5354. }
  5355. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  5356. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  5357. ,gun_index + 1
  5358. ,MESSAGE_TYPE_CALL
  5359. ,guid
  5360. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  5361. json_object_put(MeterValueReq);
  5362. }
  5363. // Put request guid to hash map
  5364. sprintf(tempdata, "MeterValues,%d", (gun_index));
  5365. 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*/)
  5366. {
  5367. result = PASS;
  5368. //DEBUG_INFO("MeterValues mapitem pass\n");
  5369. }
  5370. if((dataType != ReadingContext_Trigger) &&
  5371. (dataType != ReadingContext_Sample_Clock) &&
  5372. (ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1))
  5373. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  5374. else
  5375. {
  5376. if(FirstHeartBeat)
  5377. LWS_Send(queuedata +2);
  5378. }
  5379. return result;
  5380. }
  5381. //==========================================
  5382. // send confirm routine
  5383. //==========================================
  5384. int sendCancelReservationConfirmation(char *uuid,char *payload)
  5385. {
  5386. mtrace();
  5387. int result = FAIL;
  5388. char message[100]={0};
  5389. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  5390. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5391. LWS_Send(message);
  5392. result = TRUE;
  5393. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  5394. return result;
  5395. }
  5396. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  5397. {
  5398. mtrace();
  5399. int result = FAIL;
  5400. char message[100]={0};
  5401. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  5402. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5403. LWS_Send(message);
  5404. result = TRUE;
  5405. return result;
  5406. }
  5407. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  5408. {
  5409. mtrace();
  5410. int result = FAIL;
  5411. char message[100]={0};
  5412. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  5413. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5414. LWS_Send(message);
  5415. result = TRUE;
  5416. return result;
  5417. }
  5418. int sendClearCacheConfirmation(char *uuid,char *payload)
  5419. {
  5420. mtrace();
  5421. int result = FAIL;
  5422. char message[500]={0};
  5423. DEBUG_INFO("sendClearCacheConfirmation...\n");
  5424. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5425. LWS_Send(message);
  5426. return result;
  5427. }
  5428. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  5429. {
  5430. mtrace();
  5431. int result = FAIL;
  5432. char message[500]={0};
  5433. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  5434. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5435. LWS_Send(message);
  5436. return result;
  5437. }
  5438. int sendDataTransferConfirmation(char *uuid,char *payload)
  5439. {
  5440. mtrace();
  5441. char statusStr[20]={0};
  5442. char dataStr[10]={0};
  5443. char sstr[20]={0};
  5444. int c = 0;
  5445. char *loc;
  5446. int result = FAIL;
  5447. DEBUG_INFO("sendDataTransferConfirmation...\n");
  5448. /**********************status**************************/
  5449. loc = strstr(payload, "status");
  5450. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5451. c = 0;
  5452. while (loc[3+strlen("status")+c] != '\"')
  5453. {
  5454. sstr[c] = loc[3+strlen("status")+c];
  5455. c++;
  5456. }
  5457. sstr[c] = '\0';
  5458. strcpy(statusStr, sstr);
  5459. /**********************data**************************/
  5460. loc = strstr(payload, "data");
  5461. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5462. c = 0;
  5463. while (loc[3+strlen("data")+c] != '\"')
  5464. {
  5465. sstr[c] = loc[3+strlen("data")+c];
  5466. c++;
  5467. }
  5468. sstr[c] = '\0';
  5469. strcpy(dataStr, sstr);
  5470. return result;
  5471. }
  5472. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  5473. {
  5474. mtrace();
  5475. int result = FAIL;
  5476. char message[1000]={0};
  5477. int CompositeScheduleIndex = 0;
  5478. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  5479. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  5480. if(nPeriod == 0)
  5481. {
  5482. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  5483. {
  5484. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  5485. ,MESSAGE_TYPE_CALLRESULT
  5486. ,uuid
  5487. ,payload
  5488. ,connectorIdInt);
  5489. }
  5490. else
  5491. {
  5492. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  5493. ,MESSAGE_TYPE_CALLRESULT
  5494. ,uuid
  5495. ,payload
  5496. ,connectorIdInt
  5497. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5498. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5499. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5500. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  5501. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  5502. }
  5503. }
  5504. else
  5505. {
  5506. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  5507. ,MESSAGE_TYPE_CALLRESULT
  5508. ,uuid
  5509. ,payload
  5510. ,connectorIdInt
  5511. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5512. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5513. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5514. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  5515. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  5516. {
  5517. if (idx_sample == 0)
  5518. {
  5519. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5520. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5521. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5522. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5523. }
  5524. else
  5525. {
  5526. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5527. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5528. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5529. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5530. }
  5531. }
  5532. sprintf(message + strlen(message), "]}}]");
  5533. }
  5534. LWS_Send(message);
  5535. result = TRUE;
  5536. return result;
  5537. }
  5538. int sendGetConfigurationConfirmation(char *uuid)
  5539. {
  5540. mtrace();
  5541. int result = FAIL;
  5542. int MaxKeySupported = 0;
  5543. int sentConfigurationNumber= 0;
  5544. int sentunConfigurationNumber= 0;
  5545. char message[4000]={0};
  5546. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  5547. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  5548. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  5549. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  5550. ,MESSAGE_TYPE_CALLRESULT
  5551. ,uuid );
  5552. //configuration key
  5553. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  5554. {
  5555. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  5556. {
  5557. if (sentConfigurationNumber == 0)
  5558. {
  5559. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5560. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5561. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5562. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5563. }
  5564. else
  5565. {
  5566. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5567. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5568. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5569. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5570. }
  5571. sentConfigurationNumber = sentConfigurationNumber + 1;
  5572. }
  5573. }
  5574. sprintf(message + strlen(message), "]");
  5575. if(UnknownKeynum != 0)
  5576. {
  5577. sprintf(message + strlen(message), ",\"unknownKey\":[");
  5578. //unkown key
  5579. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  5580. {
  5581. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  5582. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  5583. if(sentunConfigurationNumber == 0)
  5584. {
  5585. sprintf(message + strlen(message), "\"%s\""
  5586. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5587. }
  5588. else
  5589. {
  5590. sprintf(message + strlen(message), ",\"%s\""
  5591. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5592. }
  5593. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  5594. }
  5595. sprintf(message + strlen(message), "]");
  5596. }
  5597. sprintf(message + strlen(message), "}]");
  5598. LWS_Send(message);
  5599. return result;
  5600. }
  5601. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  5602. {
  5603. mtrace();
  5604. int result = FAIL;
  5605. char message[400]={0};
  5606. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  5607. if(strcmp(payload,"")==0)
  5608. {
  5609. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5610. }
  5611. else
  5612. {
  5613. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5614. }
  5615. LWS_Send(message);
  5616. result = TRUE;
  5617. return result;
  5618. }
  5619. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  5620. {
  5621. mtrace();
  5622. int result = FAIL;
  5623. char message[80]={0};
  5624. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  5625. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  5626. LWS_Send(message);
  5627. result = TRUE;
  5628. return result;
  5629. }
  5630. int sendRemoteStartConfirmation(char *uuid,char *payload)
  5631. {
  5632. mtrace();
  5633. int result = FAIL;
  5634. char message[80]={0};
  5635. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  5636. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5637. LWS_Send(message);
  5638. result = TRUE;
  5639. return result;
  5640. }
  5641. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5642. {
  5643. mtrace();
  5644. int result = FAIL;
  5645. char message[80]={0};
  5646. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5647. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5648. LWS_Send(message);
  5649. result = TRUE;
  5650. return result;
  5651. }
  5652. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5653. {
  5654. mtrace();
  5655. int result = FAIL;
  5656. char message[80]={0};
  5657. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5658. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  5659. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5660. LWS_Send(message);
  5661. result = TRUE;
  5662. return result;
  5663. }
  5664. int sendResetConfirmation(char *uuid,char *payload)
  5665. {
  5666. mtrace();
  5667. int result = FAIL;
  5668. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  5669. char message[80]={0};
  5670. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  5671. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5672. LWS_Send(message);
  5673. result = TRUE;
  5674. return result;
  5675. }
  5676. int sendSendLocalListConfirmation(char *uuid,char *payload)
  5677. {
  5678. mtrace();
  5679. int result = FAIL;
  5680. char message[500]={0};
  5681. // [ 3, "1571284266109", { "status": "Accepted" } ]
  5682. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5683. LWS_Send(message);
  5684. result = TRUE;
  5685. return result;
  5686. }
  5687. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  5688. {
  5689. mtrace();
  5690. int result = FAIL;
  5691. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  5692. char message[80]={0};
  5693. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  5694. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5695. LWS_Send(message);
  5696. result = TRUE;
  5697. return result;
  5698. }
  5699. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  5700. {
  5701. mtrace();
  5702. int result = FAIL;
  5703. char message[80]={0};
  5704. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  5705. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5706. LWS_Send(message);
  5707. result = TRUE;
  5708. return result;
  5709. }
  5710. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  5711. {
  5712. mtrace();
  5713. int result = FAIL;
  5714. char message[80]={0};
  5715. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5716. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  5717. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5718. LWS_Send(message);
  5719. result = TRUE;
  5720. return result;
  5721. }
  5722. int sendUpdateFirmwareConfirmation(char *uuid)
  5723. {
  5724. mtrace();
  5725. int result = FAIL;
  5726. char message[60]={0};
  5727. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5728. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  5729. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5730. LWS_Send(message);
  5731. result = TRUE;
  5732. return result;
  5733. }
  5734. int sendUnknownConfirmation(char *uuid)
  5735. {
  5736. mtrace();
  5737. int result = FAIL;
  5738. char message[256]={0};
  5739. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5740. DEBUG_INFO("sendUnknownConfirmation...\n");
  5741. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  5742. LWS_Send(message);
  5743. result = TRUE;
  5744. return result;
  5745. }
  5746. //==========================================
  5747. // Handle server request routine Start
  5748. //==========================================
  5749. int handleCancelReservationRequest(char *uuid, char *payload)
  5750. {
  5751. mtrace();
  5752. int result = FAIL;
  5753. int gunNO = 0;
  5754. int reservationIdInt = -1;
  5755. char comfirmstr[20];
  5756. DEBUG_INFO("handleCancelReservationRequest...\n");
  5757. json_object *CancelReservation;
  5758. CancelReservation = json_tokener_parse(payload);
  5759. if(!is_error(CancelReservation))
  5760. {
  5761. // Required data
  5762. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  5763. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  5764. }
  5765. json_object_put(CancelReservation);
  5766. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  5767. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5768. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  5769. if(reservationIdInt != -1)
  5770. {
  5771. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  5772. //check Transaction active
  5773. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5774. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5775. {
  5776. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  5777. {
  5778. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5779. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5780. if(gunType[2] == GUN_TYPE_CHAdeMO)
  5781. {
  5782. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  5783. }
  5784. else
  5785. {
  5786. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  5787. }
  5788. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5789. goto end;
  5790. }
  5791. }
  5792. for (int index = 0; index < CCS_QUANTITY; index++)
  5793. {
  5794. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  5795. {
  5796. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5797. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5798. if(gunType[2] == GUN_TYPE_CCS)
  5799. {
  5800. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  5801. }
  5802. else
  5803. {
  5804. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  5805. }
  5806. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5807. goto end;
  5808. }
  5809. }
  5810. for (int index = 0; index < GB_QUANTITY; index++)
  5811. {
  5812. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  5813. {
  5814. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5815. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5816. if(gunType[2] == GUN_TYPE_GBT)
  5817. {
  5818. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  5819. }
  5820. else
  5821. {
  5822. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  5823. }
  5824. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5825. goto end;
  5826. }
  5827. }
  5828. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5829. {
  5830. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  5831. {
  5832. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5833. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5834. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  5835. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5836. goto end;
  5837. }
  5838. }
  5839. for (int index = 0; index < AC_QUANTITY; index++)
  5840. {
  5841. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  5842. {
  5843. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5844. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5845. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5846. {
  5847. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  5848. }
  5849. else
  5850. {
  5851. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  5852. }
  5853. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5854. goto end;
  5855. }
  5856. }
  5857. }
  5858. //The reservationId does NOT match the reservationId
  5859. sendCancelReservationConfirmation(uuid, comfirmstr);
  5860. end:
  5861. // Fill in ocpp packet uuid
  5862. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  5863. return result;
  5864. }
  5865. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  5866. {
  5867. mtrace();
  5868. int result = FAIL;
  5869. int gunIndex = 0;
  5870. char typeStr[16]={0};
  5871. char comfirmstr[20];
  5872. int specificId = FALSE;
  5873. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  5874. json_object *ChangeAvailability;
  5875. ChangeAvailability = json_tokener_parse(payload);
  5876. if(!is_error(ChangeAvailability))
  5877. {
  5878. // Required data
  5879. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  5880. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  5881. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  5882. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  5883. }
  5884. json_object_put(ChangeAvailability);
  5885. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5886. {
  5887. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  5888. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  5889. }
  5890. else if(gunIndex == 0)
  5891. {
  5892. for(int i=0; i < gunTotalNumber; i++)
  5893. {
  5894. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  5895. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  5896. }
  5897. }
  5898. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5899. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5900. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  5901. {
  5902. specificId = TRUE;
  5903. }
  5904. if(specificId == FALSE)
  5905. goto end;
  5906. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  5907. {
  5908. //----------------------gunIndex is 0 ------------------------------------------------//
  5909. if(gunIndex == 0)
  5910. {
  5911. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5912. {
  5913. for(int i=0; i < gunTotalNumber; i++)
  5914. {
  5915. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5916. {
  5917. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  5918. {
  5919. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5920. {
  5921. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5922. goto end;
  5923. }
  5924. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5925. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5926. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5927. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5928. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5929. {
  5930. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5931. goto end;
  5932. }
  5933. }
  5934. }//END FOR CHAdeMO_QUANTITY
  5935. for (int index = 0; index < CCS_QUANTITY; index++)
  5936. {
  5937. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  5938. {
  5939. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  5940. {
  5941. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5942. goto end;
  5943. }
  5944. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5945. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5946. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5947. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5948. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5949. {
  5950. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5951. goto end;
  5952. }
  5953. }
  5954. }//END FOR CCS_QUANTITY
  5955. for (int index = 0; index < GB_QUANTITY; index++)
  5956. {
  5957. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  5958. {
  5959. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5960. {
  5961. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5962. goto end;
  5963. }
  5964. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5965. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5966. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5967. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5968. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5969. {
  5970. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5971. goto end;
  5972. }
  5973. }
  5974. }// END FOR GB_QUANTITY
  5975. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5976. {
  5977. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  5978. {
  5979. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5980. {
  5981. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5982. goto end;
  5983. }
  5984. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  5985. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  5986. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  5987. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  5988. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5989. {
  5990. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5991. goto end;
  5992. }
  5993. }
  5994. }// END FOR GENERAL_GUN_QUANTITY
  5995. for (int index = 0; index < AC_QUANTITY; index++)
  5996. {
  5997. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  5998. {
  5999. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6000. {
  6001. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6002. goto end;
  6003. }
  6004. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6005. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6006. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6007. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6008. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6009. {
  6010. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6011. goto end;
  6012. }
  6013. }
  6014. }//END FOR AC_QUANTITY
  6015. }// END FOR gunTotalNumber
  6016. }
  6017. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6018. {
  6019. for(int i=0; i < gunTotalNumber; i++)
  6020. {
  6021. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6022. {
  6023. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6024. goto end;
  6025. }
  6026. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6027. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  6028. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  6029. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  6030. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6031. {
  6032. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6033. goto end;
  6034. }
  6035. }
  6036. }
  6037. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6038. goto end;
  6039. }
  6040. //----------------------gunIndex is not 0 ------------------------------------------------//
  6041. //check Transaction active
  6042. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6043. {
  6044. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  6045. {
  6046. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  6047. {
  6048. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6049. goto end;
  6050. }
  6051. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6052. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6053. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6054. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6055. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6056. {
  6057. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6058. goto end;
  6059. }
  6060. else
  6061. {
  6062. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  6063. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6064. goto end;
  6065. }
  6066. }
  6067. }//END FOR CHAdeMO_QUANTITY
  6068. for (int index = 0; index < CCS_QUANTITY; index++)
  6069. {
  6070. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  6071. {
  6072. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  6073. {
  6074. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6075. goto end;
  6076. }
  6077. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6078. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6079. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6080. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6081. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6082. {
  6083. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6084. goto end;
  6085. }
  6086. else
  6087. {
  6088. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  6089. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6090. goto end;
  6091. }
  6092. }
  6093. }//END FOR CCS_QUANTITY
  6094. for (int index = 0; index < GB_QUANTITY; index++)
  6095. {
  6096. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  6097. {
  6098. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6099. {
  6100. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6101. goto end;
  6102. }
  6103. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6104. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6105. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6106. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6107. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6108. {
  6109. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6110. goto end;
  6111. }
  6112. else
  6113. {
  6114. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  6115. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6116. goto end;
  6117. }
  6118. }
  6119. }// END FOR GB_QUANTITY
  6120. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6121. {
  6122. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  6123. {
  6124. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6125. {
  6126. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6127. goto end;
  6128. }
  6129. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  6130. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  6131. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  6132. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  6133. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6134. {
  6135. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6136. goto end;
  6137. }
  6138. else
  6139. {
  6140. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  6141. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6142. goto end;
  6143. }
  6144. }
  6145. }// END FOR GENERAL_GUN_QUANTITY
  6146. for (int index = 0; index < AC_QUANTITY; index++)
  6147. {
  6148. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  6149. {
  6150. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6151. {
  6152. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6153. goto end;
  6154. }
  6155. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6156. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6157. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6158. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6159. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6160. {
  6161. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6162. goto end;
  6163. }
  6164. else
  6165. {
  6166. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  6167. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6168. goto end;
  6169. }
  6170. }
  6171. }//END FOR AC_QUANTITY
  6172. }//END FOR AvailabilityTypeStr[Inoperative]
  6173. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  6174. {
  6175. //----------------------gunIndex is 0 ------------------------------------------------//
  6176. if(gunIndex == 0)
  6177. {
  6178. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6179. {
  6180. for(int i=0; i < gunTotalNumber; i++)
  6181. {
  6182. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6183. {
  6184. 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
  6185. {
  6186. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6187. goto end;
  6188. }
  6189. }//END FOR CHAdeMO_QUANTITY
  6190. for (int index = 0; index < CCS_QUANTITY; index++)
  6191. {
  6192. 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
  6193. {
  6194. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6195. goto end;
  6196. }
  6197. }//END FOR CCS_QUANTITY
  6198. for (int index = 0; index < GB_QUANTITY; index++)
  6199. {
  6200. 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
  6201. {
  6202. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6203. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6204. goto end;
  6205. }
  6206. }// END FOR GB_QUANTITY
  6207. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6208. {
  6209. 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
  6210. {
  6211. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6212. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6213. goto end;
  6214. }
  6215. }// END FOR GENERAL_GUN_QUANTITY
  6216. for (int index = 0; index < AC_QUANTITY; index++)
  6217. {
  6218. 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
  6219. {
  6220. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6221. goto end;
  6222. }
  6223. }//END FOR CHAdeMO_QUANTITY
  6224. }// END FOR gunTotalNumber
  6225. }
  6226. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6227. {
  6228. for(int i=0; i < gunTotalNumber; i++)
  6229. {
  6230. for (int index = 0; index < AC_QUANTITY; index++)
  6231. {
  6232. 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
  6233. {
  6234. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6235. goto end;
  6236. }
  6237. }//END FOR CHAdeMO_QUANTITY
  6238. } // END FOR gunTotalNumber
  6239. }
  6240. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6241. goto end;
  6242. }
  6243. //----------------------gunIndex is not 0 ------------------------------------------------//
  6244. //check Transaction active
  6245. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6246. {
  6247. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6248. {
  6249. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6250. goto end;
  6251. }
  6252. }//END FOR CHAdeMO_QUANTITY
  6253. for (int index = 0; index < CCS_QUANTITY; index++)
  6254. {
  6255. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6256. {
  6257. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6258. goto end;
  6259. }
  6260. }//END FOR CCS_QUANTITY
  6261. for (int index = 0; index < GB_QUANTITY; index++)
  6262. {
  6263. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6264. {
  6265. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6266. goto end;
  6267. }
  6268. }// END FOR GB_QUANTITY
  6269. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6270. {
  6271. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6272. {
  6273. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6274. goto end;
  6275. }
  6276. }// END FOR GENERAL_GUN_QUANTITY
  6277. for (int index = 0; index < AC_QUANTITY; index++)
  6278. {
  6279. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6280. {
  6281. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6282. goto end;
  6283. }
  6284. }//END FOR AC_QUANTITY
  6285. }//END FOR AvailabilityTypeStr[Operative]
  6286. end:
  6287. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6288. {
  6289. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  6290. }
  6291. else
  6292. {
  6293. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  6294. }
  6295. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6296. {
  6297. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6298. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6299. }
  6300. else if(gunIndex == 0)
  6301. {
  6302. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6303. {
  6304. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  6305. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  6306. }
  6307. }
  6308. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  6309. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6310. return result;
  6311. }
  6312. int handleChangeConfigurationRequest(char *uuid, char *payload)
  6313. {
  6314. mtrace();
  6315. int result = FAIL;
  6316. char keystr[40]={0};
  6317. char valuestr[256]={0};
  6318. char comfirmstr[20]={0};
  6319. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  6320. json_object *ChangeConfiguration;
  6321. ChangeConfiguration = json_tokener_parse(payload);
  6322. if(!is_error(ChangeConfiguration))
  6323. {
  6324. // Required data
  6325. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  6326. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  6327. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  6328. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  6329. }
  6330. json_object_put(ChangeConfiguration);
  6331. if((uuid==NULL) || (payload ==NULL) )
  6332. {
  6333. DEBUG_ERROR("Payload is null\n");
  6334. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6335. }
  6336. else
  6337. {
  6338. int status = setKeyValue(keystr, valuestr);
  6339. switch(status)
  6340. {
  6341. case ConfigurationStatus_Accepted:
  6342. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  6343. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  6344. StoreConfigurationTable();
  6345. break;
  6346. case RebootRequired:
  6347. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  6348. StoreConfigurationTable();
  6349. break;
  6350. case NotSupported:
  6351. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  6352. break;
  6353. case ConfigurationStatus_Rejected:
  6354. default:
  6355. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6356. break;
  6357. }
  6358. }
  6359. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  6360. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  6361. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6362. {
  6363. ChageWebSocketPingInterval(atoi(valuestr));
  6364. }
  6365. if((strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6366. {
  6367. SetOcppConnStatus(FALSE);
  6368. }
  6369. return result;
  6370. }
  6371. int handleClearCacheRequest(char *uuid, char *payload)
  6372. {
  6373. mtrace();
  6374. int result = FAIL;
  6375. char comfirmstr[20];
  6376. char rmFileCmd[100]={0};
  6377. struct stat stats;
  6378. DEBUG_INFO("handleClearCacheRequest...\n");
  6379. stat("/Storage/OCPP", &stats);
  6380. // Check for directory existence
  6381. if (S_ISDIR(stats.st_mode) == 1)
  6382. {}
  6383. else
  6384. {
  6385. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  6386. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  6387. system(rmFileCmd);
  6388. }
  6389. if(OCPP_cleanLocalCache())
  6390. {
  6391. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  6392. }
  6393. else
  6394. {
  6395. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  6396. }
  6397. sendClearCacheConfirmation(uuid, comfirmstr);
  6398. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6399. return result;
  6400. }
  6401. int handleClearChargingProfileRequest(char *uuid, char *payload)
  6402. {
  6403. mtrace();
  6404. int result = FAIL;
  6405. int resultRename;
  6406. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  6407. char chargingProfilePurposeStr[26]={0};
  6408. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  6409. char tempchargingProfilePurposeStr[26]={0};
  6410. char str[100]={0};
  6411. char fname[200]={0};
  6412. char comfirmstr[20]={0};
  6413. char word[1600]={0};
  6414. int clearflag = FALSE;
  6415. int chargingProfileIdIsNULL = FALSE;
  6416. int connectorIsNULL = FALSE;
  6417. int chargingProfilePurposeIsNULL = FALSE;
  6418. int stackLevelIsNULL = FALSE;
  6419. //int GotoEnd = FALSE;
  6420. FILE *fptr1, *fptr2;
  6421. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  6422. int n_chargingProfile=0;
  6423. int isEmptyFile = FALSE;
  6424. char sLineWord[1600]={0};
  6425. char chargingProfiles[10][100]={0};
  6426. int ChargeProfileCount = 0;
  6427. int ch;
  6428. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  6429. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  6430. json_object *ClearChargingProfile;
  6431. ClearChargingProfile = json_tokener_parse(payload);
  6432. if(!is_error(ClearChargingProfile))
  6433. {
  6434. // Optional data
  6435. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  6436. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  6437. else
  6438. chargingProfileIdIsNULL = TRUE;
  6439. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  6440. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  6441. else
  6442. connectorIsNULL = TRUE;
  6443. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  6444. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  6445. else
  6446. chargingProfilePurposeIsNULL = TRUE;
  6447. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  6448. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  6449. else
  6450. stackLevelIsNULL = TRUE;
  6451. }
  6452. json_object_put(ClearChargingProfile);
  6453. if(connectorIsNULL == FALSE)
  6454. {
  6455. switch(connectorIdInt)
  6456. {
  6457. case 0:
  6458. if(chargingProfilePurposeIsNULL == TRUE)
  6459. {
  6460. int l = 0;
  6461. strcpy(fname, ChargePointMaxProfile_JSON);
  6462. if((access(fname,F_OK))!=-1)
  6463. {
  6464. strcpy(chargingProfiles[l], fname);
  6465. l = l + 1;
  6466. }
  6467. strcpy(fname, TxDefaultProfile_0_JSON);
  6468. if((access(fname,F_OK))!=-1)
  6469. {
  6470. strcpy(chargingProfiles[l], fname);
  6471. l = l + 1;
  6472. }
  6473. ChargeProfileCount = l;
  6474. }
  6475. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  6476. {
  6477. strcpy(fname, ChargePointMaxProfile_JSON);
  6478. if((access(fname,F_OK))!=-1)
  6479. {
  6480. strcpy(chargingProfiles[0], fname);
  6481. ChargeProfileCount = 1;
  6482. }
  6483. }
  6484. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6485. {
  6486. strcpy(fname, TxDefaultProfile_0_JSON);
  6487. if((access(fname,F_OK))!=-1)
  6488. {
  6489. strcpy(chargingProfiles[0], fname);
  6490. ChargeProfileCount = 1;
  6491. }
  6492. }
  6493. break;
  6494. default:
  6495. if(chargingProfilePurposeIsNULL == TRUE)
  6496. {
  6497. int m = 0;
  6498. memset(fname, 0, ARRAY_SIZE(fname));
  6499. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6500. if((access(fname,F_OK))!=-1)
  6501. {
  6502. strcpy(chargingProfiles[m], fname);
  6503. m = m + 1;
  6504. }
  6505. memset(fname, 0, ARRAY_SIZE(fname));
  6506. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6507. if((access(fname,F_OK))!=-1)
  6508. {
  6509. strcpy(chargingProfiles[m], fname);
  6510. m = m + 1;
  6511. }
  6512. ChargeProfileCount = m;
  6513. }
  6514. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6515. {
  6516. //strcpy(fname, TxDefaultProfile_1_JSON);
  6517. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6518. if((access(fname,F_OK))!=-1)
  6519. {
  6520. strcpy(chargingProfiles[0], fname);
  6521. ChargeProfileCount = 1;
  6522. }
  6523. }
  6524. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  6525. {
  6526. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6527. if((access(fname,F_OK))!=-1)
  6528. {
  6529. strcpy(chargingProfiles[0], fname);
  6530. ChargeProfileCount = 1;
  6531. }
  6532. //strcpy(fname, TxProfile_1_JSON);
  6533. }
  6534. //strcpy(fname, ChargePointMaxProfile_JSON );
  6535. break;
  6536. }
  6537. }
  6538. else // Check all Charging Profiles
  6539. {
  6540. int i = 0;
  6541. char fnametemp[200]={0};
  6542. ChargeProfileCount = 0;
  6543. //Check ChargePointMaxProfile.json exit
  6544. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  6545. {
  6546. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  6547. i = i + 1;
  6548. }
  6549. //Check TxDefaultProfile_0.json exit
  6550. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  6551. {
  6552. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  6553. i = i + 1;
  6554. }
  6555. //Check TxDefaultProfile_%d.json
  6556. for(int j=1; j <= gunTotalNumber; j++)
  6557. {
  6558. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6559. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  6560. if((access(fnametemp,F_OK))!=-1)
  6561. {
  6562. strcpy(chargingProfiles[i], fnametemp);
  6563. i = i + 1;
  6564. }
  6565. }
  6566. //Check TxProfile_%d.json
  6567. for(int j=1; j <= gunTotalNumber; j++)
  6568. {
  6569. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6570. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  6571. if((access(fnametemp,F_OK))!=-1)
  6572. {
  6573. strcpy(chargingProfiles[i], fnametemp);
  6574. i = i + 1;
  6575. }
  6576. }
  6577. ChargeProfileCount = i;
  6578. }// End connectorIsNULL is TRUE
  6579. if(ChargeProfileCount == 0)
  6580. {
  6581. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6582. goto end;
  6583. }
  6584. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  6585. {
  6586. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6587. goto end;
  6588. }
  6589. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  6590. {
  6591. memset(str, 0, ARRAY_SIZE(str));
  6592. // clear temp file
  6593. sprintf(str,"rm -f %s",temp);
  6594. system(str);
  6595. for(int k=0; k < ChargeProfileCount; k++)
  6596. {
  6597. memset(str, 0, ARRAY_SIZE(str));
  6598. //clear file in C
  6599. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6600. system(str);
  6601. }
  6602. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6603. goto end;
  6604. }
  6605. else if(connectorIsNULL == TRUE)
  6606. {
  6607. for(int k=0; k < ChargeProfileCount; k++)
  6608. {
  6609. fptr1 = fopen(chargingProfiles[k], "r");
  6610. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  6611. //Check Charging Profile Count
  6612. while(fscanf(fptr1, "%s", word) != EOF)
  6613. {
  6614. //DEBUG_INFO("word=%s\n",word);
  6615. if(strstr(word, "chargingProfileId")!= NULL)
  6616. {
  6617. //DEBUG_INFO("test chargingProfileId \n");
  6618. n_chargingProfile = n_chargingProfile + 1;
  6619. //DEBUG_INFO("chargingProfileId Found\n");
  6620. }
  6621. }
  6622. rewind(fptr1);
  6623. //search Charging Profile Element
  6624. //int i= 0;
  6625. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6626. {
  6627. json_object *tmpProfilee;
  6628. tmpProfilee = json_tokener_parse(sLineWord);
  6629. if(!is_error(tmpProfilee))
  6630. {
  6631. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  6632. {
  6633. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  6634. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  6635. }
  6636. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  6637. {
  6638. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  6639. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  6640. }
  6641. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  6642. {
  6643. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  6644. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  6645. }
  6646. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  6647. {
  6648. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  6649. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  6650. }
  6651. }
  6652. json_object_put(tmpProfilee);
  6653. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6654. {
  6655. //------- not write to fptr2-------//
  6656. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6657. //clearflag = TRUE;
  6658. }
  6659. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  6660. {
  6661. //------- not write to fptr2-------//
  6662. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6663. }
  6664. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6665. {
  6666. //------- not write to fptr2-------//
  6667. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6668. }
  6669. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  6670. {
  6671. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6672. }
  6673. else
  6674. {
  6675. fprintf(fptr2, sLineWord);//writing data into file
  6676. }
  6677. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6678. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6679. if(clearflag == TRUE)
  6680. {
  6681. fclose(fptr1);
  6682. fclose(fptr2);
  6683. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6684. system(str);
  6685. // clear temp file
  6686. sprintf(str,"rm -f %s",temp);
  6687. system(str);
  6688. }
  6689. else
  6690. {
  6691. fclose(fptr1);
  6692. fclose(fptr2);
  6693. memset(str, 0, ARRAY_SIZE(str));
  6694. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6695. system(str);
  6696. resultRename = rename(temp, chargingProfiles[k]);
  6697. if(resultRename == 0)
  6698. {
  6699. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  6700. }
  6701. else
  6702. {
  6703. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  6704. }
  6705. if(comfirmstr[0]== 0)
  6706. {
  6707. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6708. }
  6709. //Check chargingProfile is empty file
  6710. /*------ Read the file ----------------*/
  6711. fptr1=fopen(chargingProfiles[k],"r");
  6712. ch=fgetc(fptr1);
  6713. rewind(fptr1);
  6714. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6715. if(ch!=EOF)
  6716. {
  6717. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6718. {
  6719. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6720. if(sLineWord[0]=='\0')
  6721. {
  6722. isEmptyFile = TRUE;
  6723. break;
  6724. }
  6725. else
  6726. {
  6727. isEmptyFile = FALSE;
  6728. break;
  6729. }
  6730. }
  6731. }
  6732. else
  6733. isEmptyFile = TRUE;
  6734. fclose(fptr1);
  6735. if(isEmptyFile == TRUE)
  6736. {
  6737. memset(str, 0, ARRAY_SIZE(str));
  6738. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6739. system(str);
  6740. }
  6741. }
  6742. }// End of while(int k=0; k < ChargePointCount; k++)
  6743. }
  6744. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  6745. {
  6746. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  6747. for(int k=0; k < ChargeProfileCount; k++)
  6748. {
  6749. fptr1 = fopen(chargingProfiles[k], "r");
  6750. fptr2 = fopen(temp, "w+");
  6751. //Check Charging Profile Count
  6752. while(fscanf(fptr1, "%s", word) != EOF)
  6753. {
  6754. //DEBUG_INFO("word=%s\n",word);
  6755. if(strstr(word, "chargingProfileId")!= NULL)
  6756. {
  6757. n_chargingProfile = n_chargingProfile + 1;
  6758. }
  6759. }
  6760. rewind(fptr1);
  6761. //search Charging Profile Element
  6762. //int i= 0;
  6763. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6764. {
  6765. json_object *tmpProfilee;
  6766. tmpProfilee = json_tokener_parse(sLineWord);
  6767. if(!is_error(tmpProfilee))
  6768. {
  6769. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  6770. {
  6771. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  6772. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  6773. }
  6774. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  6775. {
  6776. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  6777. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  6778. }
  6779. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  6780. {
  6781. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  6782. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  6783. }
  6784. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  6785. {
  6786. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  6787. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  6788. }
  6789. }
  6790. json_object_put(tmpProfilee);
  6791. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6792. {
  6793. //------- not write to fptr2-------//
  6794. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6795. //clearflag = TRUE;
  6796. }
  6797. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6798. {
  6799. //------- not write to fptr2-------//
  6800. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6801. }
  6802. else if(stackLevelIsNULL == TRUE)
  6803. {
  6804. //Clear Whole File
  6805. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6806. clearflag = TRUE;
  6807. break;
  6808. }
  6809. else
  6810. {
  6811. fprintf(fptr2, sLineWord);//writing data into file
  6812. }
  6813. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6814. }
  6815. if(clearflag == TRUE)
  6816. {
  6817. fclose(fptr1);
  6818. fclose(fptr2);
  6819. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6820. system(str);
  6821. // clear temp file
  6822. sprintf(str,"rm -f %s",temp);
  6823. system(str);
  6824. }
  6825. else
  6826. {
  6827. fclose(fptr1);
  6828. fclose(fptr2);
  6829. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6830. system(str);
  6831. resultRename = rename(temp, chargingProfiles[k]);
  6832. if(resultRename == 0)
  6833. {
  6834. DEBUG_INFO("File ChargingProfile renamed successfully");
  6835. }
  6836. else
  6837. {
  6838. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6839. }
  6840. if(comfirmstr[0]== 0)
  6841. {
  6842. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6843. }
  6844. //Check chargingProfile is empty file
  6845. /*------ Read the file ----------------*/
  6846. fptr1=fopen(chargingProfiles[k],"r");
  6847. ch=fgetc(fptr1);
  6848. rewind(fptr1);
  6849. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6850. if(ch!=EOF)
  6851. {
  6852. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6853. {
  6854. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6855. if(sLineWord[0]=='\0')
  6856. {
  6857. isEmptyFile = TRUE;
  6858. break;
  6859. }
  6860. else
  6861. {
  6862. isEmptyFile = FALSE;
  6863. break;
  6864. }
  6865. }
  6866. }
  6867. else
  6868. isEmptyFile = TRUE;
  6869. fclose(fptr1);
  6870. if(isEmptyFile == TRUE)
  6871. {
  6872. memset(str, 0, ARRAY_SIZE(str));
  6873. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6874. system(str);
  6875. }
  6876. /*------- End of reading ---------------*/
  6877. }
  6878. } // while(int k=0; k < ChargeProfileCount; k++)
  6879. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  6880. end:
  6881. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  6882. {
  6883. if(connectorIdInt == 0)
  6884. {
  6885. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  6886. {
  6887. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  6888. }
  6889. }
  6890. else
  6891. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  6892. }
  6893. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  6894. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6895. return result;
  6896. }
  6897. void createFirmwareVersionByDataTransfer(void)
  6898. {
  6899. json_object *FirmwareDataTransfer = json_object_new_object();
  6900. // AC & DC model
  6901. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  6902. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  6903. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  6904. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  6905. // DC model
  6906. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O')
  6907. {
  6908. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  6909. {
  6910. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  6911. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  6912. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  6913. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  6914. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  6915. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  6916. }
  6917. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  6918. ((gunType[1] != GUN_TYPE_UNKNOWN) || (gunType[2] != GUN_TYPE_UNKNOWN) || (gunType[3] != GUN_TYPE_UNKNOWN)))
  6919. {
  6920. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  6921. }
  6922. }
  6923. else
  6924. {
  6925. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  6926. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  6927. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  6928. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  6929. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  6930. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  6931. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  6932. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  6933. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  6934. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  6935. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  6936. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  6937. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  6938. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  6939. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  6940. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  6941. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  6942. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  6943. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  6944. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  6945. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  6946. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  6947. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  6948. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  6949. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  6950. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  6951. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  6952. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  6953. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  6954. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  6955. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  6956. }
  6957. // 4G model
  6958. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  6959. {
  6960. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  6961. }
  6962. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  6963. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  6964. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  6965. json_object_put(FirmwareDataTransfer);
  6966. }
  6967. int handleDataTransferRequest(char *uuid, char *payload)
  6968. {
  6969. mtrace();
  6970. json_object *response = json_object_new_object();
  6971. int result = FAIL;
  6972. char tempvendorId[255]={0};
  6973. char tempmessageId[50]={0};
  6974. char tempdata[512]={0};
  6975. char message[2048]={0};
  6976. DEBUG_INFO("handleDataTransferRequest...\n");
  6977. if((uuid != NULL) && (payload != NULL))
  6978. {
  6979. json_object *DataTransfer;
  6980. DataTransfer = json_tokener_parse(payload);
  6981. if(!is_error(DataTransfer))
  6982. {
  6983. // Required data
  6984. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  6985. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  6986. // Optional data
  6987. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  6988. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  6989. if(json_object_object_get(DataTransfer, "data") != NULL)
  6990. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  6991. result = PASS;
  6992. }
  6993. json_object_put(DataTransfer);
  6994. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  6995. {
  6996. // Send all moudle firmware version on EVSE
  6997. createFirmwareVersionByDataTransfer();
  6998. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6999. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  7000. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7001. json_object_put(response);
  7002. }
  7003. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  7004. {
  7005. system("/usr/bin/run_tmate_restart.sh &");
  7006. }
  7007. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  7008. {
  7009. json_object *data;
  7010. data = json_tokener_parse(tempdata);
  7011. if(!is_error(data))
  7012. {
  7013. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  7014. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  7015. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  7016. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  7017. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  7018. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  7019. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  7020. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  7021. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  7022. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  7023. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7024. }
  7025. else
  7026. {
  7027. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7028. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7029. }
  7030. json_object_put(data);
  7031. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7032. json_object_put(response);
  7033. }
  7034. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  7035. {
  7036. json_object *data;
  7037. data = json_tokener_parse(tempdata);
  7038. if(!is_error(data))
  7039. {
  7040. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  7041. if(json_object_object_get(data, "idToken") != NULL)
  7042. {
  7043. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  7044. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  7045. }
  7046. if(json_object_object_get(data, "price") != NULL)
  7047. {
  7048. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  7049. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  7050. }
  7051. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7052. }
  7053. else
  7054. {
  7055. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7056. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7057. }
  7058. json_object_put(data);
  7059. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7060. json_object_put(response);
  7061. }
  7062. else if(strstr(tempmessageId, "RunningCost") != NULL)
  7063. {
  7064. json_object *data;
  7065. data = json_tokener_parse(tempdata);
  7066. if(!is_error(data))
  7067. {
  7068. if(json_object_object_get(data, "txId") != NULL)
  7069. {
  7070. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7071. for(int idx = 0;idx<gunTotalNumber;idx++)
  7072. {
  7073. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7074. {
  7075. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  7076. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7077. if(json_object_object_get(data, "description") != NULL)
  7078. {
  7079. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7080. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7081. }
  7082. }
  7083. }
  7084. }
  7085. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7086. }
  7087. else
  7088. {
  7089. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7090. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7091. }
  7092. json_object_put(data);
  7093. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7094. json_object_put(response);
  7095. }
  7096. else if(strstr(tempmessageId, "FinalCost") != NULL)
  7097. {
  7098. json_object *data;
  7099. data = json_tokener_parse(tempdata);
  7100. if(!is_error(data))
  7101. {
  7102. if(json_object_object_get(data, "txId") != NULL)
  7103. {
  7104. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7105. for(int idx = 0;idx<gunTotalNumber;idx++)
  7106. {
  7107. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7108. {
  7109. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  7110. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7111. if(json_object_object_get(data, "description") != NULL)
  7112. {
  7113. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7114. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7115. }
  7116. }
  7117. }
  7118. }
  7119. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7120. }
  7121. else
  7122. {
  7123. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7124. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7125. }
  7126. json_object_put(data);
  7127. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7128. json_object_put(response);
  7129. }
  7130. else
  7131. {
  7132. // Can not find valid message id
  7133. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  7134. }
  7135. }
  7136. else
  7137. {
  7138. // Payload is null
  7139. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  7140. }
  7141. LWS_Send(message);
  7142. return result;
  7143. }
  7144. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  7145. {
  7146. mtrace();
  7147. int result = FAIL;
  7148. int connectorIdInt, durationInt;
  7149. char chargingRateUnitStr[4]={0};
  7150. char comfirmstr[20];
  7151. int confirmPeriods = 0;
  7152. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  7153. json_object *GetCompositeSchedule;
  7154. GetCompositeSchedule = json_tokener_parse(payload);
  7155. if(!is_error(GetCompositeSchedule))
  7156. {
  7157. // Required data
  7158. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  7159. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  7160. else
  7161. connectorIdInt = -1;
  7162. if(json_object_object_get(GetCompositeSchedule, "duration"))
  7163. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  7164. else
  7165. durationInt = 86400;
  7166. // Optional data
  7167. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  7168. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  7169. }
  7170. json_object_put(GetCompositeSchedule);
  7171. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  7172. if((connectorIdInt == 0) ||
  7173. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  7174. {
  7175. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  7176. struct StructChargingProfile tmpProfile[1];
  7177. if(strstr(chargingRateUnitStr, "W") != NULL)
  7178. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  7179. else
  7180. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  7181. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7182. {
  7183. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7184. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7185. }
  7186. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  7187. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  7188. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  7189. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7190. {
  7191. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7192. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7193. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  7194. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0))
  7195. {
  7196. confirmPeriods = idx;
  7197. break;
  7198. }
  7199. }
  7200. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  7201. }
  7202. else
  7203. {
  7204. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  7205. }
  7206. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  7207. return result;
  7208. }
  7209. int handleGetConfigurationRequest(char *uuid, char *payload)
  7210. {
  7211. mtrace();
  7212. int result = FAIL;
  7213. int MaxKeySupported = 0;
  7214. int n_keys = 0;
  7215. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  7216. DEBUG_INFO("handleGetConfigurationRequest...\n");
  7217. json_object *GetConfiguration;
  7218. GetConfiguration = json_tokener_parse(payload);
  7219. if(!is_error(GetConfiguration))
  7220. {
  7221. // Optional data
  7222. if(json_object_object_get(GetConfiguration, "key") != NULL)
  7223. {
  7224. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  7225. {
  7226. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  7227. n_keys = idx + 1;
  7228. }
  7229. }
  7230. }
  7231. json_object_put(GetConfiguration);
  7232. UnknownKeynum = 0;
  7233. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  7234. MaxKeySupported = GetConfigurationMaxKeysNUM;
  7235. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  7236. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  7237. if(n_keys != 0)
  7238. {
  7239. for(int i=0;i<n_keys;i++)
  7240. {
  7241. getKeyValue(requestKey[i]);
  7242. }
  7243. }
  7244. else
  7245. {
  7246. DEBUG_INFO("There is no key in Message, get all configuration\n");
  7247. getKeyValue("");
  7248. }
  7249. processUnkownKey();
  7250. sendGetConfigurationConfirmation(uuid);
  7251. return result;
  7252. }
  7253. static char fnamePlusPath[100]={0};
  7254. static char fnamePWithNoPath[60]={0};
  7255. void checkUploadLog(void)
  7256. {
  7257. FILE *fp;
  7258. /* Open the command for reading. */
  7259. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  7260. if (fp == NULL) {
  7261. printf("Failed to run command\n" );
  7262. exit(1);
  7263. }
  7264. int ftppathlen = 0;
  7265. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  7266. int i = 0;
  7267. /* Read the output a line at a time - output it. */
  7268. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  7269. if(i==0)
  7270. {
  7271. ftppathlen = strlen(fnamePlusPath);
  7272. printf("%s\n", fnamePlusPath);
  7273. fnamePlusPath[ftppathlen]='\0';
  7274. break;
  7275. }
  7276. i= i+1;
  7277. }
  7278. /* close */
  7279. pclose(fp);
  7280. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  7281. {
  7282. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  7283. {
  7284. fnamePlusPath[k]='\0';
  7285. }
  7286. }
  7287. i=1;
  7288. //char fname[60]={0};
  7289. while(i < ftppathlen)
  7290. {
  7291. int len=ftppathlen-i;
  7292. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  7293. {
  7294. printf("compare '/' all right\n");
  7295. break;
  7296. }
  7297. i=i+1;
  7298. }
  7299. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  7300. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  7301. fnamePWithNoPath[i+1] = '\0';
  7302. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  7303. {
  7304. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  7305. {
  7306. fnamePWithNoPath[j]='\0';
  7307. }
  7308. }
  7309. FILE* fp1 = fopen(fnamePlusPath, "r");
  7310. if (fp1)
  7311. {
  7312. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  7313. // file exists
  7314. fclose(fp1);
  7315. }
  7316. else
  7317. {
  7318. // file doesn't exist
  7319. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  7320. }
  7321. }
  7322. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  7323. {
  7324. mtrace();
  7325. int result = FAIL;
  7326. time_t CurrentTime;
  7327. struct tm *tm;
  7328. pthread_t th_Status;
  7329. CurrentTime = time(NULL);
  7330. tm = localtime(&CurrentTime);
  7331. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  7332. 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);
  7333. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  7334. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  7335. return result;
  7336. }
  7337. void* GetDiagnosticsProcess(void* data)
  7338. {
  7339. pthread_detach(pthread_self());
  7340. mtrace();
  7341. int retriesInt=0, retryIntervalInt=0;
  7342. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  7343. 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};
  7344. int port=0;
  7345. int isSuccess = FALSE;
  7346. char ftpbuf[200]={0};
  7347. char cmdBuf[2048];
  7348. struct tm *tmNow;
  7349. time_t CurrentTime;
  7350. struct tm tmStart;
  7351. struct tm tmStop;
  7352. CurrentTime = time(NULL);
  7353. tmNow=localtime(&CurrentTime);
  7354. uint16_t targetYear, targetMonth;
  7355. json_object *GetDiagnostics;
  7356. DEBUG_INFO("GetDiagnosticsProcess...\n");
  7357. GetDiagnostics = json_tokener_parse(data);
  7358. if(!is_error(GetDiagnostics))
  7359. {
  7360. // Required data
  7361. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  7362. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  7363. // Optional data
  7364. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  7365. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  7366. else
  7367. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  7368. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  7369. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  7370. else
  7371. retryIntervalInt = 30;
  7372. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  7373. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  7374. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  7375. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  7376. }
  7377. json_object_put(GetDiagnostics);
  7378. // Pack log to compress file
  7379. 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) &&
  7380. (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))
  7381. {
  7382. // Pack system log
  7383. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  7384. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  7385. targetYear = tmStart.tm_year;
  7386. targetMonth = tmStart.tm_mon;
  7387. do
  7388. {
  7389. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7390. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7391. if(targetMonth+1>=13)
  7392. {
  7393. targetYear += 1;
  7394. targetMonth = 1;
  7395. }
  7396. else
  7397. {
  7398. targetMonth += 1;
  7399. }
  7400. }while((targetYear < (tmNow->tm_year+1900)) ||
  7401. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  7402. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  7403. system(cmdBuf);
  7404. // Pack charging & event log
  7405. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  7406. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  7407. targetYear = tmStart.tm_year;
  7408. targetMonth = tmStart.tm_mon;
  7409. do
  7410. {
  7411. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7412. if(targetMonth+1>=13)
  7413. {
  7414. targetYear += 1;
  7415. targetMonth = 1;
  7416. }
  7417. else
  7418. {
  7419. targetMonth += 1;
  7420. }
  7421. }while((targetYear < (tmNow->tm_year+1900)) ||
  7422. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  7423. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  7424. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  7425. system(cmdBuf);
  7426. // Combine log file
  7427. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  7428. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  7429. }
  7430. else
  7431. {
  7432. system("exec /root/logPackTools 'log' 6");
  7433. }
  7434. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  7435. system(cmdBuf);
  7436. checkUploadLog();
  7437. //****************location*******************/
  7438. if(strcmp(locationstr,"")==0)
  7439. {
  7440. DEBUG_INFO("location is <Empty>!\n");
  7441. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7442. goto end;
  7443. }
  7444. memset(protocol, 0, ARRAY_SIZE(protocol));
  7445. memset(user, 0, ARRAY_SIZE(user) );
  7446. memset(password, 0, ARRAY_SIZE(password));
  7447. memset(host, 0, ARRAY_SIZE(host));
  7448. memset(path, 0, ARRAY_SIZE(path));
  7449. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  7450. memset(host1, 0, ARRAY_SIZE(host1));
  7451. memset(path1, 0, ARRAY_SIZE(path1));
  7452. /*location: ftp://user:password@host:port/path*/
  7453. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  7454. if((access(fnamePlusPath,F_OK))!=-1)
  7455. {
  7456. DEBUG_INFO("fnamePlusPath exist.\n");
  7457. }
  7458. else
  7459. {
  7460. DEBUG_INFO("fnamePlusPath not exist!\n");
  7461. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7462. goto end;
  7463. }
  7464. if(strchr(locationstr,'@')==NULL)
  7465. {
  7466. sscanf(locationstr,
  7467. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  7468. protocol, host, &port, path);
  7469. strcpy(user,"anonymous");
  7470. strcpy(password,"");
  7471. }
  7472. else
  7473. {
  7474. //DEBUG_INFO("pch=%s\n", pch);
  7475. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  7476. protocol, user, password, host, &port, path);
  7477. }
  7478. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  7479. {
  7480. DEBUG_INFO("protocol is not ftp/http ! \n");
  7481. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7482. goto end;
  7483. }
  7484. if(strncmp(locationstr,"http", 4) == 0)
  7485. {
  7486. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  7487. sprintf(ftppath,"/%s", path);
  7488. do
  7489. {
  7490. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  7491. sleep(3);
  7492. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  7493. if(!isSuccess)
  7494. {
  7495. DEBUG_INFO("Diagnostics fail.\n");
  7496. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7497. sleep(retryIntervalInt);
  7498. }
  7499. else
  7500. {
  7501. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  7502. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  7503. }
  7504. retriesInt--;
  7505. }while((isSuccess == 0)&&(retriesInt >= 0));
  7506. }
  7507. else
  7508. {
  7509. sscanf(host,"%[^/]%s",host1, path1);
  7510. if(strlen(path) > 0)
  7511. sprintf(ftppath,"/%s", path);
  7512. else
  7513. sprintf(ftppath,"/%s", path1);
  7514. int ftppathlen=strlen(ftppath);
  7515. int i=1;
  7516. char filenametemp[50];
  7517. while(i < ftppathlen)
  7518. {
  7519. int len=ftppathlen-i;
  7520. if(ftppath[len]== 47) // '/' ascll code: 47
  7521. {
  7522. DEBUG_INFO("find '/' all right\n");
  7523. break;
  7524. }
  7525. i=i+1;
  7526. }
  7527. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  7528. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  7529. filenametemp[i+1] = 0;
  7530. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  7531. if(port == 0)
  7532. port = 21;
  7533. do
  7534. {
  7535. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  7536. sleep(3);
  7537. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  7538. if(!isSuccess)
  7539. {
  7540. DEBUG_INFO("Diagnostics fail.\n");
  7541. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7542. sleep(retryIntervalInt);
  7543. }
  7544. else
  7545. {
  7546. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  7547. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  7548. }
  7549. retriesInt--;
  7550. }while((!isSuccess)&&(retriesInt >= 0));
  7551. }
  7552. end:
  7553. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  7554. system("rm -f /mnt/*");
  7555. pthread_exit(NULL);
  7556. }
  7557. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  7558. {
  7559. mtrace();
  7560. int result = FAIL;
  7561. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  7562. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  7563. {
  7564. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  7565. localversion = -1;
  7566. }
  7567. else
  7568. {
  7569. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  7570. OCPP_getListVerion();
  7571. }
  7572. //from db.OCPP_getListVerion
  7573. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  7574. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  7575. sendGetLocalListVersionConfirmation(uuid,"");
  7576. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  7577. return result;
  7578. }
  7579. int handleRemoteStartRequest(char *uuid, char *payload)
  7580. {
  7581. mtrace();
  7582. int result = FAIL;
  7583. int connectorIdInt=0;
  7584. int tempIndex = 0;
  7585. int connectorIdIsNULL, chargingProfileIsNULL;
  7586. char comfirmstr[20]={0};
  7587. char cmdBuf[512];
  7588. json_object *RemoteStartTransaction;
  7589. FILE *fp;
  7590. DEBUG_INFO("handleRemoteStartRequest ...\n");
  7591. if(server_pending == TRUE)
  7592. {
  7593. return 0;
  7594. }
  7595. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  7596. RemoteStartTransaction = json_tokener_parse(payload);
  7597. if(!is_error(RemoteStartTransaction))
  7598. {
  7599. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  7600. {
  7601. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  7602. if(connectorIdInt <= gunTotalNumber)
  7603. {
  7604. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  7605. // Required data
  7606. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  7607. // Optional data
  7608. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  7609. {
  7610. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  7611. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  7612. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  7613. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  7614. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  7615. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  7616. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  7617. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  7618. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  7619. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  7620. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  7621. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  7622. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  7623. {
  7624. 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")));
  7625. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  7626. 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"));
  7627. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  7628. 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"));
  7629. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  7630. 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")));
  7631. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  7632. {
  7633. 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++)
  7634. {
  7635. 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"));
  7636. 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"));
  7637. 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)
  7638. 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"));
  7639. }
  7640. }
  7641. }
  7642. }
  7643. else
  7644. chargingProfileIsNULL = TRUE;
  7645. }
  7646. }
  7647. else
  7648. connectorIdIsNULL = TRUE;
  7649. }
  7650. else
  7651. connectorIdIsNULL = TRUE;
  7652. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  7653. {
  7654. DEBUG_WARN("Connector id is NULL\n.");
  7655. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7656. goto end;
  7657. }
  7658. /*
  7659. enum _SYSTEM_STATUS
  7660. {
  7661. S_BOOTING = 0,
  7662. S_IDLE, = 1
  7663. S_AUTHORIZING, = 2
  7664. S_REASSIGN_CHECK, = 3
  7665. S_REASSIGN, = 4
  7666. S_PRECHARGE, = 5
  7667. S_PREPARING_FOR_EV, = 6
  7668. S_PREPARING_FOR_EVSE, = 7
  7669. S_CHARGING, = 8
  7670. S_TERMINATING, = 9
  7671. S_COMPLETE, = 10
  7672. S_ALARM, = 11
  7673. S_FAULT = 12
  7674. }
  7675. */
  7676. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  7677. {
  7678. //check Transaction active
  7679. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  7680. {
  7681. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7682. {
  7683. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7684. }
  7685. else
  7686. {
  7687. tempIndex = connectorIdInt -1;
  7688. }
  7689. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7690. {
  7691. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  7692. {
  7693. 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))
  7694. {
  7695. //Reserved
  7696. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7697. }
  7698. 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))
  7699. {
  7700. //Reserved
  7701. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7702. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7703. goto end;
  7704. }
  7705. else
  7706. {
  7707. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7708. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  7709. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  7710. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  7711. {
  7712. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  7713. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7714. goto end;
  7715. }
  7716. }//END FOR ELSE
  7717. }
  7718. }// END FOR CHAdeMO_QUANTITY
  7719. }
  7720. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  7721. {
  7722. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7723. {
  7724. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7725. }
  7726. else
  7727. {
  7728. tempIndex = connectorIdInt -1;
  7729. }
  7730. for (int index = 0; index < CCS_QUANTITY; index++)
  7731. {
  7732. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7733. {
  7734. 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))
  7735. {
  7736. //Reserved
  7737. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7738. }
  7739. 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))
  7740. {
  7741. //Reserved
  7742. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7743. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7744. goto end;
  7745. }
  7746. else
  7747. {
  7748. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7749. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7750. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7751. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7752. {
  7753. DEBUG_WARN("CCS connector not allow start\n.");
  7754. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7755. goto end;
  7756. }
  7757. }// END FOR ELSE
  7758. }
  7759. }// END FOR CCS_QUANTITY
  7760. }
  7761. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  7762. {
  7763. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7764. {
  7765. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7766. }
  7767. else
  7768. {
  7769. tempIndex = connectorIdInt -1;
  7770. }
  7771. for (int index = 0; index < GB_QUANTITY; index++)
  7772. {
  7773. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  7774. {
  7775. 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))
  7776. {
  7777. //Reserved
  7778. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7779. }
  7780. 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))
  7781. {
  7782. //Reserved
  7783. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7784. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7785. goto end;
  7786. }
  7787. else
  7788. {
  7789. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7790. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7791. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7792. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7793. {
  7794. DEBUG_WARN("GB connector not allow start\n.");
  7795. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7796. goto end;
  7797. }
  7798. }// END FOR ELSE
  7799. }
  7800. } // END FOR GB_QUANTITY
  7801. }
  7802. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  7803. {
  7804. tempIndex = connectorIdInt -1;
  7805. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7806. {
  7807. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  7808. {
  7809. 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))
  7810. {
  7811. //Reserved
  7812. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7813. }
  7814. 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))
  7815. {
  7816. //Reserved
  7817. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7818. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7819. goto end;
  7820. }
  7821. else
  7822. {
  7823. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7824. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7825. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7826. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7827. {
  7828. DEBUG_WARN("GB connector not allow start\n.");
  7829. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7830. goto end;
  7831. }
  7832. }// END FOR ELSE
  7833. }
  7834. } // END FOR GB_QUANTITY
  7835. }
  7836. else
  7837. {
  7838. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7839. {
  7840. tempIndex = 2;
  7841. }
  7842. else
  7843. {
  7844. tempIndex = connectorIdInt -1;
  7845. }
  7846. for (int index = 0; index < AC_QUANTITY; index++)
  7847. {
  7848. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  7849. {
  7850. 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))
  7851. {
  7852. //Reserved
  7853. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7854. }
  7855. 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))
  7856. {
  7857. //Reserved
  7858. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7859. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7860. goto end;
  7861. }
  7862. else
  7863. {
  7864. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7865. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7866. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7867. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7868. {
  7869. DEBUG_WARN("AC connector not allow start\n.");
  7870. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7871. goto end;
  7872. }
  7873. }//END FOR ELSE
  7874. }
  7875. }// END FOR AC_QUANTITY
  7876. }
  7877. if(chargingProfileIsNULL == FALSE)
  7878. {
  7879. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7880. {
  7881. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7882. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7883. //memset idTag
  7884. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7885. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7886. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7887. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7888. // Save profile to file
  7889. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7890. system(cmdBuf);
  7891. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7892. fp = fopen(cmdBuf, "w");
  7893. 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));
  7894. fclose(fp);
  7895. }
  7896. else
  7897. {
  7898. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  7899. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7900. }
  7901. }
  7902. else
  7903. {
  7904. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7905. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7906. //memset idTag
  7907. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7908. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7909. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7910. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7911. }
  7912. }
  7913. else
  7914. {
  7915. DEBUG_WARN("Connector id over\n.");
  7916. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7917. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7918. }
  7919. end:
  7920. json_object_put(RemoteStartTransaction);
  7921. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  7922. {
  7923. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  7924. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7925. }
  7926. //OCPP send RemoteStartConfirmation by first.
  7927. sendRemoteStartConfirmation(uuid, comfirmstr);
  7928. return result;
  7929. }
  7930. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  7931. {
  7932. mtrace();
  7933. int result = FAIL;
  7934. int match = FALSE;
  7935. int GunNO = 0;
  7936. int tempIndex = 0;
  7937. int transactionIdInt=0;
  7938. int transactionIdIsNULL= TRUE;
  7939. char comfirmstr[20];
  7940. json_object *RemoteStopTransaction;
  7941. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  7942. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  7943. if(server_pending == TRUE)
  7944. {
  7945. return 0;
  7946. }
  7947. RemoteStopTransaction = json_tokener_parse(payload);
  7948. if(!is_error(RemoteStopTransaction))
  7949. {
  7950. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  7951. {
  7952. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  7953. transactionIdIsNULL = FALSE;
  7954. }
  7955. }
  7956. json_object_put(RemoteStopTransaction);
  7957. if(transactionIdIsNULL == FALSE)
  7958. {
  7959. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  7960. {
  7961. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  7962. {
  7963. //check Transaction active
  7964. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7965. {
  7966. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7967. {
  7968. tempIndex = ((gun_index==2) ? 1: 0);
  7969. }
  7970. else
  7971. {
  7972. tempIndex = gun_index;
  7973. }
  7974. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7975. {
  7976. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7977. {
  7978. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7979. {
  7980. match = TRUE;
  7981. GunNO = gun_index;
  7982. }
  7983. }
  7984. }// END FOR CHAdeMO_QUANTITY
  7985. }
  7986. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7987. {
  7988. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7989. {
  7990. tempIndex = ((gun_index==2) ? 1: 0);
  7991. }
  7992. else
  7993. {
  7994. tempIndex = gun_index;
  7995. }
  7996. for (int index = 0; index < CCS_QUANTITY; index++)
  7997. {
  7998. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7999. {
  8000. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8001. {
  8002. match = TRUE;
  8003. GunNO = gun_index;
  8004. }
  8005. }
  8006. }// END FOR CCS_QUANTITY
  8007. }
  8008. else if(gunType[gun_index] == GUN_TYPE_GBT)
  8009. {
  8010. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8011. {
  8012. tempIndex = ((gun_index==2) ? 1: 0);
  8013. }
  8014. else
  8015. {
  8016. tempIndex = gun_index;
  8017. }
  8018. for (int index = 0; index < GB_QUANTITY; index++)
  8019. {
  8020. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8021. {
  8022. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8023. {
  8024. match = TRUE;
  8025. GunNO = gun_index;
  8026. }
  8027. }
  8028. }// END FOR GB_QUANTITY
  8029. }
  8030. else if(gunType[gun_index] == GUN_TYPE_DO)
  8031. {
  8032. tempIndex = gun_index;
  8033. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8034. {
  8035. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8036. {
  8037. 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
  8038. {
  8039. match = TRUE;
  8040. GunNO = gun_index;
  8041. }
  8042. }
  8043. }// END FOR GB_QUANTITY
  8044. }
  8045. else
  8046. {
  8047. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8048. {
  8049. tempIndex = 2;
  8050. }
  8051. else
  8052. {
  8053. tempIndex = gun_index;
  8054. }
  8055. for (int index = 0; index < AC_QUANTITY; index++)
  8056. {
  8057. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8058. {
  8059. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8060. {
  8061. match = TRUE;
  8062. GunNO = gun_index;
  8063. }
  8064. }
  8065. }// END FOR CHAdeMO_QUANTITY
  8066. } // END FOR AC ELSE
  8067. }// CHECK IF ResponseTransactionId == transactionIdInt
  8068. }//END FOR
  8069. if( match == TRUE)
  8070. {
  8071. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  8072. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8073. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  8074. }
  8075. else
  8076. {
  8077. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8078. }
  8079. }
  8080. else
  8081. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8082. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  8083. return result;
  8084. }
  8085. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  8086. {
  8087. mtrace();
  8088. int result = FAIL;
  8089. int connectorIdInt=0, reservationIdInt=0;
  8090. int tempIndex = 0;
  8091. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  8092. char comfirmstr[20]={0};
  8093. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  8094. int c = 0;
  8095. char *loc;
  8096. //char *ptr;
  8097. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  8098. strcpy(sstrtemp, stringtrimspace(payload));
  8099. //***(1)connectorId ****/
  8100. c=0;
  8101. loc = strstr(sstrtemp, "connectorId");
  8102. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8103. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  8104. {
  8105. sstr[c] = loc[strlen("connectorId")+2+c];
  8106. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8107. c++;
  8108. }
  8109. sstr[c] = '\0';
  8110. connectorIdInt = atoi(sstr);
  8111. //***(2)expiryDate ****/
  8112. loc = strstr(sstrtemp, "expiryDate");
  8113. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8114. c = 0;
  8115. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  8116. {
  8117. sstr[c] = loc[3+strlen("expiryDate")+c];
  8118. c++;
  8119. }
  8120. sstr[c] = '\0';
  8121. strcpy(expiryDatestr, sstr);
  8122. //***(3)idTag ****/
  8123. loc = strstr(sstrtemp, "idTag");
  8124. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8125. c = 0;
  8126. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  8127. {
  8128. sstr[c] = loc[3+strlen("idTag")+c];
  8129. c++;
  8130. }
  8131. sstr[c] = '\0';
  8132. strcpy(idTagstr, sstr);
  8133. //***(4)parentIdTag ****/
  8134. loc = strstr(sstrtemp, "parentIdTag");
  8135. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8136. c = 0;
  8137. if(loc == NULL)
  8138. {
  8139. strcpy(parentIdTagstr, "");
  8140. }
  8141. else
  8142. {
  8143. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8144. {
  8145. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8146. c++;
  8147. }
  8148. sstr[c] = '\0';
  8149. strcpy(parentIdTagstr, sstr);
  8150. }
  8151. //***(5)reservationId ****/
  8152. c=0;
  8153. loc = strstr(sstrtemp, "reservationId");
  8154. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8155. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  8156. {
  8157. sstr[c] = loc[strlen("reservationId")+2+c];
  8158. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8159. c++;
  8160. }
  8161. sstr[c] = '\0';
  8162. reservationIdInt = atoi(sstr);
  8163. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8164. /*
  8165. enum SYSTEM_STATUS
  8166. {
  8167. SYS_MODE_BOOTING = 0,
  8168. SYS_MODE_IDLE = 1,
  8169. SYS_MODE_AUTHORIZING = 2,
  8170. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  8171. SYS_MODE_REASSIGN = 4,
  8172. SYS_MODE_PREPARING = 5,
  8173. SYS_MODE_PREPARE_FOR_EV = 6,
  8174. SYS_MODE_PREPARE_FOR_EVSE = 7,
  8175. SYS_MODE_CHARGING = 8,
  8176. SYS_MODE_TERMINATING = 9,
  8177. SYS_MODE_COMPLETE = 10,
  8178. SYS_MODE_ALARM = 11,
  8179. SYS_MODE_FAULT = 12,
  8180. SYS_MODE_RESERVATION = 13,
  8181. SYS_MODE_BOOKING = 14,
  8182. SYS_MODE_MAINTAIN = 15,
  8183. SYS_MODE_DEBUG = 16,
  8184. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  8185. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  8186. SYS_MODE_UPDATE = 19
  8187. };
  8188. */
  8189. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  8190. {
  8191. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8192. goto end;
  8193. }
  8194. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  8195. {
  8196. //check Transaction active
  8197. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8198. {
  8199. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8200. {
  8201. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8202. }
  8203. else
  8204. {
  8205. tempIndex = connectorIdInt -1;
  8206. }
  8207. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8208. {
  8209. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8210. {
  8211. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  8212. {
  8213. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8214. {
  8215. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8216. {
  8217. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8218. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8219. }
  8220. 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'))
  8221. {
  8222. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8223. }
  8224. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8225. {
  8226. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8227. }
  8228. else
  8229. {
  8230. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8231. }
  8232. }
  8233. 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
  8234. {
  8235. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8236. }
  8237. }
  8238. else
  8239. {
  8240. //replace reservation
  8241. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8242. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8243. }
  8244. }
  8245. } // END FOR CHAdeMO_QUANTITY
  8246. }
  8247. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8248. {
  8249. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8250. {
  8251. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8252. }
  8253. else
  8254. {
  8255. tempIndex = connectorIdInt -1;
  8256. }
  8257. for (int index = 0; index < CCS_QUANTITY; index++)
  8258. {
  8259. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8260. {
  8261. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8262. {
  8263. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8264. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8265. {
  8266. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8267. {
  8268. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8269. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8270. }
  8271. 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'))
  8272. {
  8273. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8274. }
  8275. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  8276. {
  8277. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8278. }
  8279. else
  8280. {
  8281. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8282. }
  8283. }
  8284. 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
  8285. {
  8286. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8287. }
  8288. }
  8289. else
  8290. {
  8291. //replace reservation
  8292. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8293. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8294. }
  8295. }
  8296. } // END FOR CCS_QUANTITY
  8297. }
  8298. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8299. {
  8300. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8301. {
  8302. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8303. }
  8304. else
  8305. {
  8306. tempIndex = connectorIdInt -1;
  8307. }
  8308. for (int index = 0; index < GB_QUANTITY; index++)
  8309. {
  8310. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8311. {
  8312. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8313. {
  8314. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8315. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  8316. {
  8317. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8318. {
  8319. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8320. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8321. }
  8322. 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'))
  8323. {
  8324. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8325. }
  8326. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8327. {
  8328. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8329. }
  8330. else
  8331. {
  8332. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8333. }
  8334. }
  8335. 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
  8336. {
  8337. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8338. }
  8339. }
  8340. else
  8341. {
  8342. //replace reservation
  8343. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8344. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8345. }
  8346. }
  8347. }// END FOR GB_QUANTITY
  8348. }
  8349. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8350. {
  8351. tempIndex = connectorIdInt -1;
  8352. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8353. {
  8354. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8355. {
  8356. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  8357. {
  8358. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8359. 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
  8360. {
  8361. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8362. {
  8363. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8364. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8365. }
  8366. 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'))
  8367. {
  8368. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8369. }
  8370. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8371. {
  8372. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8373. }
  8374. else
  8375. {
  8376. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8377. }
  8378. }
  8379. 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
  8380. {
  8381. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8382. }
  8383. }
  8384. else
  8385. {
  8386. //replace reservation
  8387. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8388. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8389. }
  8390. }
  8391. }// END FOR GB_QUANTITY
  8392. }
  8393. else
  8394. {
  8395. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8396. {
  8397. tempIndex = 2;
  8398. }
  8399. else
  8400. {
  8401. tempIndex = (connectorIdInt -1);
  8402. }
  8403. for (int index = 0; index < AC_QUANTITY; index++)
  8404. {
  8405. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8406. {
  8407. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  8408. {
  8409. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  8410. {
  8411. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8412. {
  8413. 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))
  8414. {
  8415. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8416. }
  8417. else
  8418. {
  8419. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8420. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8421. }
  8422. }
  8423. 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'))
  8424. {
  8425. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8426. }
  8427. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8428. {
  8429. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8430. }
  8431. else
  8432. {
  8433. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8434. }
  8435. }
  8436. 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
  8437. {
  8438. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8439. }
  8440. }
  8441. else
  8442. {
  8443. //replace reservation
  8444. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8445. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8446. }
  8447. }
  8448. } // END FOR AC_QUANTITY
  8449. }
  8450. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8451. }
  8452. else if(connectorIdInt == 0)
  8453. {
  8454. //check Transaction active
  8455. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8456. {
  8457. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  8458. {
  8459. 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'))
  8460. {
  8461. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8462. goto end;
  8463. }
  8464. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8465. {
  8466. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8467. goto end;
  8468. }
  8469. 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
  8470. {
  8471. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8472. goto end;
  8473. }
  8474. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8475. {
  8476. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8477. goto end;
  8478. }
  8479. }
  8480. }// END FOR CHAdeMO_QUANTITY
  8481. for (int index = 0; index < CCS_QUANTITY; index++)
  8482. {
  8483. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8484. {
  8485. 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'))
  8486. {
  8487. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8488. goto end;
  8489. }
  8490. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  8491. {
  8492. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8493. goto end;
  8494. }
  8495. 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
  8496. {
  8497. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8498. goto end;
  8499. }
  8500. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8501. {
  8502. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8503. goto end;
  8504. }
  8505. }
  8506. } // END FOR CCS_QUANTITY
  8507. for (int index = 0; index < GB_QUANTITY; index++)
  8508. {
  8509. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8510. {
  8511. 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'))
  8512. {
  8513. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8514. goto end;
  8515. }
  8516. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8517. {
  8518. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8519. goto end;
  8520. }
  8521. 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
  8522. {
  8523. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8524. goto end;
  8525. }
  8526. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8527. {
  8528. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8529. goto end;
  8530. }
  8531. }
  8532. } // END FOR GB_QUANTITY
  8533. for (int index = 0; index < AC_QUANTITY; index++)
  8534. {
  8535. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  8536. {
  8537. 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'))
  8538. {
  8539. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8540. goto end;
  8541. }
  8542. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8543. {
  8544. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8545. goto end;
  8546. }
  8547. 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
  8548. {
  8549. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8550. goto end;
  8551. }
  8552. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8553. {
  8554. 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))
  8555. {
  8556. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8557. goto end;
  8558. }
  8559. }
  8560. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8561. {
  8562. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8563. goto end;
  8564. }
  8565. }
  8566. }// END FOR AC_QUANTITY
  8567. //The connectorId is 0
  8568. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  8569. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8570. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  8571. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  8572. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  8573. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  8574. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  8575. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  8576. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  8577. result = TRUE;
  8578. return result;
  8579. }
  8580. else
  8581. {
  8582. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8583. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8584. }
  8585. if(strcmp(comfirmstr,"Accepted") == 0)
  8586. {
  8587. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  8588. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  8589. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  8590. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  8591. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  8592. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  8593. result = TRUE;
  8594. return result;
  8595. }
  8596. end:
  8597. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  8598. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  8599. return result;
  8600. }
  8601. int handleResetRequest(char *uuid, char *payload)
  8602. {
  8603. mtrace();
  8604. int result = FAIL;
  8605. char sstr[10]={0},sstrtemp[30]={ 0 };
  8606. char typestr[10]={0};
  8607. char comfirmstr[20]={0};
  8608. int c = 0;
  8609. char *loc;
  8610. DEBUG_INFO("handleResetRequest...\n");
  8611. strcpy(sstrtemp, stringtrimspace(payload));
  8612. loc = strstr(sstrtemp, "type");
  8613. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8614. c = 0;
  8615. while (loc[3+strlen("type")+c] != '\"')
  8616. {
  8617. sstr[c] = loc[3+strlen("type")+c];
  8618. c++;
  8619. }
  8620. sstr[c] = '\0';
  8621. strcpy(typestr,sstr);
  8622. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  8623. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  8624. {
  8625. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  8626. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  8627. result = TRUE;
  8628. return result;
  8629. }
  8630. else
  8631. {
  8632. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  8633. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  8634. goto errorend;
  8635. }
  8636. errorend:
  8637. sendResetConfirmation(uuid, comfirmstr);
  8638. return result;
  8639. }
  8640. int handleSendLocalListRequest(char *uuid, char *payload)
  8641. {
  8642. mtrace();
  8643. int result = FAIL;
  8644. int listVersionInt;
  8645. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  8646. char listsearch[]="listVersion";
  8647. char updateTypesearch[]="updateType";
  8648. char localAuthorizationListsearch[]="localAuthorizationList";
  8649. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  8650. char CardList[500][160]={0};
  8651. char updateTypestr[15]={0};
  8652. char idTagstr[20]={0};
  8653. char parentIdTag[20]={0};
  8654. char expiryDate[30]={0};
  8655. char idTagstatus[16]={0};
  8656. int c = 0;
  8657. int i = 0;
  8658. char *delim1 = "}";
  8659. char * pch;
  8660. char *loc;
  8661. //char *ptr;
  8662. char comfirmstr[20];
  8663. //int n_localAuthorizations = 0;
  8664. int checkState_Faulted = FALSE;
  8665. DEBUG_INFO("handleSendLocalListRequest...\n");
  8666. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  8667. {
  8668. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8669. goto end;
  8670. }
  8671. //check Charge Point state
  8672. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8673. {
  8674. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8675. {
  8676. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8677. }
  8678. }
  8679. for (int index = 0; index < CCS_QUANTITY; index++)
  8680. {
  8681. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8682. {
  8683. checkState_Faulted = TRUE; //OCPP Status
  8684. }
  8685. }
  8686. for (int index = 0; index < GB_QUANTITY; index++)
  8687. {
  8688. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8689. {
  8690. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8691. }
  8692. }
  8693. //check Charge Point state
  8694. for (int index = 0; index < AC_QUANTITY; index++)
  8695. {
  8696. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8697. {
  8698. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8699. }
  8700. }
  8701. if(checkState_Faulted == TRUE)
  8702. {
  8703. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8704. goto end;
  8705. }
  8706. //Filter payload space
  8707. strcpy(sstrtemp, stringtrimspace(payload));
  8708. //listVersion
  8709. c = 0;
  8710. loc = strstr(sstrtemp, listsearch);
  8711. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  8712. {
  8713. sstr[c] = loc[strlen("listVersion")+2+c];
  8714. c++;
  8715. }
  8716. sstr[c] = '\0';
  8717. listVersionInt = atoi(sstr);
  8718. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8719. //updateType
  8720. loc = strstr(sstrtemp, updateTypesearch);
  8721. c = 0;
  8722. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  8723. {
  8724. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  8725. c++;
  8726. }
  8727. sstr[c] = '\0';
  8728. strcpy(updateTypestr, sstr);
  8729. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  8730. //localAuthorizationList
  8731. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8732. loc = strstr(sstrtemp, localAuthorizationListsearch);
  8733. if(loc != NULL) // localAuthorizationList is not NULL
  8734. {
  8735. //Check UpdateType
  8736. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8737. {
  8738. //Local list full update
  8739. printf("Local list full update.\n");
  8740. OCPP_getListVerion();
  8741. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8742. {
  8743. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8744. goto end;
  8745. }
  8746. OCPP_cleanLocalList();
  8747. }
  8748. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8749. {
  8750. //Local list different update
  8751. printf("Local list different update.\n");
  8752. OCPP_getListVerion();
  8753. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8754. {
  8755. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  8756. goto end;
  8757. }
  8758. }
  8759. else
  8760. {
  8761. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8762. goto end;
  8763. }
  8764. c = 0;
  8765. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  8766. {
  8767. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  8768. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8769. c++;
  8770. }
  8771. sstr[c] = '\0';
  8772. //DEBUG_INFO("sstr=%s\n", sstr);
  8773. //parsing strings to words
  8774. i = 0;
  8775. pch = strtok(sstr,delim1);
  8776. while (pch != NULL)
  8777. {
  8778. strcpy(CardList[i], pch);
  8779. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  8780. pch = strtok (NULL, delim1);
  8781. i = i + 1;
  8782. }
  8783. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  8784. //local Authorizations List Numbers
  8785. //n_localAuthorizations = i;
  8786. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8787. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  8788. c= 0;
  8789. while(c < i) // i is CardList Number
  8790. {
  8791. //Search "IdToken"
  8792. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8793. loc = strstr(CardList[c], "idTag");
  8794. int j = 0;
  8795. while (loc[3+strlen("idTag")+j] != '\"')
  8796. {
  8797. sstr[j] = loc[3+strlen("idTag")+j];
  8798. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8799. j++;
  8800. }
  8801. sstr[j] = '\0';
  8802. strcpy(idTagstr, sstr);
  8803. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  8804. //Search "expiryDate"
  8805. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8806. loc = strstr(CardList[c], "expiryDate");
  8807. j = 0;
  8808. if(loc != NULL)
  8809. {
  8810. while (loc[3+strlen("expiryDate")+j] != '\"')
  8811. {
  8812. sstr[j] = loc[3+strlen("expiryDate")+j];
  8813. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8814. j++;
  8815. }
  8816. sstr[j] = '\0';
  8817. strcpy(expiryDate, sstr);
  8818. }
  8819. else
  8820. {
  8821. strcpy(expiryDate, "");
  8822. }
  8823. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  8824. //Search "parentIdTag"
  8825. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8826. loc = strstr(CardList[c], "parentIdTag");
  8827. j = 0;
  8828. if(loc != NULL)
  8829. {
  8830. while (loc[3+strlen("parentIdTag")+j] != '\"')
  8831. {
  8832. sstr[j] = loc[3+strlen("parentIdTag")+j];
  8833. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8834. j++;
  8835. }
  8836. sstr[j] = '\0';
  8837. strcpy(parentIdTag, sstr);
  8838. }
  8839. else
  8840. {
  8841. strcpy(parentIdTag, "");
  8842. }
  8843. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  8844. //Search "status"
  8845. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8846. loc = strstr(CardList[c], "status");
  8847. j = 0;
  8848. while (loc[3+strlen("status")+j] != '\"')
  8849. {
  8850. sstr[j] = loc[3+strlen("status")+j];
  8851. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8852. j++;
  8853. }
  8854. sstr[j] = '\0';
  8855. strcpy(idTagstatus, sstr);
  8856. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  8857. OCPP_getIdTagFromLocalList(idTagstr);
  8858. //OCPP_getIdTagFromLocalList("test"); For Test
  8859. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  8860. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  8861. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8862. {
  8863. //Local list full update
  8864. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8865. // update list
  8866. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8867. //DEBUG_INFO("Local list full update. 1\n");
  8868. //OCPP_get_TableAuthlocalAllData();
  8869. //DEBUG_INFO("Local list full update. 2\n");
  8870. }
  8871. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8872. {
  8873. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8874. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  8875. }
  8876. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  8877. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  8878. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  8879. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  8880. c++;
  8881. }
  8882. }
  8883. else
  8884. {
  8885. //Check UpdateType
  8886. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8887. {
  8888. //Local list full update
  8889. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  8890. OCPP_cleanLocalList();
  8891. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8892. goto end;
  8893. }
  8894. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8895. {
  8896. //Local list different update
  8897. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  8898. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8899. goto end;
  8900. }
  8901. }
  8902. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8903. end:
  8904. sendSendLocalListConfirmation(uuid, comfirmstr);
  8905. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  8906. return result;
  8907. }
  8908. #define MAX 200
  8909. int handleSetChargingProfileRequest(char *uuid, char *payload)
  8910. {
  8911. mtrace();
  8912. int result = FAIL;
  8913. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  8914. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  8915. char chargingProfilePurposeStr[30]={0};
  8916. char chargingProfileKindStr[16]={0};
  8917. char recurrencyKindStr[10]={0};
  8918. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  8919. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  8920. int chargingSchedulePeriodCount = 0;
  8921. char comfirmstr[20]={0};
  8922. int meet= FALSE;
  8923. FILE *fptr1;
  8924. char filename[MAX]={0};
  8925. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  8926. char rmFileCmd[50]={0};
  8927. char tempchargingProfilePurposeStr[30]={0};
  8928. char word[1600]={0};
  8929. int n_chargingProfile = 0;
  8930. json_object *SetChargingProfile;
  8931. DEBUG_INFO("handleSetChargingProfileRequest\n");
  8932. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  8933. SetChargingProfile = json_tokener_parse(payload);
  8934. if(!is_error(SetChargingProfile))
  8935. {
  8936. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  8937. {
  8938. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  8939. if(connectorIdInt == 0)
  8940. {
  8941. memset(&ShmOCPP16Data->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  8942. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  8943. }
  8944. else
  8945. {
  8946. memset(&ShmOCPP16Data->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  8947. ShmOCPP16Data->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  8948. }
  8949. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  8950. }
  8951. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  8952. {
  8953. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  8954. {
  8955. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  8956. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8957. {
  8958. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8959. }
  8960. else
  8961. {
  8962. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8963. }
  8964. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  8965. }
  8966. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  8967. {
  8968. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  8969. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8970. {
  8971. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  8972. }
  8973. else
  8974. {
  8975. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  8976. }
  8977. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  8978. }
  8979. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8980. {
  8981. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  8982. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8983. {
  8984. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8985. }
  8986. else
  8987. {
  8988. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8989. }
  8990. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  8991. }
  8992. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  8993. {
  8994. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  8995. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8996. {
  8997. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8998. }
  8999. else
  9000. {
  9001. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  9002. }
  9003. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  9004. }
  9005. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  9006. {
  9007. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  9008. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9009. {
  9010. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  9011. }
  9012. else
  9013. {
  9014. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  9015. }
  9016. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  9017. }
  9018. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  9019. {
  9020. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  9021. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9022. {
  9023. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9024. }
  9025. else
  9026. {
  9027. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9028. }
  9029. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  9030. }
  9031. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  9032. {
  9033. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  9034. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9035. {
  9036. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  9037. }
  9038. else
  9039. {
  9040. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  9041. }
  9042. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  9043. }
  9044. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  9045. {
  9046. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  9047. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9048. {
  9049. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  9050. }
  9051. else
  9052. {
  9053. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  9054. }
  9055. //DEBUG_INFO("validToStr: %s\n", validToStr);
  9056. }
  9057. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  9058. {
  9059. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  9060. {
  9061. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  9062. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9063. {
  9064. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9065. }
  9066. else
  9067. {
  9068. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9069. }
  9070. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  9071. }
  9072. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  9073. {
  9074. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  9075. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9076. {
  9077. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9078. }
  9079. else
  9080. {
  9081. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9082. }
  9083. //DEBUG_INFO("durationInt: %d\n", durationInt);
  9084. }
  9085. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  9086. {
  9087. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  9088. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9089. {
  9090. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9091. }
  9092. else
  9093. {
  9094. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9095. }
  9096. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  9097. }
  9098. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  9099. {
  9100. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  9101. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9102. {
  9103. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9104. }
  9105. else
  9106. {
  9107. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9108. }
  9109. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  9110. }
  9111. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9112. {
  9113. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  9114. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  9115. if(chargingSchedulePeriodCount <= 10)
  9116. {
  9117. 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++)
  9118. {
  9119. 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)
  9120. {
  9121. 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"));
  9122. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9123. {
  9124. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9125. }
  9126. else
  9127. {
  9128. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9129. }
  9130. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  9131. }
  9132. 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)
  9133. {
  9134. 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"));
  9135. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9136. {
  9137. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9138. }
  9139. else
  9140. {
  9141. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9142. }
  9143. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  9144. }
  9145. 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)
  9146. {
  9147. 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"));
  9148. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9149. {
  9150. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9151. }
  9152. else
  9153. {
  9154. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9155. }
  9156. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  9157. }
  9158. }
  9159. }
  9160. }
  9161. }
  9162. }
  9163. }
  9164. json_object_put(SetChargingProfile);
  9165. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  9166. {
  9167. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9168. goto end;
  9169. }
  9170. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  9171. {
  9172. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  9173. if(connectorIdInt != 0)
  9174. {
  9175. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9176. goto end;
  9177. }
  9178. strcpy(filename, ChargePointMaxProfile_JSON );
  9179. fptr1 = fopen(filename, "r");
  9180. if (!fptr1)
  9181. {
  9182. //file not exist
  9183. DEBUG_INFO("Unable to open the input file!!\n");
  9184. fptr1 = fopen(filename, "w+");
  9185. }
  9186. else
  9187. {
  9188. //Check Charging Profile Count
  9189. while(fscanf(fptr1, "%s", word) != EOF)
  9190. {
  9191. //DEBUG_INFO("word=%s\n",word);
  9192. if(strstr(word, "chargingProfileId")!= NULL)
  9193. {
  9194. //DEBUG_INFO("test chargingProfileId \n");
  9195. n_chargingProfile = n_chargingProfile + 1;
  9196. //DEBUG_INFO("chargingProfileId Found\n");
  9197. }
  9198. }
  9199. }
  9200. fclose(fptr1);
  9201. }
  9202. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  9203. {
  9204. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  9205. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9206. {
  9207. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9208. goto end;
  9209. }
  9210. memset(filename, 0, ARRAY_SIZE(filename));
  9211. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9212. fptr1 = fopen(filename, "r");
  9213. if (!fptr1)
  9214. {
  9215. //file not exist
  9216. //DEBUG_INFO("Unable to open the input file!!\n");
  9217. fptr1 = fopen(filename, "w+");
  9218. }
  9219. else
  9220. {
  9221. //Check Charging Profile Count
  9222. while(fscanf(fptr1, "%s", word) != EOF)
  9223. {
  9224. //DEBUG_INFO("word=%s\n",word);
  9225. if(strstr(word, "chargingProfileId")!= NULL)
  9226. {
  9227. //DEBUG_INFO("test chargingProfileId \n");
  9228. n_chargingProfile = n_chargingProfile + 1;
  9229. //DEBUG_INFO("chargingProfileId Found\n");
  9230. }
  9231. }
  9232. }
  9233. fclose(fptr1);
  9234. }
  9235. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9236. {
  9237. //printf("set chargingProfile 1-4\n");
  9238. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  9239. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  9240. if(connectorIdInt == 0)
  9241. {
  9242. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9243. goto end;
  9244. }
  9245. int tempIndex = 0;
  9246. //check Transaction active
  9247. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9248. {
  9249. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9250. {
  9251. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9252. }
  9253. else
  9254. {
  9255. tempIndex = connectorIdInt -1;
  9256. }
  9257. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9258. {
  9259. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9260. {
  9261. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9262. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9263. {
  9264. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9265. {
  9266. meet = TRUE;
  9267. break;
  9268. }
  9269. }
  9270. }
  9271. }
  9272. }
  9273. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9274. {
  9275. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9276. {
  9277. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9278. }
  9279. else
  9280. {
  9281. tempIndex = connectorIdInt -1;
  9282. }
  9283. for (int index = 0; index < CCS_QUANTITY; index++)
  9284. {
  9285. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9286. {
  9287. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9288. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9289. {
  9290. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9291. {
  9292. meet = TRUE;
  9293. break;
  9294. }
  9295. }
  9296. }
  9297. }
  9298. }
  9299. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9300. {
  9301. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9302. {
  9303. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9304. }
  9305. else
  9306. {
  9307. tempIndex = connectorIdInt -1;
  9308. }
  9309. for (int index = 0; index < GB_QUANTITY; index++)
  9310. {
  9311. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9312. {
  9313. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9314. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9315. {
  9316. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9317. {
  9318. meet = TRUE;
  9319. break;
  9320. }
  9321. }
  9322. }
  9323. }
  9324. }
  9325. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9326. {
  9327. tempIndex = connectorIdInt -1;
  9328. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9329. {
  9330. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9331. {
  9332. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  9333. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9334. {
  9335. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9336. {
  9337. meet = TRUE;
  9338. break;
  9339. }
  9340. }
  9341. }
  9342. }
  9343. }
  9344. else
  9345. {
  9346. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9347. {
  9348. tempIndex = 2;
  9349. }
  9350. else
  9351. {
  9352. tempIndex = (connectorIdInt -1);
  9353. }
  9354. for (int index = 0; index < AC_QUANTITY; index++)
  9355. {
  9356. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9357. {
  9358. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9359. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9360. {
  9361. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9362. {
  9363. meet = TRUE;
  9364. break;
  9365. }
  9366. }
  9367. }
  9368. }
  9369. }
  9370. //check Transaction active
  9371. if(meet == FALSE)
  9372. {
  9373. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9374. goto end;
  9375. }
  9376. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9377. {
  9378. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9379. goto end;
  9380. }
  9381. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9382. fptr1 = fopen(filename, "r");
  9383. if (!fptr1)
  9384. {
  9385. //file not exist
  9386. DEBUG_INFO("Unable to open the input file!!\n");
  9387. fptr1 = fopen(filename, "w+");
  9388. }
  9389. else
  9390. {
  9391. //Check Charging Profile Count
  9392. while(fscanf(fptr1, "%s", word) != EOF)
  9393. {
  9394. //DEBUG_INFO("word=%s\n",word);
  9395. if(strstr(word, "chargingProfileId")!= NULL)
  9396. {
  9397. //DEBUG_INFO("test chargingProfileId \n");
  9398. n_chargingProfile = n_chargingProfile + 1;
  9399. //DEBUG_INFO("chargingProfileId Found\n");
  9400. }
  9401. }
  9402. }
  9403. fclose(fptr1);
  9404. }
  9405. // Check ChargeProfileMaxStackLevel
  9406. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  9407. {
  9408. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9409. goto end;
  9410. }
  9411. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9412. {
  9413. int i = 0;
  9414. char fnametemp[200]={0};
  9415. n_chargingProfile = 0;
  9416. //Check ChargePointMaxProfile.json exit
  9417. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9418. {
  9419. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  9420. //Check Charging Profile Count
  9421. while(fscanf(fptr1, "%s", word) != EOF)
  9422. {
  9423. //DEBUG_INFO("word=%s\n",word);
  9424. if(strstr(word, "chargingProfileId")!= NULL)
  9425. {
  9426. //DEBUG_INFO("test chargingProfileId \n");
  9427. n_chargingProfile = n_chargingProfile + 1;
  9428. i = i + 1;
  9429. //DEBUG_INFO("chargingProfileId Found\n");
  9430. }
  9431. memset(word, 0, ARRAY_SIZE(word));
  9432. }
  9433. fclose(fptr1);
  9434. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  9435. }
  9436. //Check TxDefaultProfile_0.json exit
  9437. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9438. {
  9439. i = 0;
  9440. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  9441. //Check Charging Profile Count
  9442. while(fscanf(fptr1, "%s", word) != EOF)
  9443. {
  9444. //DEBUG_INFO("word=%s\n",word);
  9445. if(strstr(word, "chargingProfileId")!= NULL)
  9446. {
  9447. //DEBUG_INFO("test chargingProfileId \n");
  9448. n_chargingProfile = n_chargingProfile + 1;
  9449. i = i + 1;
  9450. //DEBUG_INFO("chargingProfileId Found\n");
  9451. }
  9452. memset(word, 0, ARRAY_SIZE(word));
  9453. }
  9454. fclose(fptr1);
  9455. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  9456. }
  9457. //Check TxDefaultProfile_%d.json
  9458. for(int j=1; j <= gunTotalNumber; j++)
  9459. {
  9460. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9461. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9462. if((access(fnametemp,F_OK))!=-1)
  9463. {
  9464. i = 0;
  9465. fptr1 = fopen(fnametemp, "r");
  9466. //Check Charging Profile Count
  9467. while(fscanf(fptr1, "%s", word) != EOF)
  9468. {
  9469. //DEBUG_INFO("word=%s\n",word);
  9470. if(strstr(word, "chargingProfileId")!= NULL)
  9471. {
  9472. //DEBUG_INFO("test chargingProfileId \n");
  9473. n_chargingProfile = n_chargingProfile + 1;
  9474. i = i + 1;
  9475. //DEBUG_INFO("chargingProfileId Found\n");
  9476. }
  9477. memset(word, 0, ARRAY_SIZE(word));
  9478. }
  9479. fclose(fptr1);
  9480. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9481. }
  9482. }
  9483. //Check TxProfile_%d.json
  9484. for(int j=1; j <= gunTotalNumber; j++)
  9485. {
  9486. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9487. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9488. if((access(fnametemp,F_OK))!=-1)
  9489. {
  9490. i = 0;
  9491. fptr1 = fopen(fnametemp, "r");
  9492. //Check Charging Profile Count
  9493. while(fscanf(fptr1, "%s", word) != EOF)
  9494. {
  9495. //DEBUG_INFO("word=%s\n",word);
  9496. if(strstr(word, "chargingProfileId")!= NULL)
  9497. {
  9498. //DEBUG_INFO("test chargingProfileId \n");
  9499. n_chargingProfile = n_chargingProfile + 1;
  9500. i = i + 1;
  9501. //DEBUG_INFO("chargingProfileId Found\n");
  9502. }
  9503. memset(word, 0, ARRAY_SIZE(word));
  9504. }
  9505. fclose(fptr1);
  9506. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9507. }
  9508. }
  9509. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  9510. {
  9511. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9512. goto end;
  9513. }
  9514. }
  9515. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9516. //**********************************Write to File********************************************************/
  9517. FILE *infile;
  9518. FILE *outfile;
  9519. infile = fopen (filename, "r");
  9520. outfile = fopen (tempfile, "w");
  9521. int d =0;
  9522. d = fgetc(infile);
  9523. rewind(infile);
  9524. if(d == EOF)
  9525. {
  9526. // Profile is empty
  9527. fprintf(outfile,"%s\n",payload);
  9528. fclose(infile);
  9529. fclose(outfile);
  9530. sprintf(rmFileCmd,"rm -f %s",filename);
  9531. system(rmFileCmd);
  9532. rename(tempfile, filename);
  9533. }
  9534. else
  9535. {
  9536. // Profile is not empty
  9537. char buf[2048]={0};
  9538. int ChargingProfileAdded = FALSE;
  9539. while (fgets(buf, sizeof(buf), infile) != NULL)
  9540. {
  9541. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9542. json_object *tmpChargingProfile;
  9543. tmpChargingProfile = json_tokener_parse(buf);
  9544. if(!is_error(SetChargingProfile))
  9545. {
  9546. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  9547. {
  9548. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  9549. }
  9550. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  9551. {
  9552. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  9553. {
  9554. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  9555. }
  9556. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  9557. {
  9558. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  9559. }
  9560. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9561. {
  9562. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  9563. }
  9564. }
  9565. }
  9566. json_object_put(tmpChargingProfile);
  9567. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  9568. {
  9569. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9570. {
  9571. //DEBUG_INFO("update set chargingProfile to file -0\n");
  9572. if(ChargingProfileAdded == FALSE)
  9573. {
  9574. fprintf(outfile,"%s\n",payload);
  9575. ChargingProfileAdded = TRUE;
  9576. }
  9577. }
  9578. else
  9579. {
  9580. if(tempstackLevelInt < stackLevelInt)
  9581. {
  9582. if(ChargingProfileAdded == FALSE)
  9583. {
  9584. fprintf(outfile,"%s\n",buf);
  9585. fprintf(outfile,"%s\n",payload);
  9586. ChargingProfileAdded = TRUE;
  9587. }
  9588. else
  9589. {
  9590. fprintf(outfile,"%s\n",buf);
  9591. }
  9592. }
  9593. else
  9594. {
  9595. if(ChargingProfileAdded == FALSE)
  9596. {
  9597. fprintf(outfile,"%s\n",buf);
  9598. fprintf(outfile,"%s\n",payload);
  9599. ChargingProfileAdded = TRUE;
  9600. }
  9601. else
  9602. {
  9603. fprintf(outfile,"%s\n",buf);
  9604. }
  9605. }
  9606. }
  9607. }
  9608. else
  9609. {
  9610. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9611. {
  9612. if(ChargingProfileAdded == FALSE)
  9613. {
  9614. fprintf(outfile,"%s\n",buf);
  9615. fprintf(outfile,"%s\n",payload);
  9616. ChargingProfileAdded = TRUE;
  9617. }
  9618. else
  9619. {
  9620. fprintf(outfile,"%s\n",buf);
  9621. }
  9622. }
  9623. else if(tempstackLevelInt < stackLevelInt)
  9624. {
  9625. if(ChargingProfileAdded == FALSE)
  9626. {
  9627. fprintf(outfile,"%s\n",buf);
  9628. fprintf(outfile,"%s\n",payload);
  9629. ChargingProfileAdded = TRUE;
  9630. }
  9631. else
  9632. {
  9633. fprintf(outfile,"%s\n",buf);
  9634. }
  9635. }
  9636. else
  9637. {
  9638. if(ChargingProfileAdded == FALSE)
  9639. {
  9640. fprintf(outfile,"%s\n",buf);
  9641. fprintf(outfile,"%s\n",payload);
  9642. ChargingProfileAdded = TRUE;
  9643. }
  9644. else
  9645. {
  9646. fprintf(outfile,"%s\n",buf);
  9647. }
  9648. }
  9649. }
  9650. } // end of while loop
  9651. fclose(infile);
  9652. fclose(outfile);
  9653. sprintf(rmFileCmd,"rm -f %s",filename);
  9654. system(rmFileCmd);
  9655. rename(tempfile, filename);
  9656. }
  9657. sleep(1);
  9658. result = TRUE;
  9659. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9660. end:
  9661. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  9662. {
  9663. if(connectorIdInt == 0)
  9664. {
  9665. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9666. {
  9667. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  9668. }
  9669. }
  9670. else
  9671. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  9672. }
  9673. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  9674. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9675. return result;
  9676. }
  9677. int handleTriggerMessageRequest(char *uuid, char *payload)
  9678. {
  9679. mtrace();
  9680. int result = FAIL;
  9681. int connectorIdIsNULL = FALSE;
  9682. int connectorIdInt =0;
  9683. char sstr[40]={0},sstrtemp[100]={ 0 };
  9684. char requestedMessagestr[40]={0};
  9685. char comfirmstr[20]={0};
  9686. int c = 0;
  9687. char *loc;
  9688. DEBUG_INFO("handleTriggerMessageRequest\n");
  9689. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  9690. strcpy(sstrtemp, stringtrimspace(payload));
  9691. c = 0;
  9692. loc = strstr(sstrtemp, "requestedMessage");
  9693. while (loc[3+strlen("requestedMessage")+c] != '\"')
  9694. {
  9695. sstr[c] = loc[3+strlen("requestedMessage")+c];
  9696. c++;
  9697. }
  9698. sstr[c] = '\0';
  9699. strcpy(requestedMessagestr, sstr);
  9700. c = 0;
  9701. loc = strstr(sstrtemp, "connectorId");
  9702. if(loc == NULL)
  9703. {
  9704. connectorIdIsNULL = TRUE;
  9705. }
  9706. else
  9707. {
  9708. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9709. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  9710. {
  9711. sstr[c] = loc[strlen("connectorId")+2+c];
  9712. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9713. c++;
  9714. }
  9715. sstr[c] = '\0';
  9716. connectorIdInt = atoi(sstr);
  9717. }
  9718. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  9719. {
  9720. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  9721. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  9722. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  9723. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  9724. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  9725. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  9726. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  9727. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  9728. {
  9729. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  9730. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9731. return TRUE;
  9732. }
  9733. else
  9734. {
  9735. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9736. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9737. }
  9738. }
  9739. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  9740. {
  9741. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  9742. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9743. return TRUE;
  9744. }
  9745. //==========================
  9746. // Trigger message
  9747. //==========================
  9748. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  9749. {
  9750. if((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) &&
  9751. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) &&
  9752. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) &&
  9753. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING) )
  9754. {
  9755. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  9756. }
  9757. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  9758. }
  9759. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  9760. {
  9761. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  9762. }
  9763. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  9764. {
  9765. //sendBootNotificationRequest();
  9766. server_sign = FALSE;
  9767. }
  9768. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  9769. {
  9770. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  9771. }
  9772. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  9773. {
  9774. if(connectorIdIsNULL == FALSE)
  9775. {
  9776. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9777. {
  9778. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  9779. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  9780. }
  9781. }
  9782. else
  9783. {
  9784. for(int idx=0;idx< gunTotalNumber;idx++)
  9785. {
  9786. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  9787. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  9788. }
  9789. }
  9790. }
  9791. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  9792. {
  9793. if(connectorIdIsNULL == FALSE)
  9794. {
  9795. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9796. {
  9797. cpinitateMsg.bits[connectorIdInt -1].StatusNotificationReq = 1;
  9798. }
  9799. }
  9800. else
  9801. {
  9802. for(int idx=0;idx< gunTotalNumber;idx++)
  9803. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  9804. }
  9805. }
  9806. return result;
  9807. }
  9808. int handleUnlockConnectorRequest(char *uuid, char *payload)
  9809. {
  9810. mtrace();
  9811. int result = FAIL;
  9812. int connectorIdInt =0;
  9813. char comfirmstr[20]={0};
  9814. int tempIndex = 0;
  9815. json_object *UnlockConnector;
  9816. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  9817. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  9818. UnlockConnector = json_tokener_parse(payload);
  9819. if(!is_error(UnlockConnector))
  9820. {
  9821. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  9822. {
  9823. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  9824. }
  9825. }
  9826. json_object_put(UnlockConnector);
  9827. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  9828. if(gunTotalNumber == 0)
  9829. {
  9830. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9831. goto end;
  9832. }
  9833. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  9834. {
  9835. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9836. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9837. goto end;
  9838. }
  9839. else
  9840. {
  9841. //check Transaction active
  9842. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  9843. {
  9844. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9845. {
  9846. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9847. }
  9848. else
  9849. {
  9850. tempIndex = connectorIdInt -1;
  9851. }
  9852. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9853. {
  9854. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9855. {
  9856. //stop Transaction
  9857. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9858. }
  9859. }
  9860. }
  9861. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  9862. {
  9863. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9864. {
  9865. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9866. }
  9867. else
  9868. {
  9869. tempIndex = connectorIdInt -1;
  9870. }
  9871. for (int index = 0; index < CCS_QUANTITY; index++)
  9872. {
  9873. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9874. {
  9875. //stop Transaction
  9876. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9877. }
  9878. }
  9879. }
  9880. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  9881. {
  9882. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9883. {
  9884. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9885. }
  9886. else
  9887. {
  9888. tempIndex = connectorIdInt -1;
  9889. }
  9890. for (int index = 0; index < GB_QUANTITY; index++)
  9891. {
  9892. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  9893. {
  9894. //stop Transaction
  9895. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9896. }
  9897. }
  9898. }
  9899. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  9900. {
  9901. tempIndex = connectorIdInt -1;
  9902. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9903. {
  9904. 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)))
  9905. {
  9906. //stop Transaction
  9907. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9908. }
  9909. }
  9910. }
  9911. else
  9912. {
  9913. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9914. {
  9915. tempIndex = 2;
  9916. }
  9917. else
  9918. {
  9919. tempIndex = connectorIdInt-1;
  9920. }
  9921. for (int index = 0; index < AC_QUANTITY; index++)
  9922. {
  9923. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9924. {
  9925. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9926. }
  9927. }
  9928. }
  9929. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  9930. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  9931. result = TRUE;
  9932. return result;
  9933. }
  9934. end:
  9935. //json_object_put(obj); --- remove temporally
  9936. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  9937. return result;
  9938. }
  9939. static char UpdateFirmwarepayloadData[300]={0};
  9940. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  9941. {
  9942. mtrace();
  9943. int result = FAIL;
  9944. pthread_t t;
  9945. sendUpdateFirmwareConfirmation(uuid);
  9946. memset(UpdateFirmwarepayloadData, 0, 300);
  9947. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  9948. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  9949. ////pthread_join(t, NULL); //
  9950. //pthread_detach(t);
  9951. //sendUpdateFirmwareConfirmation(uuid);
  9952. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  9953. return result;
  9954. }
  9955. void *UpdateFirmwareProcess(void *data)
  9956. {
  9957. pthread_detach(pthread_self());
  9958. mtrace();
  9959. int retriesInt =0, retryIntervalInt=0;
  9960. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  9961. int port=0;
  9962. char locationstr[160]={0}, retrieveDatestr[30]={0};
  9963. int isSuccess = 0;
  9964. char ftpbuf[200];
  9965. char temp[100];
  9966. char * pch;
  9967. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  9968. json_object *UpdateFirmware;
  9969. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  9970. if(!is_error(UpdateFirmware))
  9971. {
  9972. // Required data
  9973. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  9974. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  9975. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  9976. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  9977. // Optional data
  9978. if(json_object_object_get(UpdateFirmware, "retries"))
  9979. {
  9980. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  9981. }
  9982. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  9983. {
  9984. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  9985. }
  9986. }
  9987. json_object_put(UpdateFirmware);
  9988. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9989. memset(path, 0, ARRAY_SIZE(path));
  9990. system("rm -f /mnt/*");
  9991. if(strncmp(locationstr,"http", 4) == 0)
  9992. {
  9993. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9994. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  9995. // protocol, user, password, host, path);
  9996. sprintf(ftppath,"/%s", path);
  9997. DEBUG_INFO("locationstr: %s\n", locationstr);
  9998. DEBUG_INFO("protocol: %s\n",protocol);
  9999. DEBUG_INFO("host: %s\n",host);
  10000. DEBUG_INFO("path: %s\n",path);
  10001. DEBUG_INFO("ftppath: %s\n",ftppath);
  10002. int ftppathlen=strlen(ftppath);
  10003. int i=1;
  10004. char filenametemp[50];
  10005. while(i < ftppathlen)
  10006. {
  10007. int len=ftppathlen-i;
  10008. if(ftppath[len]== 47) // '/' ascll code: 47
  10009. {
  10010. DEBUG_INFO("compare '/' all right\n");
  10011. break;
  10012. }
  10013. i=i+1;
  10014. }
  10015. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10016. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10017. filenametemp[i+1] = 0;
  10018. do
  10019. {
  10020. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  10021. sleep(3);
  10022. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  10023. if(!isSuccess)
  10024. {
  10025. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10026. sleep(retryIntervalInt);
  10027. }
  10028. else
  10029. {
  10030. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10031. }
  10032. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  10033. }
  10034. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  10035. {
  10036. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  10037. memset(temp, 0, ARRAY_SIZE(temp));
  10038. //DEBUG_INFO("locationstr=%s\n",locationstr);
  10039. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  10040. int ftppathlen=strlen(ftpbuf);
  10041. int i=1;
  10042. char filenametemp[50];
  10043. while(i < ftppathlen)
  10044. {
  10045. int len=ftppathlen-i;
  10046. if(ftpbuf[len]== 47) // '/' ascll code: 47
  10047. {
  10048. DEBUG_INFO(" compare '/' all right\n");
  10049. break;
  10050. }
  10051. i=i+1;
  10052. }
  10053. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10054. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  10055. filenametemp[i+1] = 0;
  10056. strncpy(temp, ftpbuf, ftppathlen-i+1);
  10057. pch=strchr(temp,'@');
  10058. if(pch==NULL)
  10059. {
  10060. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10061. protocol, host, &port, path);
  10062. strcpy(user,"anonymous");
  10063. strcpy(password,"");
  10064. }
  10065. else
  10066. {
  10067. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10068. protocol, user, password, host, &port, path);
  10069. }
  10070. sscanf(host,"%[^/]%s",host1, path1);
  10071. sprintf(ftppath,"%s", path1);
  10072. //DEBUG_INFO("protocol =%s\n",protocol);
  10073. //DEBUG_INFO("user =%s\n",user);
  10074. //DEBUG_INFO("password =%s\n",password);
  10075. //DEBUG_INFO("host1 =%s\n",host1);
  10076. //DEBUG_INFO("port =%d\n",port);
  10077. //DEBUG_INFO("path1 =%s\n",path1);
  10078. //DEBUG_INFO("ftppath=%s\n",ftppath);
  10079. //ftpFile(host, user, password, port, ftppath, fname);
  10080. //download firmware pthred
  10081. if(port == 0)
  10082. {
  10083. port = 21;
  10084. }
  10085. do
  10086. {
  10087. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  10088. sleep(3);
  10089. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  10090. if(!isSuccess)
  10091. {
  10092. //BulldogUtil.sleepMs(interval*1000);
  10093. DEBUG_INFO("Update firmware request and download file fail.\n");
  10094. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10095. sleep(retryIntervalInt);
  10096. }
  10097. else
  10098. {
  10099. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10100. }
  10101. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  10102. }
  10103. else
  10104. {
  10105. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10106. }
  10107. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  10108. pthread_exit(NULL);
  10109. }
  10110. int handleUnknownRequest(char *uuid, char *payload)
  10111. {
  10112. mtrace();
  10113. int result = FAIL;
  10114. DEBUG_INFO("handleUnknownRequest...\n");
  10115. sendUnknownConfirmation(uuid);
  10116. result = PASS;
  10117. return result;
  10118. }
  10119. //==========================================
  10120. // Handle server response routine
  10121. //==========================================
  10122. void handleAuthorizeResponse(char *payload, int gun_index)
  10123. {
  10124. mtrace();
  10125. char expiryDatestr[30]={0};
  10126. char parentIdTagstr[20]={0};
  10127. char statusstr[20]={0};
  10128. int expiryDateISNULL=FALSE;
  10129. int parentIdTagISNULL=FALSE;
  10130. DEBUG_INFO("handleAuthorizeResponse...\n");
  10131. json_object *Authorize;
  10132. Authorize = json_tokener_parse(payload);
  10133. if(!is_error(Authorize))
  10134. {
  10135. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  10136. {
  10137. // Required data
  10138. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  10139. // Optional data
  10140. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  10141. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  10142. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  10143. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  10144. }
  10145. }
  10146. json_object_put(Authorize);
  10147. if(expiryDateISNULL == FALSE)
  10148. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  10149. if(parentIdTagISNULL == FALSE)
  10150. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  10151. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  10152. //Update idTag information to authorization cache if supproted
  10153. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  10154. {
  10155. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  10156. }
  10157. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  10158. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  10159. authorizeRetryTimes = 0;
  10160. }
  10161. void handleBootNotificationResponse(char *payload, int gun_index)
  10162. {
  10163. mtrace();
  10164. char statusStr[12]={0};
  10165. char currentTimeStr[30]={0};
  10166. int intervalInt = 0;
  10167. struct tm tp;
  10168. char buf[28]={0};
  10169. char timebuf[50]={0};
  10170. DEBUG_INFO("handleBootNotificationResponse...\n");
  10171. json_object *BootNotification;
  10172. BootNotification = json_tokener_parse(payload);
  10173. if(!is_error(BootNotification))
  10174. {
  10175. // Required data
  10176. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  10177. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  10178. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  10179. }
  10180. json_object_put(BootNotification);
  10181. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10182. BootNotificationInterval = intervalInt;
  10183. HeartBeatWaitTime = intervalInt;
  10184. //write back to ShmOCPP16Data->BootNotification
  10185. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  10186. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10187. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  10188. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  10189. {
  10190. server_sign = TRUE;
  10191. server_pending =FALSE;
  10192. }
  10193. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  10194. {
  10195. server_pending = TRUE;
  10196. }
  10197. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10198. tp.tm_isdst = -1;
  10199. //time_t utc = mktime(&tp);
  10200. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  10201. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  10202. sprintf(timebuf,"date -s '%s'",buf);
  10203. system(timebuf);
  10204. srand(time(NULL));
  10205. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  10206. //==============================================
  10207. // RTC sync
  10208. //==============================================
  10209. system("/sbin/hwclock -w --systohc");
  10210. SetOcppConnStatus(TRUE);
  10211. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  10212. }
  10213. void handleDataTransferResponse(char *payload, int gun_index)
  10214. {
  10215. char sstr[160]={0};//sstr[200]={ 0 };
  10216. int c = 0;
  10217. char *loc;
  10218. DEBUG_INFO("handleDataTransferResponse ...\n");
  10219. loc = strstr(payload, "status");
  10220. printf("loc=%s\n",loc);
  10221. c = 0;
  10222. while (loc[3+strlen("status")+c] != '\"')
  10223. {
  10224. sstr[c] = loc[3+strlen("status")+c];
  10225. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10226. c++;
  10227. }
  10228. sstr[c] = '\0';
  10229. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  10230. }
  10231. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  10232. {
  10233. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  10234. //struct json_object *obj;
  10235. // obj = json_tokener_parse(payload);
  10236. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  10237. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  10238. //No fields are defined.
  10239. }
  10240. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  10241. {
  10242. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  10243. //struct json_object *obj;
  10244. // obj = json_tokener_parse(payload);
  10245. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  10246. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  10247. //No fields are defined.
  10248. }
  10249. void handleHeartbeatResponse(char *payload, int gun_index)
  10250. {
  10251. mtrace();
  10252. struct tm tp;
  10253. char buf[28]={0};
  10254. char timebuf[50]={0};
  10255. DEBUG_INFO("handleHeartbeatResponse...\n");
  10256. json_object *Heartbeat;
  10257. Heartbeat = json_tokener_parse(payload);
  10258. if(!is_error(Heartbeat))
  10259. {
  10260. // Required data
  10261. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  10262. }
  10263. json_object_put(Heartbeat);
  10264. if(FirstHeartBeat == 0)
  10265. {
  10266. FirstHeartBeat = 1;
  10267. DEBUG_INFO("FirstHeartBeat \n");
  10268. }
  10269. HeartBeatWithNOResponse = 0;
  10270. clientTime.Heartbeat=time((time_t*)NULL);
  10271. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10272. tp.tm_isdst = -1;
  10273. //time_t utc = mktime(&tp);
  10274. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  10275. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  10276. sprintf(timebuf,"date -s '%s'",buf);
  10277. system(timebuf);
  10278. //==============================================
  10279. // RTC sync
  10280. //==============================================
  10281. system("/sbin/hwclock -w --systohc");
  10282. }
  10283. void handleMeterValuesResponse(char *payload, int gun_index)
  10284. {
  10285. mtrace();
  10286. DEBUG_INFO("handleMeterValuesResponse...\n");
  10287. }
  10288. void handleStartTransactionResponse(char *payload, int gun_index)
  10289. {
  10290. mtrace();
  10291. //int transactionIdInt = 0;
  10292. FILE *outfile;
  10293. char data[100]={0};
  10294. DEBUG_INFO("handleStartTransactionResponse...\n");
  10295. json_object *StartTransaction;
  10296. StartTransaction = json_tokener_parse(payload);
  10297. if(!is_error(StartTransaction))
  10298. {
  10299. // Required data
  10300. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  10301. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  10302. // Optional data
  10303. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  10304. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  10305. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  10306. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  10307. }
  10308. json_object_put(StartTransaction);
  10309. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  10310. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  10311. //-----------Start : write to the Queue TransactionId file -----------------//
  10312. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  10313. {}
  10314. else
  10315. {
  10316. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  10317. if(log == NULL)
  10318. {
  10319. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  10320. return ;
  10321. }
  10322. else
  10323. {
  10324. fclose(log);
  10325. }
  10326. }
  10327. // open file for writing
  10328. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  10329. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  10330. {
  10331. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  10332. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  10333. fputs(data, outfile);
  10334. fclose (outfile);
  10335. }
  10336. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10337. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10338. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  10339. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  10340. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10341. }
  10342. void handleStatusNotificationResponse(char *payload, int gun_index)
  10343. {
  10344. mtrace();
  10345. DEBUG_INFO("handleStatusNotificationResponse...\n");
  10346. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  10347. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  10348. }
  10349. void handleStopTransactionnResponse(char *payload, int gun_index)
  10350. {
  10351. mtrace();
  10352. DEBUG_INFO("handleStopTransactionnResponse...\n");
  10353. json_object *StopTransaction;
  10354. StopTransaction = json_tokener_parse(payload);
  10355. if(!is_error(StopTransaction))
  10356. {
  10357. // Optional data
  10358. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  10359. {
  10360. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  10361. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  10362. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  10363. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  10364. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  10365. }
  10366. }
  10367. json_object_put(StopTransaction);
  10368. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  10369. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  10370. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10371. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10372. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  10373. }
  10374. //==========================================
  10375. // Handle Error routine
  10376. //==========================================
  10377. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  10378. {
  10379. mtrace();
  10380. #ifdef SystemLogMessage
  10381. DEBUG_INFO("errorCode: %s\n", errorCode);
  10382. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  10383. DEBUG_INFO("errorDetails: %s\n", payload);
  10384. #endif
  10385. }
  10386. //===============================================
  10387. // Common routine
  10388. //===============================================
  10389. int initialConfigurationTable(void)
  10390. {
  10391. //clock_t start_t, end_t, total_t;
  10392. FILE *fp;
  10393. FILE *outfile;
  10394. char str[512]={0};
  10395. char sstr[256]={0};
  10396. int c = 0;
  10397. char *loc;
  10398. int confVersion = 1;
  10399. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  10400. //start_t = clock();
  10401. //printf("Starting of the program, start_t = %ld\n", start_t);
  10402. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  10403. // Check configuration file size is correct
  10404. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  10405. {
  10406. struct stat st;
  10407. stat("/Storage/OCPP/OCPPConfiguration", &st);
  10408. if(st.st_size < 3100)
  10409. {
  10410. system("rm -f /Storage/OCPP/OCPPConfiguration");
  10411. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  10412. }
  10413. }
  10414. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  10415. {
  10416. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10417. if(outfile == NULL)
  10418. {
  10419. DEBUG_INFO("Error opening file\n");
  10420. return FALSE;
  10421. }
  10422. /*Core Profile*/
  10423. //AllowOfflineTxForUnknownId
  10424. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10425. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10426. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  10427. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10428. //AuthorizationCacheEnabled
  10429. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10430. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10431. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10432. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10433. //AuthorizeRemoteTxRequests
  10434. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10435. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10436. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  10437. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10438. //BlinkRepeat
  10439. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10440. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10441. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10442. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10443. //ClockAlignedDataInterval
  10444. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10445. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10446. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10447. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10448. //ConnectionTimeOut
  10449. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10450. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10451. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10452. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10453. //GetConfigurationMaxKeys
  10454. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10455. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10456. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  10457. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10458. // HeartbeatInterval
  10459. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10460. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10461. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  10462. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10463. // LightIntensity
  10464. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10465. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10466. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10467. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10468. // LocalAuthorizeOffline
  10469. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  10470. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10471. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10472. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10473. // LocalPreAuthorize
  10474. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10475. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10476. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10477. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10478. // MaxEnergyOnInvalidId
  10479. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10480. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10481. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10482. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10483. // MeterValuesAlignedData
  10484. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10485. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10486. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10487. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10488. else
  10489. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10490. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10491. // MeterValuesAlignedDataMaxLength
  10492. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10493. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10494. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10495. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  10496. else
  10497. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "9" );
  10498. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10499. // MeterValuesSampledData
  10500. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10501. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10502. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10503. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10504. else
  10505. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10506. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10507. // MeterValuesSampledDataMaxLength
  10508. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10509. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10510. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10511. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  10512. else
  10513. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "9" );
  10514. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10515. // MeterValueSampleInterval
  10516. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10517. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10518. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  10519. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10520. // MinimumStatusDuration
  10521. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10522. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10523. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  10524. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  10525. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10526. // NumberOfConnectors
  10527. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10528. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10529. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10530. {
  10531. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10532. }
  10533. else
  10534. {
  10535. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10536. }
  10537. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10538. // ResetRetries
  10539. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10540. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10541. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10542. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10543. // ConnectorPhaseRotation
  10544. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10545. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10546. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10547. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10548. // ConnectorPhaseRotationMaxLength
  10549. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10550. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10551. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10552. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10553. // StopTransactionOnEVSideDisconnect
  10554. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10555. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10556. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10557. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10558. // StopTransactionOnInvalidId
  10559. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  10560. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10561. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10562. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10563. // StopTxnAlignedData
  10564. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  10565. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10566. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10567. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10568. // StopTxnAlignedDataMaxLength
  10569. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10570. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10571. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10572. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10573. // StopTxnSampledData
  10574. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10575. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10576. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10577. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10578. else
  10579. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10580. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10581. // StopTxnSampledDataMaxLength
  10582. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10583. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10584. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10585. {
  10586. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  10587. }
  10588. else
  10589. {
  10590. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  10591. }
  10592. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10593. // SupportedFeatureProfiles
  10594. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10595. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10596. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10597. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10598. // SupportedFeatureProfilesMaxLength
  10599. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10600. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10601. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10602. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10603. // TransactionMessageAttempts
  10604. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10605. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10606. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10607. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10608. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10609. // TransactionMessageRetryInterval
  10610. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10611. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10612. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10613. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10614. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10615. // UnlockConnectorOnEVSideDisconnect
  10616. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10617. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10618. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10619. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10620. // WebSocketPingInterval
  10621. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10622. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10623. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10624. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10625. // QueueOffLineStartTransactionMessage
  10626. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  10627. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10628. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10629. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10630. // AuthorizationKey
  10631. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  10632. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  10633. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "" );
  10634. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  10635. // SecurityProfile
  10636. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  10637. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  10638. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "0" );
  10639. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  10640. // DefaultPrice
  10641. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  10642. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  10643. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  10644. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  10645. // CustomDisplayCostAndPrice
  10646. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  10647. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  10648. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  10649. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  10650. // CustomIdleFeeAfterStop
  10651. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  10652. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  10653. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  10654. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  10655. // Configuration Version
  10656. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  10657. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  10658. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  10659. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  10660. //* Local Auth List Management Profile*/
  10661. #if 0
  10662. //For OCTT Test Case
  10663. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10664. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  10665. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10666. #endif
  10667. #if 1
  10668. //LocalAuthListEnabled
  10669. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10670. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10671. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10672. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10673. #endif
  10674. //LocalAuthListMaxLength
  10675. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10676. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10677. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10678. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10679. //SendLocalListMaxLength
  10680. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10681. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10682. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  10683. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10684. //ReserveConnectorZeroSupported
  10685. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10686. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10687. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10688. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10689. //* Smart Charging Profile */
  10690. //ChargeProfileMaxStackLevel
  10691. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10692. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10693. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10694. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10695. // ChargingScheduleAllowedChargingRateUnit
  10696. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10697. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10698. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10699. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10700. // ChargingScheduleMaxPeriods
  10701. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10702. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10703. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10704. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10705. // ConnectorSwitch3to1PhaseSupported
  10706. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10707. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10708. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10709. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10710. // MaxChargingProfilesInstalled
  10711. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10712. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10713. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  10714. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10715. fclose(outfile);
  10716. }
  10717. else
  10718. {
  10719. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10720. char keystr[60]={0};
  10721. char readonlystr[10]={0};
  10722. char valuestr[256]={0};
  10723. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10724. if(fp == NULL) {
  10725. DEBUG_INFO("Error opening file");
  10726. return FALSE;
  10727. }
  10728. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  10729. {
  10730. //DEBUG_INFO("Get Configuration \n");
  10731. if(strlen(str) > 0)
  10732. {
  10733. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10734. //*************************key*********************************/
  10735. if(strstr(str, "key") != NULL)
  10736. {
  10737. loc = strstr(str, "key");
  10738. c = 0;
  10739. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10740. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  10741. {
  10742. sstr[c] = loc[strlen("key")+3+c];
  10743. c++;
  10744. }
  10745. sstr[c] = '\0';
  10746. strcpy(keystr,sstr);
  10747. }
  10748. //*************************readonly*********************************/
  10749. if(strstr(str, "readonly") != NULL)
  10750. {
  10751. loc = strstr(str, "readonly");
  10752. c = 0;
  10753. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10754. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  10755. {
  10756. sstr[c] = loc[strlen("readonly")+2+c];
  10757. c++;
  10758. }
  10759. sstr[c] = '\0';
  10760. strcpy(readonlystr,sstr);
  10761. }
  10762. //*************************value*********************************/
  10763. if(strstr(str, "value") != NULL)
  10764. {
  10765. loc = strstr(str, "value");
  10766. c = 0;
  10767. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10768. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  10769. {
  10770. sstr[c] = loc[strlen("value")+3+c];
  10771. c++;
  10772. }
  10773. sstr[c] = '\0';
  10774. strcpy(valuestr,sstr);
  10775. }
  10776. // DEBUG_INFO("keystr=%s\n",keystr);
  10777. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10778. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10779. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10780. {
  10781. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10782. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10783. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10784. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10785. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10786. }
  10787. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10788. {
  10789. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10790. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10791. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10792. }
  10793. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10794. {
  10795. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10796. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10797. }
  10798. if(strcmp(keystr, "BlinkRepeat") == 0)
  10799. {
  10800. //Charger.BlinkRepeat = Integer.parseInt(value);
  10801. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10802. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10803. }
  10804. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10805. {
  10806. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10807. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10808. }
  10809. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10810. {
  10811. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10812. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10813. }
  10814. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10815. {
  10816. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10817. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  10818. }
  10819. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10820. {
  10821. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10822. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10823. HeartBeatWaitTime = atoi(valuestr);
  10824. }
  10825. if(strcmp(keystr, "LightIntensity") == 0)
  10826. {
  10827. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10828. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10829. }
  10830. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10831. {
  10832. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10833. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10834. }
  10835. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10836. {
  10837. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10838. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10839. }
  10840. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10841. {
  10842. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10843. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10844. }
  10845. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10846. {
  10847. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10848. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10849. }
  10850. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10851. {
  10852. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10853. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10854. }
  10855. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10856. {
  10857. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10858. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10859. }
  10860. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10861. {
  10862. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10863. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10864. }
  10865. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10866. {
  10867. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10868. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10869. }
  10870. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10871. {
  10872. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10873. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10874. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10875. }
  10876. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10877. {
  10878. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10879. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10880. }
  10881. if(strcmp(keystr, "ResetRetries") == 0)
  10882. {
  10883. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10884. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10885. }
  10886. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10887. {
  10888. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10889. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10890. }
  10891. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10892. {
  10893. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10894. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10895. }
  10896. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10897. {
  10898. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10899. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10900. }
  10901. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10902. {
  10903. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10904. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10905. }
  10906. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10907. {
  10908. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10909. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10910. }
  10911. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10912. {
  10913. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10914. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10915. }
  10916. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10917. {
  10918. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10919. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10920. }
  10921. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10922. {
  10923. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10924. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10925. }
  10926. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10927. {
  10928. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10929. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10930. }
  10931. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10932. {
  10933. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10934. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10935. }
  10936. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10937. {
  10938. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10939. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10940. TransactionMessageAttemptsValue = atoi(valuestr);
  10941. }
  10942. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10943. {
  10944. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10945. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10946. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10947. }
  10948. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10949. {
  10950. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10951. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10952. }
  10953. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10954. {
  10955. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10956. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10957. }
  10958. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  10959. {
  10960. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10961. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  10962. }
  10963. if(strcmp(keystr, "AuthorizationKey") == 0)
  10964. {
  10965. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10966. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  10967. }
  10968. if(strcmp(keystr, "SecurityProfile") == 0)
  10969. {
  10970. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10971. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  10972. }
  10973. if(strcmp(keystr, "DefaultPrice") == 0)
  10974. {
  10975. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10976. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  10977. }
  10978. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  10979. {
  10980. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10981. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  10982. }
  10983. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  10984. {
  10985. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10986. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  10987. }
  10988. if(strcmp(keystr, "ConfigurationVersion") == 0)
  10989. {
  10990. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10991. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  10992. }
  10993. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10994. {
  10995. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10996. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10997. }
  10998. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10999. {
  11000. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11001. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  11002. }
  11003. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  11004. {
  11005. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11006. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  11007. }
  11008. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  11009. {
  11010. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11011. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  11012. }
  11013. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  11014. {
  11015. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11016. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  11017. }
  11018. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  11019. {
  11020. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11021. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  11022. }
  11023. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  11024. {
  11025. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11026. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  11027. }
  11028. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  11029. {
  11030. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11031. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  11032. }
  11033. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  11034. {
  11035. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11036. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  11037. }
  11038. }
  11039. }
  11040. fclose(fp);
  11041. }
  11042. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  11043. {
  11044. return PASS;
  11045. }
  11046. else
  11047. {
  11048. return FAIL;
  11049. }
  11050. }
  11051. void StoreConfigurationTable(void)
  11052. {
  11053. FILE *outfile;
  11054. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  11055. if(outfile == NULL)
  11056. {
  11057. DEBUG_INFO("Error opening file");
  11058. return ;
  11059. }
  11060. /*Core Profile*/
  11061. //AllowOfflineTxForUnknownId
  11062. /*
  11063. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11064. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  11065. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11066. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  11067. */
  11068. //DEBUG_INFO("data=%s\n",data);
  11069. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11070. //AuthorizationCacheEnabled
  11071. /*
  11072. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11073. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11074. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11075. */
  11076. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11077. //AuthorizeRemoteTxRequests
  11078. /*
  11079. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11080. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11081. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  11082. */
  11083. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11084. //BlinkRepeat
  11085. /*
  11086. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11087. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11088. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11089. */
  11090. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11091. //ClockAlignedDataInterval
  11092. /*
  11093. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11094. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11095. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11096. */
  11097. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11098. //ConnectionTimeOut
  11099. /*
  11100. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11101. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11102. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11103. */
  11104. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11105. //GetConfigurationMaxKeys
  11106. /*
  11107. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11108. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11109. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  11110. */
  11111. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11112. // HeartbeatInterval
  11113. /*
  11114. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11115. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11116. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  11117. */
  11118. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11119. // LightIntensity
  11120. /*
  11121. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11122. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11123. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11124. */
  11125. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11126. // LocalAuthorizeOffline
  11127. /*
  11128. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  11129. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  11130. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  11131. */
  11132. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11133. // LocalPreAuthorize
  11134. /*
  11135. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  11136. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  11137. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  11138. */
  11139. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  11140. // MaxEnergyOnInvalidId
  11141. /*
  11142. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  11143. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  11144. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  11145. */
  11146. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  11147. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  11148. // MeterValuesAlignedData
  11149. /*
  11150. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  11151. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  11152. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  11153. */
  11154. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  11155. // MeterValuesAlignedDataMaxLength
  11156. /*
  11157. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  11158. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  11159. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  11160. */
  11161. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  11162. // MeterValuesSampledData
  11163. /*
  11164. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  11165. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  11166. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  11167. */
  11168. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  11169. // MeterValuesSampledDataMaxLength
  11170. /*
  11171. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  11172. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  11173. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  11174. */
  11175. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  11176. // MeterValueSampleInterval
  11177. /*
  11178. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  11179. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  11180. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  11181. */
  11182. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  11183. // MinimumStatusDuration
  11184. /*
  11185. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  11186. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  11187. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  11188. */
  11189. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  11190. // NumberOfConnectors
  11191. /*
  11192. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  11193. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  11194. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11195. {
  11196. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  11197. }
  11198. else
  11199. {
  11200. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  11201. }
  11202. */
  11203. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  11204. // ResetRetries
  11205. /*
  11206. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  11207. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  11208. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  11209. */
  11210. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  11211. // ConnectorPhaseRotation
  11212. /*
  11213. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  11214. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  11215. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  11216. */
  11217. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  11218. // ConnectorPhaseRotationMaxLength
  11219. /*
  11220. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  11221. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  11222. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  11223. */
  11224. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  11225. // StopTransactionOnEVSideDisconnect
  11226. /*
  11227. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  11228. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  11229. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  11230. */
  11231. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  11232. // StopTransactionOnInvalidId
  11233. /*
  11234. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  11235. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  11236. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  11237. */
  11238. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  11239. // StopTxnAlignedData
  11240. /*
  11241. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  11242. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  11243. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  11244. */
  11245. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  11246. // StopTxnAlignedDataMaxLength
  11247. /*
  11248. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  11249. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  11250. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  11251. */
  11252. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  11253. // StopTxnSampledData
  11254. /*
  11255. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  11256. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  11257. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  11258. */
  11259. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  11260. // StopTxnSampledDataMaxLength
  11261. /*
  11262. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  11263. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  11264. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  11265. */
  11266. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  11267. // SupportedFeatureProfiles
  11268. /*
  11269. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  11270. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  11271. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  11272. */
  11273. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  11274. // SupportedFeatureProfilesMaxLength
  11275. /*
  11276. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  11277. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  11278. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  11279. */
  11280. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  11281. // TransactionMessageAttempts
  11282. /*
  11283. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  11284. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  11285. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  11286. */
  11287. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11288. // TransactionMessageRetryInterval
  11289. /*
  11290. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  11291. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  11292. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  11293. */
  11294. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11295. // UnlockConnectorOnEVSideDisconnect
  11296. /*
  11297. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  11298. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  11299. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  11300. */
  11301. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  11302. // WebSocketPingInterval
  11303. /*
  11304. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  11305. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  11306. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  11307. */
  11308. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  11309. // QueueOffLineStartTransactionMessage
  11310. /*
  11311. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  11312. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  11313. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  11314. */
  11315. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  11316. // AuthorizationKey
  11317. /*
  11318. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  11319. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  11320. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  11321. */
  11322. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  11323. // SecurityProfile
  11324. /*
  11325. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  11326. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  11327. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  11328. */
  11329. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  11330. // DefaultPrice
  11331. /*
  11332. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  11333. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  11334. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  11335. */
  11336. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  11337. // CustomDisplayCostAndPrice
  11338. /*
  11339. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  11340. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  11341. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  11342. */
  11343. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  11344. // CustomIdleFeeAfterStop
  11345. /*
  11346. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  11347. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  11348. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  11349. */
  11350. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  11351. // ConfigurationVersion
  11352. /*
  11353. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  11354. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  11355. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  11356. */
  11357. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  11358. //* Local Auth List Management Profile*/
  11359. //LocalAuthListEnabled
  11360. /*
  11361. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11362. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  11363. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11364. */
  11365. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11366. //LocalAuthListMaxLength
  11367. /*
  11368. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  11369. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  11370. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  11371. */
  11372. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  11373. //SendLocalListMaxLength
  11374. /*
  11375. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  11376. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  11377. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  11378. */
  11379. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  11380. //ReserveConnectorZeroSupported
  11381. /*
  11382. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  11383. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  11384. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  11385. */
  11386. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11387. //* Smart Charging Profile */
  11388. //ChargeProfileMaxStackLevel
  11389. /*
  11390. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  11391. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  11392. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  11393. */
  11394. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11395. // ChargingScheduleAllowedChargingRateUnit
  11396. /*
  11397. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  11398. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  11399. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  11400. */
  11401. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11402. // ChargingScheduleMaxPeriods
  11403. /*
  11404. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  11405. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  11406. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  11407. */
  11408. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11409. // ConnectorSwitch3to1PhaseSupported
  11410. /*
  11411. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11412. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11413. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  11414. */
  11415. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11416. // MaxChargingProfilesInstalled
  11417. /*
  11418. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11419. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11420. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  11421. */
  11422. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11423. fclose(outfile);
  11424. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11425. }
  11426. void getKeyValue(char *keyReq)
  11427. {
  11428. int isEmpty = FALSE;
  11429. int isKnowKey = FALSE;
  11430. DEBUG_INFO("keyReq = %s\n", keyReq);
  11431. if((keyReq == NULL) || (strlen(keyReq) == 0))
  11432. isEmpty = TRUE;
  11433. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  11434. {
  11435. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  11436. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  11437. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11438. {
  11439. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  11440. }
  11441. else
  11442. {
  11443. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  11444. }
  11445. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  11446. isKnowKey = TRUE;
  11447. }
  11448. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  11449. {
  11450. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  11451. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  11452. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11453. {
  11454. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  11455. }
  11456. else
  11457. {
  11458. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  11459. }
  11460. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  11461. isKnowKey = TRUE;
  11462. }
  11463. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  11464. {
  11465. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  11466. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  11467. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11468. {
  11469. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  11470. }
  11471. else
  11472. {
  11473. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  11474. }
  11475. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  11476. isKnowKey = TRUE;
  11477. }
  11478. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  11479. {
  11480. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  11481. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  11482. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11483. {
  11484. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  11485. }
  11486. else
  11487. {
  11488. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  11489. }
  11490. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  11491. isKnowKey = TRUE;
  11492. }
  11493. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  11494. {
  11495. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  11496. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  11497. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11498. {
  11499. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  11500. }
  11501. else
  11502. {
  11503. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  11504. }
  11505. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  11506. isKnowKey = TRUE;
  11507. }
  11508. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  11509. {
  11510. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  11511. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  11512. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11513. {
  11514. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  11515. }
  11516. else
  11517. {
  11518. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  11519. }
  11520. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  11521. isKnowKey = TRUE;
  11522. }
  11523. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  11524. {
  11525. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  11526. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  11527. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11528. {
  11529. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  11530. }
  11531. else
  11532. {
  11533. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  11534. }
  11535. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  11536. isKnowKey = TRUE;
  11537. }
  11538. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  11539. {
  11540. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  11541. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  11542. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11543. {
  11544. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  11545. }
  11546. else
  11547. {
  11548. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  11549. }
  11550. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  11551. isKnowKey = TRUE;
  11552. }
  11553. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  11554. {
  11555. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  11556. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  11557. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11558. {
  11559. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  11560. }
  11561. else
  11562. {
  11563. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  11564. }
  11565. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  11566. isKnowKey = TRUE;
  11567. }
  11568. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  11569. {
  11570. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  11571. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  11572. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11573. {
  11574. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  11575. }
  11576. else
  11577. {
  11578. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  11579. }
  11580. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  11581. isKnowKey = TRUE;
  11582. }
  11583. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  11584. {
  11585. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  11586. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  11587. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11588. {
  11589. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  11590. }
  11591. else
  11592. {
  11593. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  11594. }
  11595. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  11596. isKnowKey = TRUE;
  11597. }
  11598. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  11599. {
  11600. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  11601. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  11602. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11603. {
  11604. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11605. }
  11606. else
  11607. {
  11608. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11609. }
  11610. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  11611. isKnowKey = TRUE;
  11612. }
  11613. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  11614. {
  11615. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  11616. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  11617. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11618. {
  11619. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11620. }
  11621. else
  11622. {
  11623. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11624. }
  11625. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  11626. isKnowKey = TRUE;
  11627. }
  11628. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  11629. {
  11630. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  11631. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  11632. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11633. {
  11634. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11635. }
  11636. else
  11637. {
  11638. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11639. }
  11640. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  11641. isKnowKey = TRUE;
  11642. }
  11643. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  11644. {
  11645. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  11646. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  11647. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11648. {
  11649. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  11650. }
  11651. else
  11652. {
  11653. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  11654. }
  11655. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  11656. isKnowKey = TRUE;
  11657. }
  11658. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  11659. {
  11660. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  11661. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  11662. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11663. {
  11664. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11665. }
  11666. else
  11667. {
  11668. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11669. }
  11670. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  11671. isKnowKey = TRUE;
  11672. }
  11673. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  11674. {
  11675. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  11676. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  11677. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11678. {
  11679. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  11680. }
  11681. else
  11682. {
  11683. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  11684. }
  11685. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  11686. isKnowKey = TRUE;
  11687. }
  11688. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  11689. {
  11690. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  11691. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  11692. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11693. {
  11694. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  11695. }
  11696. else
  11697. {
  11698. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  11699. }
  11700. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  11701. isKnowKey = TRUE;
  11702. }
  11703. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  11704. {
  11705. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  11706. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  11707. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11708. {
  11709. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  11710. }
  11711. else
  11712. {
  11713. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  11714. }
  11715. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  11716. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  11717. isKnowKey = TRUE;
  11718. }
  11719. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  11720. {
  11721. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  11722. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11723. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11724. {
  11725. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11726. }
  11727. else
  11728. {
  11729. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11730. }
  11731. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11732. isKnowKey = TRUE;
  11733. }
  11734. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11735. {
  11736. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11737. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11738. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11739. {
  11740. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11741. }
  11742. else
  11743. {
  11744. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11745. }
  11746. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11747. isKnowKey = TRUE;
  11748. }
  11749. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11750. {
  11751. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11752. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11753. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11754. {
  11755. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11756. }
  11757. else
  11758. {
  11759. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11760. }
  11761. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11762. isKnowKey = TRUE;
  11763. }
  11764. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11765. {
  11766. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11767. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11768. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11769. {
  11770. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11771. }
  11772. else
  11773. {
  11774. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11775. }
  11776. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11777. isKnowKey = TRUE;
  11778. }
  11779. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11780. {
  11781. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11782. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11783. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11784. {
  11785. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11786. }
  11787. else
  11788. {
  11789. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11790. }
  11791. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11792. isKnowKey = TRUE;
  11793. }
  11794. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11795. {
  11796. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11797. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11798. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11799. {
  11800. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11801. }
  11802. else
  11803. {
  11804. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11805. }
  11806. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11807. isKnowKey = TRUE;
  11808. }
  11809. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11810. {
  11811. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11812. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11813. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11814. {
  11815. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11816. }
  11817. else
  11818. {
  11819. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11820. }
  11821. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11822. isKnowKey = TRUE;
  11823. }
  11824. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11825. {
  11826. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11827. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11828. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11829. {
  11830. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11831. }
  11832. else
  11833. {
  11834. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11835. }
  11836. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11837. isKnowKey = TRUE;
  11838. }
  11839. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11840. {
  11841. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11842. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11843. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11844. {
  11845. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11846. }
  11847. else
  11848. {
  11849. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11850. }
  11851. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11852. isKnowKey = TRUE;
  11853. }
  11854. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11855. {
  11856. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11857. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11858. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11859. {
  11860. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11861. }
  11862. else
  11863. {
  11864. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11865. }
  11866. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11867. isKnowKey = TRUE;
  11868. }
  11869. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11870. {
  11871. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11872. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11873. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11874. {
  11875. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11876. }
  11877. else
  11878. {
  11879. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11880. }
  11881. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11882. isKnowKey = TRUE;
  11883. }
  11884. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11885. {
  11886. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11887. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11888. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11889. {
  11890. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11891. }
  11892. else
  11893. {
  11894. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11895. }
  11896. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11897. isKnowKey = TRUE;
  11898. }
  11899. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11900. {
  11901. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11902. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11903. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11904. {
  11905. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11906. }
  11907. else
  11908. {
  11909. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11910. }
  11911. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11912. isKnowKey = TRUE;
  11913. }
  11914. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11915. {
  11916. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11917. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11918. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11919. {
  11920. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11921. }
  11922. else
  11923. {
  11924. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11925. }
  11926. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11927. isKnowKey = TRUE;
  11928. }
  11929. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11930. {
  11931. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11932. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11933. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11934. {
  11935. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11936. }
  11937. else
  11938. {
  11939. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11940. }
  11941. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11942. isKnowKey = TRUE;
  11943. }
  11944. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  11945. {
  11946. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  11947. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  11948. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  11949. {
  11950. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  11951. }
  11952. else
  11953. {
  11954. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  11955. }
  11956. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  11957. isKnowKey = TRUE;
  11958. }
  11959. /*
  11960. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  11961. {
  11962. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  11963. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  11964. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  11965. {
  11966. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  11967. }
  11968. else
  11969. {
  11970. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  11971. }
  11972. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  11973. isKnowKey = TRUE;
  11974. }*/
  11975. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  11976. {
  11977. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  11978. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  11979. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  11980. {
  11981. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  11982. }
  11983. else
  11984. {
  11985. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  11986. }
  11987. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  11988. isKnowKey = TRUE;
  11989. }
  11990. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  11991. {
  11992. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  11993. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  11994. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  11995. {
  11996. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  11997. }
  11998. else
  11999. {
  12000. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  12001. }
  12002. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  12003. isKnowKey = TRUE;
  12004. }
  12005. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  12006. {
  12007. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  12008. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  12009. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  12010. {
  12011. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  12012. }
  12013. else
  12014. {
  12015. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  12016. }
  12017. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  12018. isKnowKey = TRUE;
  12019. }
  12020. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  12021. {
  12022. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  12023. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  12024. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  12025. {
  12026. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  12027. }
  12028. else
  12029. {
  12030. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  12031. }
  12032. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  12033. isKnowKey = TRUE;
  12034. }
  12035. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  12036. {
  12037. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  12038. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  12039. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  12040. {
  12041. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  12042. }
  12043. else
  12044. {
  12045. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  12046. }
  12047. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  12048. isKnowKey = TRUE;
  12049. }
  12050. #if 1
  12051. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  12052. {
  12053. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  12054. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  12055. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12056. {
  12057. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  12058. }
  12059. else
  12060. {
  12061. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  12062. }
  12063. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  12064. isKnowKey = TRUE;
  12065. }
  12066. #endif
  12067. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  12068. {
  12069. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  12070. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  12071. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12072. {
  12073. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12074. }
  12075. else
  12076. {
  12077. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12078. }
  12079. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  12080. isKnowKey = TRUE;
  12081. }
  12082. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  12083. {
  12084. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  12085. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  12086. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12087. {
  12088. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12089. }
  12090. else
  12091. {
  12092. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12093. }
  12094. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  12095. isKnowKey = TRUE;
  12096. }
  12097. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  12098. {
  12099. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  12100. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  12101. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12102. {
  12103. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  12104. }
  12105. else
  12106. {
  12107. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  12108. }
  12109. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12110. isKnowKey = TRUE;
  12111. }
  12112. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  12113. {
  12114. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  12115. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  12116. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12117. {
  12118. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  12119. }
  12120. else
  12121. {
  12122. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  12123. }
  12124. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12125. isKnowKey = TRUE;
  12126. }
  12127. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  12128. {
  12129. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  12130. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  12131. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12132. {
  12133. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  12134. }
  12135. else
  12136. {
  12137. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  12138. }
  12139. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12140. isKnowKey = TRUE;
  12141. }
  12142. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  12143. {
  12144. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  12145. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  12146. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12147. {
  12148. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  12149. }
  12150. else
  12151. {
  12152. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  12153. }
  12154. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12155. isKnowKey = TRUE;
  12156. }
  12157. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  12158. {
  12159. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  12160. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  12161. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12162. {
  12163. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  12164. }
  12165. else
  12166. {
  12167. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  12168. }
  12169. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12170. isKnowKey = TRUE;
  12171. }
  12172. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  12173. {
  12174. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  12175. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  12176. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12177. {
  12178. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  12179. }
  12180. else
  12181. {
  12182. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  12183. }
  12184. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12185. isKnowKey = TRUE;
  12186. }
  12187. //=========================================================
  12188. if(!isEmpty && !isKnowKey)
  12189. {
  12190. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  12191. strcpy(unknownkey[UnknownKeynum], keyReq);
  12192. UnknownKeynum = UnknownKeynum + 1;
  12193. }
  12194. }
  12195. void processUnkownKey(void)
  12196. {
  12197. DEBUG_INFO("processUnkownKey...\n");
  12198. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  12199. for(int index=0; index < UnknownKeynum; index++)
  12200. {
  12201. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  12202. {
  12203. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  12204. }
  12205. }
  12206. }
  12207. int setKeyValue(char *key, char *value)
  12208. {
  12209. int isSuccess = NotSupported;
  12210. int check_ascii=0;
  12211. char str[256]={0};
  12212. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  12213. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  12214. {
  12215. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  12216. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  12217. {
  12218. strcpy(str, (const char*)value);
  12219. for(int i = 0; str[i]; i++){
  12220. str[i] = tolower(str[i]);
  12221. }
  12222. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12223. isSuccess = ConfigurationStatus_Accepted;
  12224. }
  12225. else
  12226. {
  12227. isSuccess = ConfigurationStatus_Rejected;
  12228. }
  12229. }
  12230. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  12231. {
  12232. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  12233. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  12234. {
  12235. strcpy(str, (const char*)value);
  12236. for(int i = 0; str[i]; i++){
  12237. str[i] = tolower(str[i]);
  12238. }
  12239. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12240. isSuccess = ConfigurationStatus_Accepted;
  12241. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  12242. }
  12243. else
  12244. {
  12245. isSuccess = ConfigurationStatus_Rejected;
  12246. }
  12247. }
  12248. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  12249. {
  12250. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  12251. {
  12252. strcpy(str, (const char*)value);
  12253. for(int i = 0; str[i]; i++)
  12254. {
  12255. str[i] = tolower(str[i]);
  12256. }
  12257. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  12258. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12259. isSuccess = ConfigurationStatus_Accepted;
  12260. }
  12261. else
  12262. {
  12263. isSuccess = ConfigurationStatus_Rejected;
  12264. }
  12265. }
  12266. if(strcmp(key, "BlinkRepeat") == 0)
  12267. {
  12268. //Charger.BlinkRepeat = Integer.parseInt(value);
  12269. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  12270. {
  12271. check_ascii = value[0];
  12272. if( (check_ascii < 48) || (check_ascii > 57) )
  12273. {
  12274. isSuccess = ConfigurationStatus_Rejected;
  12275. }
  12276. else
  12277. {
  12278. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  12279. isSuccess = ConfigurationStatus_Accepted;
  12280. }
  12281. }
  12282. else
  12283. {
  12284. isSuccess = ConfigurationStatus_Rejected;
  12285. }
  12286. }
  12287. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  12288. {
  12289. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  12290. {
  12291. check_ascii = value[0];
  12292. if( (check_ascii < 48) || (check_ascii > 57) )
  12293. {
  12294. isSuccess = ConfigurationStatus_Rejected;
  12295. }
  12296. else
  12297. {
  12298. if((atoi(value) == 0) || (atoi(value) >= 10))
  12299. {
  12300. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  12301. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  12302. isSuccess = ConfigurationStatus_Accepted;
  12303. }
  12304. else
  12305. isSuccess = ConfigurationStatus_Rejected;
  12306. }
  12307. }
  12308. else
  12309. {
  12310. isSuccess = ConfigurationStatus_Rejected;
  12311. }
  12312. }
  12313. if(strcmp(key, "ConnectionTimeOut") == 0 )
  12314. {
  12315. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  12316. {
  12317. check_ascii = value[0];
  12318. if( (check_ascii < 48) || (check_ascii > 57) )
  12319. {
  12320. isSuccess = ConfigurationStatus_Rejected;
  12321. }
  12322. else
  12323. {
  12324. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  12325. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  12326. isSuccess = ConfigurationStatus_Accepted;
  12327. }
  12328. }
  12329. else
  12330. {
  12331. isSuccess = ConfigurationStatus_Rejected;
  12332. }
  12333. }
  12334. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  12335. {
  12336. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  12337. {
  12338. check_ascii = value[0];
  12339. if( (check_ascii < 48) || (check_ascii > 57) )
  12340. {
  12341. isSuccess = ConfigurationStatus_Rejected;
  12342. }
  12343. else
  12344. {
  12345. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  12346. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  12347. isSuccess = ConfigurationStatus_Accepted;
  12348. }
  12349. }
  12350. else
  12351. {
  12352. isSuccess = ConfigurationStatus_Rejected;
  12353. }
  12354. }
  12355. if(strcmp(key, "HeartbeatInterval") == 0)
  12356. {
  12357. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  12358. {
  12359. check_ascii = value[0];
  12360. if( (check_ascii < 48) || (check_ascii > 57) )
  12361. {
  12362. isSuccess = ConfigurationStatus_Rejected;
  12363. }
  12364. else
  12365. {
  12366. if((atoi(value) == 0) || (atoi(value) >= 10))
  12367. {
  12368. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  12369. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  12370. HeartBeatWaitTime = atoi(value);
  12371. isSuccess = ConfigurationStatus_Accepted;
  12372. }
  12373. else
  12374. {
  12375. isSuccess = ConfigurationStatus_Rejected;
  12376. }
  12377. }
  12378. }
  12379. else
  12380. {
  12381. isSuccess = ConfigurationStatus_Rejected;
  12382. }
  12383. }
  12384. if(strcmp(key, "LightIntensity") == 0)
  12385. {
  12386. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  12387. {
  12388. check_ascii = value[0];
  12389. if( (check_ascii < 48) || (check_ascii > 57) )
  12390. {
  12391. isSuccess = ConfigurationStatus_Rejected;
  12392. }
  12393. else
  12394. {
  12395. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  12396. isSuccess = ConfigurationStatus_Accepted;
  12397. }
  12398. }
  12399. else
  12400. {
  12401. isSuccess = ConfigurationStatus_Rejected;
  12402. }
  12403. }
  12404. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  12405. {
  12406. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  12407. {
  12408. strcpy(str, (const char*)value);
  12409. for(int i = 0; str[i]; i++)
  12410. {
  12411. str[i] = tolower(str[i]);
  12412. }
  12413. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12414. isSuccess = ConfigurationStatus_Accepted;
  12415. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12416. }
  12417. else
  12418. {
  12419. isSuccess = ConfigurationStatus_Rejected;
  12420. }
  12421. }
  12422. if(strcmp(key, "LocalPreAuthorize") == 0)
  12423. {
  12424. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  12425. {
  12426. strcpy(str, (const char*)value);
  12427. for(int i = 0; str[i]; i++)
  12428. {
  12429. str[i] = tolower(str[i]);
  12430. }
  12431. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12432. isSuccess = ConfigurationStatus_Accepted;
  12433. }
  12434. else
  12435. {
  12436. isSuccess = ConfigurationStatus_Rejected;
  12437. }
  12438. }
  12439. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  12440. {
  12441. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  12442. {
  12443. check_ascii = value[0];
  12444. if( (check_ascii < 48) || (check_ascii > 57) )
  12445. {
  12446. isSuccess = ConfigurationStatus_Rejected;
  12447. }
  12448. else
  12449. {
  12450. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  12451. isSuccess = ConfigurationStatus_Accepted;
  12452. }
  12453. }
  12454. else
  12455. {
  12456. isSuccess = ConfigurationStatus_Rejected;
  12457. }
  12458. }
  12459. if(strcmp(key, "MeterValuesAlignedData") == 0)
  12460. {
  12461. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  12462. {
  12463. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  12464. isSuccess = ConfigurationStatus_Accepted;
  12465. }
  12466. else
  12467. {
  12468. isSuccess = ConfigurationStatus_Rejected;
  12469. }
  12470. }
  12471. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  12472. {
  12473. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  12474. {
  12475. check_ascii = value[0];
  12476. if( (check_ascii < 48) || (check_ascii > 57) )
  12477. {
  12478. isSuccess = ConfigurationStatus_Rejected;
  12479. }
  12480. else
  12481. {
  12482. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12483. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  12484. isSuccess = ConfigurationStatus_Accepted;
  12485. }
  12486. }
  12487. else
  12488. {
  12489. isSuccess = ConfigurationStatus_Rejected;
  12490. }
  12491. }
  12492. if(strcmp(key, "MeterValuesSampledData") == 0 )
  12493. {
  12494. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  12495. {
  12496. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  12497. isSuccess = ConfigurationStatus_Accepted;
  12498. }
  12499. else
  12500. {
  12501. isSuccess = ConfigurationStatus_Rejected;
  12502. }
  12503. }
  12504. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  12505. {
  12506. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  12507. {
  12508. check_ascii = value[0];
  12509. if( (check_ascii < 48) || (check_ascii > 57) )
  12510. {
  12511. isSuccess = ConfigurationStatus_Rejected;
  12512. }
  12513. else
  12514. {
  12515. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12516. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  12517. isSuccess = ConfigurationStatus_Accepted;
  12518. }
  12519. }
  12520. else
  12521. {
  12522. isSuccess = ConfigurationStatus_Rejected;
  12523. }
  12524. }
  12525. if(strcmp(key, "MeterValueSampleInterval") == 0)
  12526. {
  12527. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12528. {
  12529. check_ascii = value[0];
  12530. if( (check_ascii < 48) || (check_ascii > 57) )
  12531. {
  12532. isSuccess = ConfigurationStatus_Rejected;
  12533. }
  12534. else
  12535. {
  12536. if((atoi(value) == 0) || (atoi(value) >= 10))
  12537. {
  12538. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12539. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  12540. isSuccess = ConfigurationStatus_Accepted;
  12541. }
  12542. else
  12543. {
  12544. isSuccess = ConfigurationStatus_Rejected;
  12545. }
  12546. }
  12547. }
  12548. else
  12549. {
  12550. isSuccess = ConfigurationStatus_Rejected;
  12551. }
  12552. }
  12553. if(strcmp(key, "MinimumStatusDuration") == 0)
  12554. {
  12555. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12556. {
  12557. check_ascii = value[0];
  12558. if( (check_ascii < 48) || (check_ascii > 57) )
  12559. {
  12560. isSuccess = ConfigurationStatus_Rejected;
  12561. }
  12562. else
  12563. {
  12564. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  12565. {
  12566. isSuccess = ConfigurationStatus_Rejected;
  12567. }
  12568. else
  12569. {
  12570. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  12571. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  12572. server_cycle_Status = atoi(value); //StatusNotification Cycle
  12573. isSuccess = ConfigurationStatus_Accepted;
  12574. }
  12575. }
  12576. }
  12577. else
  12578. {
  12579. isSuccess = ConfigurationStatus_Rejected;
  12580. }
  12581. }
  12582. if(strcmp(key, "NumberOfConnectors") == 0)
  12583. {
  12584. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12585. {
  12586. check_ascii = value[0];
  12587. if( (check_ascii < 48) || (check_ascii > 57) )
  12588. {
  12589. isSuccess = ConfigurationStatus_Rejected;
  12590. }
  12591. else
  12592. {
  12593. //Charger.ResetRetries = Integer.parseInt(value);
  12594. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  12595. isSuccess = ConfigurationStatus_Accepted;
  12596. }
  12597. }
  12598. else
  12599. {
  12600. isSuccess = ConfigurationStatus_Rejected;
  12601. }
  12602. }
  12603. if(strcmp(key, "ResetRetries") == 0)
  12604. {
  12605. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12606. {
  12607. check_ascii = value[0];
  12608. if( (check_ascii < 48) || (check_ascii > 57) )
  12609. {
  12610. isSuccess = ConfigurationStatus_Rejected;
  12611. }
  12612. else
  12613. {
  12614. //Charger.ResetRetries = Integer.parseInt(value);
  12615. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  12616. isSuccess = ConfigurationStatus_Accepted;
  12617. }
  12618. }
  12619. else
  12620. {
  12621. isSuccess = ConfigurationStatus_Rejected;
  12622. }
  12623. }
  12624. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  12625. {
  12626. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12627. {
  12628. strcpy(str, (const char*)value);
  12629. for(int i = 0; str[i]; i++)
  12630. {
  12631. str[i] = tolower(str[i]);
  12632. }
  12633. if(strcmp(str, "notapplicable")== 0)
  12634. {
  12635. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  12636. isSuccess = ConfigurationStatus_Accepted;
  12637. }
  12638. else if(strcmp(str, "unknown")== 0)
  12639. {
  12640. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  12641. isSuccess = ConfigurationStatus_Accepted;
  12642. }
  12643. else if(strcmp(str, "rst")== 0)
  12644. {
  12645. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  12646. isSuccess = ConfigurationStatus_Accepted;
  12647. }
  12648. else if(strcmp(str, "rts")== 0)
  12649. {
  12650. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  12651. isSuccess = ConfigurationStatus_Accepted;
  12652. }
  12653. else if(strcmp(str, "srt")== 0)
  12654. {
  12655. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  12656. isSuccess = ConfigurationStatus_Accepted;
  12657. }
  12658. else if(strcmp(str, "str")== 0)
  12659. {
  12660. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  12661. isSuccess = ConfigurationStatus_Accepted;
  12662. }
  12663. else if(strcmp(str, "trs")== 0)
  12664. {
  12665. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  12666. isSuccess = ConfigurationStatus_Accepted;
  12667. }
  12668. else if(strcmp(str, "tsr")== 0)
  12669. {
  12670. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  12671. isSuccess = ConfigurationStatus_Accepted;
  12672. }
  12673. else
  12674. {
  12675. isSuccess = ConfigurationStatus_Rejected;
  12676. }
  12677. }
  12678. else
  12679. {
  12680. isSuccess = ConfigurationStatus_Rejected;
  12681. }
  12682. }
  12683. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  12684. {
  12685. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12686. {
  12687. check_ascii = value[0];
  12688. if( (check_ascii < 48) || (check_ascii > 57) )
  12689. {
  12690. isSuccess = ConfigurationStatus_Rejected;
  12691. }
  12692. else
  12693. {
  12694. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  12695. isSuccess = ConfigurationStatus_Accepted;
  12696. }
  12697. }
  12698. else
  12699. {
  12700. isSuccess = ConfigurationStatus_Rejected;
  12701. }
  12702. }
  12703. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  12704. {
  12705. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12706. {
  12707. strcpy(str, (const char*)value);
  12708. for(int i = 0; str[i]; i++)
  12709. {
  12710. str[i] = tolower(str[i]);
  12711. }
  12712. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12713. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12714. isSuccess = ConfigurationStatus_Accepted;
  12715. }
  12716. else
  12717. {
  12718. isSuccess = ConfigurationStatus_Rejected;
  12719. }
  12720. }
  12721. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  12722. {
  12723. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12724. {
  12725. strcpy(str, (const char*)value);
  12726. for(int i = 0; str[i]; i++)
  12727. {
  12728. str[i] = tolower(str[i]);
  12729. }
  12730. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  12731. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12732. isSuccess = ConfigurationStatus_Accepted;
  12733. }
  12734. else
  12735. {
  12736. isSuccess = ConfigurationStatus_Rejected;
  12737. }
  12738. }
  12739. if(strcmp(key, "StopTxnAlignedData") == 0)
  12740. {
  12741. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12742. {
  12743. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  12744. isSuccess = ConfigurationStatus_Accepted;
  12745. }
  12746. else
  12747. {
  12748. isSuccess = ConfigurationStatus_Rejected;
  12749. }
  12750. }
  12751. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  12752. {
  12753. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12754. {
  12755. check_ascii = value[0];
  12756. if( (check_ascii < 48) || (check_ascii > 57) )
  12757. {
  12758. isSuccess = ConfigurationStatus_Rejected;
  12759. }
  12760. else
  12761. {
  12762. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  12763. isSuccess = ConfigurationStatus_Accepted;
  12764. }
  12765. }
  12766. else
  12767. {
  12768. isSuccess = ConfigurationStatus_Rejected;
  12769. }
  12770. }
  12771. if(strcmp(key, "StopTxnSampledData") == 0)
  12772. {
  12773. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12774. {
  12775. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  12776. isSuccess = ConfigurationStatus_Accepted;
  12777. }
  12778. else
  12779. {
  12780. isSuccess = ConfigurationStatus_Rejected;
  12781. }
  12782. }
  12783. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  12784. {
  12785. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12786. {
  12787. check_ascii = value[0];
  12788. if( (check_ascii < 48) || (check_ascii > 57) )
  12789. {
  12790. isSuccess = ConfigurationStatus_Rejected;
  12791. }
  12792. else
  12793. {
  12794. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  12795. isSuccess = ConfigurationStatus_Accepted;
  12796. }
  12797. }
  12798. else
  12799. {
  12800. isSuccess = ConfigurationStatus_Rejected;
  12801. }
  12802. }
  12803. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  12804. {
  12805. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12806. {
  12807. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  12808. isSuccess = ConfigurationStatus_Accepted;
  12809. }
  12810. else
  12811. {
  12812. isSuccess = ConfigurationStatus_Rejected;
  12813. }
  12814. }
  12815. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  12816. {
  12817. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12818. {
  12819. check_ascii = value[0];
  12820. if( (check_ascii < 48) || (check_ascii > 57) )
  12821. {
  12822. isSuccess = ConfigurationStatus_Rejected;
  12823. }
  12824. else
  12825. {
  12826. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  12827. isSuccess = ConfigurationStatus_Accepted;
  12828. }
  12829. }
  12830. else
  12831. {
  12832. isSuccess = ConfigurationStatus_Rejected;
  12833. }
  12834. }
  12835. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12836. {
  12837. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12838. {
  12839. check_ascii = value[0];
  12840. if( (check_ascii < 48) || (check_ascii > 57) )
  12841. {
  12842. isSuccess = ConfigurationStatus_Rejected;
  12843. }
  12844. else
  12845. {
  12846. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12847. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12848. TransactionMessageAttemptsValue = atoi(value);
  12849. isSuccess = ConfigurationStatus_Accepted;
  12850. }
  12851. }
  12852. else
  12853. {
  12854. isSuccess = ConfigurationStatus_Rejected;
  12855. }
  12856. }
  12857. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12858. {
  12859. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].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. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12869. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12870. TransactionMessageRetryIntervalValue = atoi(value);
  12871. isSuccess = ConfigurationStatus_Accepted;
  12872. }
  12873. }
  12874. else
  12875. {
  12876. isSuccess = ConfigurationStatus_Rejected;
  12877. }
  12878. }
  12879. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12880. {
  12881. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12882. {
  12883. strcpy(str, (const char*)value);
  12884. for(int i = 0; str[i]; i++)
  12885. {
  12886. str[i] = tolower(str[i]);
  12887. }
  12888. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12889. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12890. isSuccess = ConfigurationStatus_Accepted;
  12891. }
  12892. else
  12893. {
  12894. isSuccess = ConfigurationStatus_Rejected;
  12895. }
  12896. }
  12897. if(strcmp(key, "WebSocketPingInterval") == 0)
  12898. {
  12899. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12900. {
  12901. check_ascii = value[0];
  12902. if( (check_ascii < 48) || (check_ascii > 57) )
  12903. {
  12904. isSuccess = ConfigurationStatus_Rejected;
  12905. }
  12906. else
  12907. {
  12908. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12909. isSuccess = ConfigurationStatus_Accepted;
  12910. }
  12911. }
  12912. else
  12913. {
  12914. isSuccess = ConfigurationStatus_Rejected;
  12915. }
  12916. }
  12917. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  12918. {
  12919. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12920. {
  12921. strcpy(str, (const char*)value);
  12922. for(int i = 0; str[i]; i++)
  12923. {
  12924. str[i] = tolower(str[i]);
  12925. }
  12926. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12927. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12928. isSuccess = ConfigurationStatus_Accepted;
  12929. }
  12930. else
  12931. {
  12932. isSuccess = ConfigurationStatus_Rejected;
  12933. }
  12934. }
  12935. if(strcmp(key, "AuthorizationKey") == 0)
  12936. {
  12937. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  12938. {
  12939. strcpy(str, (const char*)value);
  12940. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  12941. isSuccess = ConfigurationStatus_Accepted;
  12942. }
  12943. else
  12944. {
  12945. isSuccess = ConfigurationStatus_Rejected;
  12946. }
  12947. }
  12948. if(strcmp(key, "SecurityProfile") == 0)
  12949. {
  12950. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  12951. {
  12952. check_ascii = value[0];
  12953. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  12954. {
  12955. isSuccess = ConfigurationStatus_Rejected;
  12956. }
  12957. else if(check_ascii == 0x33)
  12958. {
  12959. isSuccess = NotSupported;
  12960. }
  12961. else
  12962. {
  12963. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  12964. {
  12965. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  12966. isSuccess = ConfigurationStatus_Accepted;
  12967. }
  12968. else
  12969. isSuccess = ConfigurationStatus_Rejected;
  12970. }
  12971. }
  12972. else
  12973. {
  12974. isSuccess = ConfigurationStatus_Rejected;
  12975. }
  12976. }
  12977. if(strcmp(key, "DefaultPrice") == 0)
  12978. {
  12979. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  12980. {
  12981. strcpy(str, (const char*)value);
  12982. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  12983. isSuccess = ConfigurationStatus_Accepted;
  12984. }
  12985. else
  12986. {
  12987. isSuccess = ConfigurationStatus_Rejected;
  12988. }
  12989. }
  12990. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  12991. {
  12992. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  12993. {
  12994. strcpy(str, (const char*)value);
  12995. for(int i = 0; str[i]; i++)
  12996. {
  12997. str[i] = tolower(str[i]);
  12998. }
  12999. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13000. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13001. isSuccess = ConfigurationStatus_Accepted;
  13002. }
  13003. else
  13004. {
  13005. isSuccess = ConfigurationStatus_Rejected;
  13006. }
  13007. }
  13008. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  13009. {
  13010. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  13011. {
  13012. strcpy(str, (const char*)value);
  13013. for(int i = 0; str[i]; i++)
  13014. {
  13015. str[i] = tolower(str[i]);
  13016. }
  13017. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13018. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13019. isSuccess = ConfigurationStatus_Accepted;
  13020. }
  13021. else
  13022. {
  13023. isSuccess = ConfigurationStatus_Rejected;
  13024. }
  13025. }
  13026. #if 0
  13027. //For OCPP Test Case
  13028. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  13029. {
  13030. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13031. {
  13032. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  13033. isSuccess = ConfigurationStatus_Accepted;
  13034. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13035. }
  13036. else
  13037. {
  13038. isSuccess = ConfigurationStatus_Rejected;
  13039. }
  13040. }
  13041. #endif
  13042. #if 1
  13043. if(strcmp(key, "LocalAuthListEnabled") == 0)
  13044. {
  13045. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13046. {
  13047. strcpy(str, (const char*)value);
  13048. for(int i = 0; str[i]; i++)
  13049. {
  13050. str[i] = tolower(str[i]);
  13051. }
  13052. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13053. isSuccess = ConfigurationStatus_Accepted;
  13054. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13055. }
  13056. else
  13057. {
  13058. isSuccess = ConfigurationStatus_Rejected;
  13059. }
  13060. }
  13061. #endif
  13062. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  13063. {
  13064. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  13065. {
  13066. check_ascii = value[0];
  13067. if( (check_ascii < 48) || (check_ascii > 57) )
  13068. {
  13069. isSuccess = ConfigurationStatus_Rejected;
  13070. }
  13071. else
  13072. {
  13073. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  13074. isSuccess = ConfigurationStatus_Accepted;
  13075. }
  13076. }
  13077. else
  13078. {
  13079. isSuccess = ConfigurationStatus_Rejected;
  13080. }
  13081. }
  13082. if(strcmp(key, "SendLocalListMaxLength") == 0)
  13083. {
  13084. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  13085. {
  13086. check_ascii = value[0];
  13087. if( (check_ascii < 48) || (check_ascii > 57) )
  13088. {
  13089. isSuccess = ConfigurationStatus_Rejected;
  13090. }
  13091. else
  13092. {
  13093. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  13094. isSuccess = ConfigurationStatus_Accepted;
  13095. }
  13096. }
  13097. else
  13098. {
  13099. isSuccess = ConfigurationStatus_Rejected;
  13100. }
  13101. }
  13102. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  13103. {
  13104. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  13105. {
  13106. strcpy(str, (const char*)value);
  13107. for(int i = 0; str[i]; i++)
  13108. {
  13109. str[i] = tolower(str[i]);
  13110. }
  13111. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13112. isSuccess = ConfigurationStatus_Accepted;
  13113. }
  13114. else
  13115. {
  13116. isSuccess = ConfigurationStatus_Rejected;
  13117. }
  13118. }
  13119. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  13120. {
  13121. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  13122. {
  13123. check_ascii = value[0];
  13124. if( (check_ascii < 48) || (check_ascii > 57) )
  13125. {
  13126. isSuccess = ConfigurationStatus_Rejected;
  13127. }
  13128. else
  13129. {
  13130. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  13131. isSuccess = ConfigurationStatus_Accepted;
  13132. }
  13133. }
  13134. else
  13135. {
  13136. isSuccess = ConfigurationStatus_Rejected;
  13137. }
  13138. }
  13139. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  13140. {
  13141. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  13142. {
  13143. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  13144. isSuccess = ConfigurationStatus_Accepted;
  13145. }
  13146. else
  13147. {
  13148. isSuccess = ConfigurationStatus_Rejected;
  13149. }
  13150. }
  13151. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  13152. {
  13153. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  13154. {
  13155. check_ascii = value[0];
  13156. if( (check_ascii < 48) || (check_ascii > 57) )
  13157. {
  13158. isSuccess = ConfigurationStatus_Rejected;
  13159. }
  13160. else
  13161. {
  13162. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  13163. isSuccess = ConfigurationStatus_Accepted;
  13164. }
  13165. }
  13166. else
  13167. {
  13168. isSuccess = ConfigurationStatus_Rejected;
  13169. }
  13170. }
  13171. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  13172. {
  13173. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  13174. {
  13175. strcpy(str, (const char*)value);
  13176. for(int i = 0; str[i]; i++)
  13177. {
  13178. str[i] = tolower(str[i]);
  13179. }
  13180. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13181. isSuccess = ConfigurationStatus_Accepted;
  13182. }
  13183. else
  13184. {
  13185. isSuccess = ConfigurationStatus_Rejected;
  13186. }
  13187. }
  13188. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  13189. {
  13190. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  13191. {
  13192. check_ascii = value[0];
  13193. if( (check_ascii < 48) || (check_ascii > 57) )
  13194. {
  13195. isSuccess = ConfigurationStatus_Rejected;
  13196. }
  13197. else
  13198. {
  13199. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  13200. isSuccess = ConfigurationStatus_Accepted;
  13201. }
  13202. }
  13203. else
  13204. {
  13205. isSuccess = ConfigurationStatus_Rejected;
  13206. }
  13207. }
  13208. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13209. return isSuccess;
  13210. }
  13211. int TransactionMessageAttemptsGet(void)
  13212. {
  13213. return TransactionMessageAttemptsValue;
  13214. }
  13215. int FirstHeartBeatResponse(void)
  13216. {
  13217. return FirstHeartBeat;
  13218. }
  13219. int TransactionMessageRetryIntervalGet(void)
  13220. {
  13221. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13222. }
  13223. int ReadHttpStatus(int sock)
  13224. {
  13225. //char c;
  13226. char buff[1024]="",*ptr=buff+1;
  13227. int bytes_received, status;
  13228. DEBUG_INFO("Begin Response ..\n");
  13229. while((bytes_received = recv(sock, ptr, 1, 0))){
  13230. if(bytes_received==-1){
  13231. perror("ReadHttpStatus");
  13232. exit(1);
  13233. }
  13234. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  13235. ptr++;
  13236. }
  13237. *ptr=0;
  13238. ptr=buff+1;
  13239. sscanf(ptr,"%*s %d ", &status);
  13240. DEBUG_INFO("%s\n",ptr);
  13241. DEBUG_INFO("status=%d\n",status);
  13242. DEBUG_INFO("End Response ..\n");
  13243. return (bytes_received>0)?status:0;
  13244. }
  13245. //the only filed that it parsed is 'Content-Length'
  13246. int ParseHeader(int sock)
  13247. {
  13248. //char c;
  13249. char buff[1024]="",*ptr=buff+4;
  13250. int bytes_received;
  13251. DEBUG_INFO("Begin HEADER ..\n");
  13252. while((bytes_received = recv(sock, ptr, 1, 0))){
  13253. if(bytes_received==-1){
  13254. perror("Parse Header");
  13255. exit(1);
  13256. }
  13257. if(
  13258. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  13259. (ptr[-1]=='\r') && (*ptr=='\n' )
  13260. ) break;
  13261. ptr++;
  13262. }
  13263. *ptr=0;
  13264. ptr=buff+4;
  13265. //printf("%s",ptr);
  13266. if(bytes_received){
  13267. ptr=strstr(ptr,"Content-Length:");
  13268. if(ptr){
  13269. sscanf(ptr,"%*s %d",&bytes_received);
  13270. }else
  13271. bytes_received=-1; //unknown size
  13272. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  13273. }
  13274. DEBUG_INFO("End HEADER ..\n");
  13275. return bytes_received ;
  13276. }
  13277. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  13278. {
  13279. int result = TRUE;
  13280. char rmFileCmd[100]={0};
  13281. char FilePath[100]={0};
  13282. char ftpbuf[200];
  13283. int systemresult;
  13284. //DEBUG_INFO("filename=%s\n",filename);
  13285. //DEBUG_INFO("url=%s\n",url);
  13286. sprintf(FilePath,"/mnt/%s",filename);
  13287. system("ping 8.8.8.8 &");
  13288. if((access(FilePath,F_OK))!=-1)
  13289. {
  13290. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13291. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13292. system(rmFileCmd);
  13293. }
  13294. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13295. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  13296. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13297. systemresult = system(ftpbuf);
  13298. //DEBUG_INFO("systemresult=%d\n",systemresult);
  13299. if(systemresult != 0)
  13300. {
  13301. DEBUG_INFO("http DownLoad error!\n");
  13302. result = FALSE;
  13303. }
  13304. system("pkill ping");
  13305. return result;
  13306. }
  13307. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  13308. {
  13309. int result = TRUE;
  13310. char rmFileCmd[100]={0};
  13311. char FilePath[100]={0};
  13312. char ftpbuf[200];
  13313. int systemresult;
  13314. //char temp[100];
  13315. sprintf(FilePath,"/mnt/%s",filename);
  13316. system("ping 8.8.8.8 &");
  13317. if((access(FilePath,F_OK))!=-1)
  13318. {
  13319. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13320. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13321. system(rmFileCmd);
  13322. }
  13323. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13324. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  13325. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  13326. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  13327. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13328. systemresult = system(ftpbuf);
  13329. //DEBUG_INFO("systemresult=%d\n",systemresult);
  13330. if(systemresult != 0)
  13331. {
  13332. printf("wget error!\n");
  13333. result = FALSE;
  13334. }
  13335. system("pkill ping");
  13336. return result;
  13337. }
  13338. int httpUploadFile(char *location, char *path, char *filename,char *url)
  13339. {
  13340. char rmFileCmd[100]={0};
  13341. char FilePath[100]={0};
  13342. char buf[512];
  13343. int systemresult = 0;
  13344. //DEBUG_INFO("filename=%s\n",filename);
  13345. //DEBUG_INFO("url=%s\n",url);
  13346. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  13347. if((access(FilePath,F_OK))!=-1)
  13348. {
  13349. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13350. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13351. system(rmFileCmd);
  13352. }
  13353. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  13354. if(fp == NULL)
  13355. {
  13356. DEBUG_INFO("log is NULL\n");
  13357. return FALSE;
  13358. }
  13359. else
  13360. {
  13361. fprintf(fp, "%s\n", url);
  13362. fprintf(fp, "%s\n", filename);
  13363. fclose(fp);
  13364. }
  13365. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  13366. if(phpFP == NULL)
  13367. {
  13368. DEBUG_INFO("PHP upload fail.\n");
  13369. return FALSE;
  13370. }
  13371. else
  13372. {
  13373. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  13374. {
  13375. if(strstr(buf, "result") != NULL)
  13376. {
  13377. sscanf(buf, "result: %d", &systemresult);
  13378. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  13379. }
  13380. }
  13381. pclose(phpFP);
  13382. }
  13383. if(systemresult != 1)
  13384. {
  13385. DEBUG_INFO("HTTP upload error!\n");
  13386. return FALSE;
  13387. }
  13388. return TRUE;
  13389. }
  13390. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  13391. {
  13392. struct hostent* server;
  13393. char *IPbuffer;
  13394. char ftpbuf[200];
  13395. int systemresult;
  13396. // To retrieve host information
  13397. server = gethostbyname(location);
  13398. // To convert an Internet network
  13399. // address into ASCII string
  13400. IPbuffer = inet_ntoa(*((struct in_addr*)
  13401. server->h_addr_list[0]));
  13402. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13403. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  13404. /* format : ftpput -u username -p passwd IP target source*/
  13405. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  13406. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  13407. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13408. systemresult = system(ftpbuf);
  13409. DEBUG_INFO("systemresult=%d\n",systemresult);
  13410. if(systemresult != 0)
  13411. {
  13412. DEBUG_INFO("ftpput error!\n");
  13413. return FALSE;
  13414. }
  13415. return TRUE;
  13416. }
  13417. int GetOcppServerURL()
  13418. {
  13419. int result = FALSE;
  13420. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  13421. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  13422. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  13423. struct yuarel url;
  13424. char urlStr[512];
  13425. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  13426. {
  13427. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  13428. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13429. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  13430. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  13431. if(yuarel_parse(&url, urlStr) != -1)
  13432. {
  13433. sprintf(OcppProtocol, "%s", url.scheme);
  13434. sprintf(OcppHost, "%s", url.host);
  13435. if(url.path == NULL)
  13436. OcppTempPath[0] = '\0';
  13437. else
  13438. {
  13439. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  13440. {
  13441. sprintf(OcppTempPath, "%s/", url.path);
  13442. }
  13443. else
  13444. {
  13445. sprintf(OcppTempPath, "%s", url.path);
  13446. }
  13447. }
  13448. if(url.port == 0)
  13449. {
  13450. if(strcmp(OcppProtocol, "wss") == 0)
  13451. OcppPort = 443;
  13452. else
  13453. OcppPort = 80;
  13454. }
  13455. else
  13456. OcppPort = url.port;
  13457. result = TRUE;
  13458. }
  13459. }
  13460. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  13461. {
  13462. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  13463. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13464. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  13465. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  13466. if(yuarel_parse(&url, urlStr) != -1)
  13467. {
  13468. sprintf(OcppProtocol, "%s", url.scheme);
  13469. sprintf(OcppHost, "%s", url.host);
  13470. if(url.path == NULL)
  13471. OcppTempPath[0] = '\0';
  13472. else
  13473. sprintf(OcppTempPath, "%s", url.path);
  13474. if(url.port == 0)
  13475. {
  13476. if(strcmp(OcppProtocol, "wss") == 0)
  13477. OcppPort = 443;
  13478. else
  13479. OcppPort = 80;
  13480. }
  13481. else
  13482. OcppPort = url.port;
  13483. result = TRUE;
  13484. }
  13485. }
  13486. else
  13487. {
  13488. strcpy(OcppHost,"");
  13489. }
  13490. return result;
  13491. }
  13492. int GetOcppPath()
  13493. {
  13494. int result = FALSE;
  13495. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  13496. {
  13497. if(OcppTempPath == NULL)
  13498. {
  13499. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13500. }
  13501. else
  13502. {
  13503. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13504. }
  13505. result = TRUE;
  13506. goto End;
  13507. }
  13508. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  13509. {
  13510. if(OcppTempPath == NULL)
  13511. {
  13512. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  13513. }
  13514. else
  13515. {
  13516. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  13517. }
  13518. result = TRUE;
  13519. goto End;
  13520. }
  13521. else
  13522. {
  13523. strcpy(OcppPath,"");
  13524. }
  13525. End:
  13526. return result;
  13527. }
  13528. int GetOcppPort()
  13529. {
  13530. return OcppPort;
  13531. }
  13532. int GetOcppConnStatus(void)
  13533. {
  13534. return ShmOCPP16Data->OcppConnStatus;
  13535. }
  13536. void SetOcppConnStatus(uint8_t status)
  13537. {
  13538. ShmOCPP16Data->OcppConnStatus = status;
  13539. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  13540. }
  13541. int GetHeartBeatWithNOResponse(void)
  13542. {
  13543. return HeartBeatWithNOResponse;
  13544. }
  13545. void SetHeartBeatWithNOResponse(void)
  13546. {
  13547. HeartBeatWithNOResponse = 0;
  13548. }
  13549. void GetStartTransactionIdTag(int gun_index)
  13550. {
  13551. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  13552. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13553. }
  13554. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  13555. {
  13556. char ch;
  13557. FILE *fptr1;
  13558. int temptransactionId;
  13559. char str[100]={0};
  13560. temptransactionId = 0;
  13561. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  13562. {
  13563. DEBUG_INFO("IdTag is empty.\n");
  13564. return temptransactionId;
  13565. }
  13566. /*------ Read the file ----------------*/
  13567. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  13568. if (!fptr1)
  13569. {
  13570. DEBUG_INFO("QueueTransactionId file open error.\n");
  13571. //printf(" File not found or unable to open the input file!!\n");
  13572. return temptransactionId;
  13573. }
  13574. ch=fgetc(fptr1);
  13575. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  13576. rewind(fptr1);
  13577. if(ch!=EOF)
  13578. {
  13579. // printf("%c",ch);
  13580. while (fgets(str, 100, fptr1) != NULL)
  13581. {
  13582. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13583. if(str[0]=='\0')
  13584. {
  13585. break;
  13586. }
  13587. char *revbuf[8] = {0}; // Variable store string split
  13588. int num = 0;// Quantity after string split
  13589. DEBUG_INFO("Transaction queue data= %s\n", str);
  13590. splitstring(str,",",revbuf,&num); // String split
  13591. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  13592. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  13593. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  13594. DEBUG_INFO("------------------------------\n");
  13595. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  13596. {
  13597. if(isStopTransaction)
  13598. {
  13599. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  13600. {
  13601. temptransactionId = atoi(revbuf[2]);
  13602. //break;
  13603. }
  13604. }
  13605. else
  13606. {
  13607. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  13608. {
  13609. temptransactionId = atoi(revbuf[2]);
  13610. //break;
  13611. }
  13612. }
  13613. }
  13614. }
  13615. }
  13616. else
  13617. DEBUG_INFO("EOF\n");
  13618. fclose(fptr1);
  13619. /*------- End of reading ---------------*/
  13620. return temptransactionId;
  13621. }
  13622. void SetTransactionIdZero(int transactionId)
  13623. {
  13624. char ch;
  13625. FILE *fptr1, *fptr2;
  13626. int temptransactionId = 0;
  13627. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  13628. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  13629. if (!fptr1)
  13630. {
  13631. //printf(" File not found or unable to open the input file!!\n");
  13632. return ;
  13633. }
  13634. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13635. if (!fptr2)
  13636. {
  13637. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  13638. fclose(fptr1);
  13639. return ;
  13640. }
  13641. ch=fgetc(fptr1);
  13642. rewind(fptr1);
  13643. if(ch!=EOF)
  13644. {
  13645. // copy all contents to the temporary file except the specific line
  13646. while (fgets(str, 100, fptr1) != NULL)
  13647. {
  13648. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13649. if(str[0]=='\0')
  13650. {
  13651. break;
  13652. }
  13653. char *revbuf[8] = {0};
  13654. int num = 0;
  13655. strcpy(strtemp, str);
  13656. splitstring(str,",",revbuf,&num);
  13657. if(revbuf[2][0] != '\0')
  13658. {
  13659. temptransactionId = atoi(revbuf[2]);
  13660. if(transactionId != temptransactionId)
  13661. {
  13662. fprintf(fptr2, "%s\n", strtemp);
  13663. }
  13664. }
  13665. }
  13666. }
  13667. fclose(fptr1);
  13668. fclose(fptr2);
  13669. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13670. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13671. /*------ Read the file ----------------*/
  13672. }
  13673. int InternetDisconnect(void)
  13674. {
  13675. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13676. }
  13677. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  13678. void storeTempStopTransaction(int gun_index)
  13679. {
  13680. char guid[37]={0};
  13681. int tempIndex = 0;
  13682. char TempStopTransaction[256];
  13683. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  13684. DEBUG_INFO("storeTempStopTransaction...\n");
  13685. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  13686. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  13687. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  13688. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13689. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  13690. {
  13691. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13692. {
  13693. tempIndex = ((gun_index==2) ? 1: 0);
  13694. }
  13695. else
  13696. {
  13697. tempIndex = gun_index;
  13698. }
  13699. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13700. {
  13701. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13702. {
  13703. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  13704. }
  13705. }// END OF CHAdeMO_QUANTITY
  13706. }
  13707. else if(gunType[gun_index] == GUN_TYPE_CCS)
  13708. {
  13709. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13710. {
  13711. tempIndex = ((gun_index==2) ? 1: 0);
  13712. }
  13713. else
  13714. {
  13715. tempIndex = gun_index;
  13716. }
  13717. for (int index = 0; index < CCS_QUANTITY; index++)
  13718. {
  13719. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13720. {
  13721. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  13722. }
  13723. }// END OF CCS_QUANTITY
  13724. }
  13725. else if(gunType[gun_index] == GUN_TYPE_GBT)
  13726. {
  13727. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13728. {
  13729. tempIndex = ((gun_index==2) ? 1: 0);
  13730. }
  13731. else
  13732. {
  13733. tempIndex = gun_index;
  13734. }
  13735. for (int index = 0; index < GB_QUANTITY; index++)
  13736. {
  13737. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13738. {
  13739. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  13740. }
  13741. }// END OF GB_QUANTITY
  13742. }
  13743. else if(gunType[gun_index] == GUN_TYPE_DO)
  13744. {
  13745. tempIndex = gun_index;
  13746. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13747. {
  13748. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13749. {
  13750. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  13751. }
  13752. }
  13753. }
  13754. else
  13755. {
  13756. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13757. {
  13758. tempIndex = 2;
  13759. }
  13760. else
  13761. {
  13762. tempIndex = gun_index;
  13763. }
  13764. for (int index = 0; index < AC_QUANTITY; index++)
  13765. {
  13766. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13767. {
  13768. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  13769. }
  13770. }// END OF AC_QUANTITY
  13771. }
  13772. //Stop Transaction Time
  13773. struct timeval tmnow;
  13774. struct tm *tm;
  13775. char buf[28];//, usec_buf[6];
  13776. gettimeofday(&tmnow, NULL);
  13777. time_t t;
  13778. t = time(NULL);
  13779. /*UTC time and date*/
  13780. tm = gmtime(&t);
  13781. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  13782. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  13783. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  13784. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13785. random_uuid(guid);
  13786. /***********************************transactionData******************************************************/
  13787. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  13788. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  13789. //=================================
  13790. //1. Transaction_Begin
  13791. //=================================
  13792. //============================== Energy.Active.Import.Interval ===========================================
  13793. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  13794. {
  13795. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  13796. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  13797. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  13798. 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*/]);
  13799. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13800. 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))
  13801. {
  13802. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  13803. }
  13804. else
  13805. {
  13806. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  13807. }
  13808. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  13809. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13810. }
  13811. //=================================
  13812. //2. Transaction_End
  13813. //=================================
  13814. //2.1====================================== Current.Import L1 ==============================================
  13815. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  13816. {
  13817. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  13818. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  13819. {
  13820. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13821. {
  13822. tempIndex = ((gun_index==2) ? 1: 0);
  13823. }
  13824. else
  13825. {
  13826. tempIndex = gun_index;
  13827. }
  13828. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13829. {
  13830. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13831. {
  13832. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13833. }
  13834. }// End of for CHAdeMO_QUANTITY
  13835. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13836. }
  13837. else if(gunType[gun_index] == GUN_TYPE_CCS)
  13838. {
  13839. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13840. {
  13841. tempIndex = ((gun_index==2) ? 1: 0);
  13842. }
  13843. else
  13844. {
  13845. tempIndex = gun_index;
  13846. }
  13847. for (int index = 0; index < CCS_QUANTITY; index++)
  13848. {
  13849. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13850. {
  13851. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13852. }
  13853. }// End of for CCS_QUANTITY
  13854. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13855. }
  13856. else if(gunType[gun_index] == GUN_TYPE_GBT)
  13857. {
  13858. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13859. {
  13860. tempIndex = ((gun_index==2) ? 1: 0);
  13861. }
  13862. else
  13863. {
  13864. tempIndex = gun_index;
  13865. }
  13866. for (int index = 0; index < GB_QUANTITY; index++)
  13867. {
  13868. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13869. {
  13870. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13871. }
  13872. }// End of for GB_QUANTITY
  13873. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13874. }
  13875. else if(gunType[gun_index] == GUN_TYPE_DO)
  13876. {
  13877. tempIndex = gun_index;
  13878. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13879. {
  13880. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13881. {
  13882. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13883. }
  13884. }
  13885. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13886. }
  13887. else
  13888. {
  13889. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13890. {
  13891. tempIndex = 2;
  13892. }
  13893. else
  13894. {
  13895. tempIndex = gun_index;
  13896. }
  13897. for (int index = 0; index < AC_QUANTITY; index++)
  13898. {
  13899. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13900. {
  13901. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  13902. }
  13903. }// End of for AC_QUANTITY
  13904. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13905. }
  13906. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13907. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  13908. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  13909. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13910. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  13911. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13912. }
  13913. //2.2===================================== Energy.Active.Import.Interval ==========================================
  13914. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  13915. {
  13916. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13917. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  13918. {
  13919. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13920. {
  13921. tempIndex = ((gun_index==2) ? 1: 0);
  13922. }
  13923. else
  13924. {
  13925. tempIndex = gun_index;
  13926. }
  13927. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13928. {
  13929. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13930. {
  13931. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13932. }
  13933. }// END OF CHAdeMO_QUANTITY
  13934. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13935. }
  13936. else if(gunType[gun_index] == GUN_TYPE_CCS)
  13937. {
  13938. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13939. {
  13940. tempIndex = ((gun_index==2) ? 1: 0);
  13941. }
  13942. else
  13943. {
  13944. tempIndex = gun_index;
  13945. }
  13946. for (int index = 0; index < CCS_QUANTITY; index++)
  13947. {
  13948. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13949. {
  13950. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13951. }
  13952. }// END OF CCS_QUANTITY
  13953. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13954. }
  13955. else if(gunType[gun_index] == GUN_TYPE_GBT)
  13956. {
  13957. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13958. {
  13959. tempIndex = ((gun_index==2) ? 1: 0);
  13960. }
  13961. else
  13962. {
  13963. tempIndex = gun_index;
  13964. }
  13965. for (int index = 0; index < GB_QUANTITY; index++)
  13966. {
  13967. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13968. {
  13969. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13970. }
  13971. }// END OF GB_QUANTITY
  13972. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13973. }
  13974. else if(gunType[gun_index] == GUN_TYPE_DO)
  13975. {
  13976. tempIndex = gun_index;
  13977. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13978. {
  13979. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13980. {
  13981. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13982. }
  13983. }
  13984. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13985. }
  13986. else
  13987. {
  13988. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13989. {
  13990. tempIndex = 2;
  13991. }
  13992. else
  13993. {
  13994. tempIndex = gun_index;
  13995. }
  13996. for (int index = 0; index < AC_QUANTITY; index++)
  13997. {
  13998. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13999. {
  14000. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14001. }
  14002. }// END OF AC_QUANTITY
  14003. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  14004. }
  14005. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14006. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  14007. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  14008. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  14009. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  14010. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  14011. }
  14012. //2.3====================================== Power.Active.Import =========================================
  14013. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  14014. {
  14015. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14016. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14017. {
  14018. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14019. {
  14020. tempIndex = ((gun_index==2) ? 1: 0);
  14021. }
  14022. else
  14023. {
  14024. tempIndex = gun_index;
  14025. }
  14026. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14027. {
  14028. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14029. {
  14030. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14031. }
  14032. } // End for CHAdeMO_QUANTITY
  14033. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14034. }
  14035. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14036. {
  14037. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14038. {
  14039. tempIndex = ((gun_index==2) ? 1: 0);
  14040. }
  14041. else
  14042. {
  14043. tempIndex = gun_index;
  14044. }
  14045. for (int index = 0; index < CCS_QUANTITY; index++)
  14046. {
  14047. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14048. {
  14049. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14050. }
  14051. } // END for CCS_QUANTITY
  14052. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14053. }
  14054. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14055. {
  14056. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14057. {
  14058. tempIndex = ((gun_index==2) ? 1: 0);
  14059. }
  14060. else
  14061. {
  14062. tempIndex = gun_index;
  14063. }
  14064. for (int index = 0; index < GB_QUANTITY; index++)
  14065. {
  14066. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14067. {
  14068. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14069. }
  14070. }// END for GB_QUANTITY
  14071. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14072. }
  14073. else if(gunType[gun_index] == GUN_TYPE_DO)
  14074. {
  14075. tempIndex = gun_index;
  14076. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14077. {
  14078. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14079. {
  14080. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14081. }
  14082. }
  14083. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14084. }
  14085. else
  14086. {
  14087. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14088. {
  14089. tempIndex = 2;
  14090. }
  14091. else
  14092. {
  14093. tempIndex = gun_index;
  14094. }
  14095. for (int index = 0; index < AC_QUANTITY; index++)
  14096. {
  14097. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14098. {
  14099. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14100. }
  14101. } // END for AC_QUANTITY
  14102. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  14103. }
  14104. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14105. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  14106. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  14107. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  14108. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  14109. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  14110. }
  14111. //2.4====================================== Voltage L1 ====================================================
  14112. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  14113. {
  14114. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14115. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14116. {
  14117. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14118. {
  14119. tempIndex = ((gun_index==2) ? 1: 0);
  14120. }
  14121. else
  14122. {
  14123. tempIndex = gun_index;
  14124. }
  14125. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14126. {
  14127. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14128. {
  14129. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14130. }
  14131. } // END OF FOR CHAdeMO_QUANTITY
  14132. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14133. }
  14134. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14135. {
  14136. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14137. {
  14138. tempIndex = ((gun_index==2) ? 1: 0);
  14139. }
  14140. else
  14141. {
  14142. tempIndex = gun_index;
  14143. }
  14144. for (int index = 0; index < CCS_QUANTITY; index++)
  14145. {
  14146. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14147. {
  14148. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14149. }
  14150. } // END OF FOR CCS_QUANTITY
  14151. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14152. }
  14153. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14154. {
  14155. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14156. {
  14157. tempIndex = ((gun_index==2) ? 1: 0);
  14158. }
  14159. else
  14160. {
  14161. tempIndex = gun_index;
  14162. }
  14163. for (int index = 0; index < GB_QUANTITY; index++)
  14164. {
  14165. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14166. {
  14167. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14168. }
  14169. } // END OF FOR GB_QUANTITY
  14170. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14171. }
  14172. else if(gunType[gun_index] == GUN_TYPE_DO)
  14173. {
  14174. tempIndex = gun_index;
  14175. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14176. {
  14177. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14178. {
  14179. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14180. }
  14181. }
  14182. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14183. }
  14184. else
  14185. {
  14186. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14187. {
  14188. tempIndex = 2;
  14189. }
  14190. else
  14191. {
  14192. tempIndex = gun_index;
  14193. }
  14194. for (int index = 0; index < AC_QUANTITY; index++)
  14195. {
  14196. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14197. {
  14198. 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
  14199. }
  14200. } // END OF FOR AC_QUANTITY
  14201. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  14202. }
  14203. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14204. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  14205. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  14206. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  14207. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  14208. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  14209. }
  14210. //2.5============================================== End SoC =========================================================
  14211. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  14212. {
  14213. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14214. 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))
  14215. {
  14216. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  14217. {
  14218. tempIndex = ((gun_index==2) ? 1: 0);
  14219. }
  14220. else
  14221. {
  14222. tempIndex = gun_index;
  14223. }
  14224. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14225. {
  14226. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14227. {
  14228. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14229. {
  14230. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  14231. }
  14232. }
  14233. }
  14234. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14235. {
  14236. for (int index = 0; index < CCS_QUANTITY; index++)
  14237. {
  14238. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14239. {
  14240. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  14241. }
  14242. }
  14243. }
  14244. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14245. {
  14246. for (int index = 0; index < GB_QUANTITY; index++)
  14247. {
  14248. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14249. {
  14250. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  14251. }
  14252. }
  14253. }
  14254. else if(gunType[gun_index] == GUN_TYPE_DO)
  14255. {
  14256. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14257. {
  14258. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14259. {
  14260. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  14261. }
  14262. }
  14263. }
  14264. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14265. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  14266. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  14267. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  14268. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  14269. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  14270. } // END FOR DC CASE
  14271. }
  14272. //2.6====================================== Current.Import L2 ==============================================
  14273. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  14274. {
  14275. // AC 3 phase L2 current
  14276. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  14277. {
  14278. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14279. {
  14280. tempIndex = 2;
  14281. }
  14282. else
  14283. {
  14284. tempIndex = gun_index;
  14285. }
  14286. for (int index = 0; index < AC_QUANTITY; index++)
  14287. {
  14288. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14289. {
  14290. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  14291. }
  14292. }// End of for AC_QUANTITY
  14293. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  14294. }
  14295. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14296. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  14297. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  14298. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  14299. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14300. }
  14301. //2.7====================================== Current.Import L3 ==============================================
  14302. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  14303. {
  14304. // AC 3 phase L3 current
  14305. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  14306. {
  14307. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14308. {
  14309. tempIndex = 2;
  14310. }
  14311. else
  14312. {
  14313. tempIndex = gun_index;
  14314. }
  14315. for (int index = 0; index < AC_QUANTITY; index++)
  14316. {
  14317. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14318. {
  14319. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  14320. }
  14321. }// End of for AC_QUANTITY
  14322. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  14323. }
  14324. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14325. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  14326. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  14327. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  14328. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14329. }
  14330. //2.9====================================== Voltage L2 ====================================================
  14331. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  14332. {
  14333. // AC 3 phase L2 volatge
  14334. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  14335. {
  14336. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14337. {
  14338. tempIndex = 2;
  14339. }
  14340. else
  14341. {
  14342. tempIndex = gun_index;
  14343. }
  14344. for (int index = 0; index < AC_QUANTITY; index++)
  14345. {
  14346. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14347. {
  14348. 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
  14349. }
  14350. } // END OF FOR AC_QUANTITY
  14351. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  14352. }
  14353. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14354. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  14355. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  14356. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  14357. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  14358. }
  14359. //2.10====================================== Voltage L3 ====================================================
  14360. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  14361. {
  14362. // AC 3 phase L3 volatge
  14363. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  14364. {
  14365. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14366. {
  14367. tempIndex = 2;
  14368. }
  14369. else
  14370. {
  14371. tempIndex = gun_index;
  14372. }
  14373. for (int index = 0; index < AC_QUANTITY; index++)
  14374. {
  14375. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14376. {
  14377. 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
  14378. }
  14379. } // END OF FOR AC_QUANTITY
  14380. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  14381. }
  14382. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14383. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  14384. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  14385. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  14386. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  14387. }
  14388. //====================== Start SoC ================================
  14389. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  14390. {
  14391. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14392. 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))
  14393. {
  14394. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  14395. {
  14396. tempIndex = ((gun_index==2) ? 1: 0);
  14397. }
  14398. else
  14399. {
  14400. tempIndex = gun_index;
  14401. }
  14402. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14403. {
  14404. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14405. {
  14406. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14407. {
  14408. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  14409. }
  14410. }
  14411. }
  14412. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14413. {
  14414. for (int index = 0; index < CCS_QUANTITY; index++)
  14415. {
  14416. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14417. {
  14418. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  14419. }
  14420. }
  14421. }
  14422. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14423. {
  14424. for (int index = 0; index < GB_QUANTITY; index++)
  14425. {
  14426. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14427. {
  14428. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  14429. }
  14430. }
  14431. }
  14432. else if(gunType[gun_index] == GUN_TYPE_DO)
  14433. {
  14434. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14435. {
  14436. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14437. {
  14438. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  14439. }
  14440. }
  14441. }
  14442. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  14443. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  14444. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  14445. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  14446. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  14447. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  14448. } // END FOR DC CASE
  14449. }
  14450. //======================================== Message create ==============================================
  14451. json_object *StopTransaction = json_object_new_object();
  14452. json_object *transactionDatas = json_object_new_array();
  14453. json_object *sampledValues = json_object_new_array();
  14454. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  14455. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  14456. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  14457. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  14458. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  14459. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  14460. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  14461. {
  14462. json_object *transactionData = json_object_new_object();
  14463. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  14464. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  14465. {
  14466. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  14467. {
  14468. json_object *sampledValue = json_object_new_object();
  14469. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  14470. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  14471. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  14472. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  14473. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  14474. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  14475. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  14476. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  14477. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  14478. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  14479. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  14480. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  14481. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  14482. json_object_array_add(sampledValues, sampledValue);
  14483. }
  14484. }
  14485. json_object_object_add(transactionData, "sampledValue", sampledValues);
  14486. json_object_array_add(transactionDatas, transactionData);
  14487. }
  14488. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  14489. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  14490. ,MESSAGE_TYPE_CALL
  14491. ,guid
  14492. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  14493. json_object_put(StopTransaction);
  14494. // Check File "TempStopTransaction" Exist
  14495. if((access(TempStopTransaction,F_OK))!=-1)
  14496. {
  14497. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  14498. fclose(fopen(TempStopTransaction, "w"));
  14499. }
  14500. else
  14501. {
  14502. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  14503. FILE *log = fopen(TempStopTransaction, "w+");
  14504. if(log == NULL)
  14505. {
  14506. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  14507. return ;
  14508. }
  14509. else
  14510. {
  14511. fclose(log);
  14512. }
  14513. }
  14514. //Add TempStopTransaction | Update TempStopTransaction
  14515. // open file for writing
  14516. FILE *outfile;
  14517. outfile = fopen (TempStopTransaction, "a");
  14518. //DEBUG_INFO("data = %s\n", queuedata);
  14519. fputs(queuedata, outfile);
  14520. fputs("\n", outfile);
  14521. fclose (outfile);
  14522. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14523. }
  14524. void checkTempStopTransaction(int gun_index)
  14525. {
  14526. FILE *fptr1;
  14527. char ch;
  14528. char str[QUEUE_MESSAGE_LENGTH]={0};
  14529. char guid[37]={0};
  14530. char tempdata[65]={0};
  14531. char connectorStr[2]={0};
  14532. char TempStopTransaction[256];
  14533. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  14534. fptr1 = fopen(TempStopTransaction, "r");
  14535. //TempStopTransaction格式: 槍號,StopTransaction封包
  14536. if (!fptr1)
  14537. {
  14538. //printf(" File not found or unable to open the input file!!\n");
  14539. return ;
  14540. }
  14541. ch=fgetc(fptr1);
  14542. //printf(" Now the content of the file %s is : \n",fname);
  14543. rewind(fptr1);
  14544. if(ch!=EOF)
  14545. {
  14546. // copy all contents to the temporary file except the specific line
  14547. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  14548. {
  14549. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14550. if(str[0]=='\0')
  14551. {
  14552. break;
  14553. }
  14554. //TempStopTransaction格式: 槍號,StopTransaction封包
  14555. strncpy(connectorStr, str, 1);
  14556. if(atoi(connectorStr) != (gun_index+1))
  14557. {
  14558. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  14559. fclose(fptr1);
  14560. return ;
  14561. }
  14562. //random_uuid(guid);
  14563. strncpy(guid, str+6, 36); //copy guid
  14564. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  14565. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  14566. {
  14567. //DEBUG_INFO("StopTransaction mapitem pass\n");
  14568. }
  14569. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  14570. OCPP_insert_transaction_msg(NO, str);
  14571. memset(str,0,ARRAY_SIZE(str));
  14572. }
  14573. }
  14574. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  14575. fclose(fptr1);
  14576. remove(TempStopTransaction); // remove the original file
  14577. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14578. }
  14579. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  14580. {
  14581. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  14582. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  14583. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  14584. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  14585. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  14586. }
  14587. int GetWebSocketPingInterval(void)
  14588. {
  14589. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14590. }
  14591. int GetServerSign(void)
  14592. {
  14593. return server_sign;
  14594. }
  14595. uint8_t GetOcppSecurityProfile()
  14596. {
  14597. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14598. }
  14599. void GetOcppChargerBoxId(uint8_t *data)
  14600. {
  14601. sprintf((char*)data, "%s", ShmOCPP16Data->ChargeBoxId);
  14602. }
  14603. void GetOcppSecurityPassword(uint8_t *data)
  14604. {
  14605. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14606. }
  14607. void SetOcppVersion(uint8_t *version)
  14608. {
  14609. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  14610. DEBUG_INFO("ocpp version: %s\n", version);
  14611. if(strstr((char*)version, "ocpp1.6") != NULL)
  14612. {
  14613. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  14614. }
  14615. else if(strstr((char*)version, "ocpp2.0") != NULL)
  14616. {
  14617. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  14618. system("pkill OcppBackend");
  14619. }
  14620. }
  14621. void SetServerSign(int value)
  14622. {
  14623. server_sign = value;
  14624. }
  14625. int GetBootNotificationInterval(void)
  14626. {
  14627. return BootNotificationInterval;
  14628. }
  14629. int GetInternetConn(void)
  14630. {
  14631. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  14632. }
  14633. int isConnectorInitMode(int gun_index)
  14634. {
  14635. int tempIndex = 0;
  14636. int result = TRUE;
  14637. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14638. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14639. {
  14640. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14641. {
  14642. tempIndex = ((gun_index==2) ? 1: 0);
  14643. }
  14644. else
  14645. {
  14646. tempIndex = gun_index;
  14647. }
  14648. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14649. {
  14650. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  14651. {
  14652. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  14653. } //end of the same index
  14654. }//end of for CHAdeMO_QUANTITY
  14655. }
  14656. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14657. {
  14658. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14659. {
  14660. tempIndex = ((gun_index==2) ? 1: 0);
  14661. }
  14662. else
  14663. {
  14664. tempIndex = gun_index;
  14665. }
  14666. for (int index = 0; index < CCS_QUANTITY; index++)
  14667. {
  14668. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14669. {
  14670. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  14671. } //end of the same index
  14672. } // end of for CCS_QUANTITY
  14673. }
  14674. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14675. {
  14676. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14677. {
  14678. tempIndex = ((gun_index==2) ? 1: 0);
  14679. }
  14680. else
  14681. {
  14682. tempIndex = gun_index;
  14683. }
  14684. for (int index = 0; index < GB_QUANTITY; index++)
  14685. {
  14686. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14687. {
  14688. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  14689. } //end of the same index
  14690. } // end of for GB_QUANTITY
  14691. }
  14692. else if(gunType[gun_index] == GUN_TYPE_DO)
  14693. {
  14694. tempIndex = gun_index;
  14695. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14696. {
  14697. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14698. {
  14699. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  14700. } //end of the same index
  14701. }
  14702. }
  14703. else
  14704. {
  14705. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14706. {
  14707. tempIndex = 2;
  14708. }
  14709. else
  14710. {
  14711. tempIndex = gun_index;
  14712. }
  14713. for (int index = 0; index < AC_QUANTITY; index++)
  14714. {
  14715. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14716. {
  14717. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  14718. }//end of the same index
  14719. }//end of for AC_QUANTITY
  14720. }
  14721. return result;
  14722. }
  14723. void refreshProcDogTimer()
  14724. {
  14725. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  14726. }
  14727. void InitialSystemValue(void)
  14728. {
  14729. int connectorIndex = 0;
  14730. //int valueASCII = 0;
  14731. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14732. gunTotalNumber=0;
  14733. SystemInitial = 0;
  14734. localversion=0;
  14735. BootNotificationInterval = 0;
  14736. authorizeRetryTimes = 0;
  14737. GunStatusInterval = 10;
  14738. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14739. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14740. //Hear Beat
  14741. HeartBeatWithNOResponse = 0;
  14742. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  14743. FirstHeartBeat = 0;
  14744. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  14745. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  14746. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  14747. memset(statusModeChage, 0, ARRAY_SIZE(statusModeChage));
  14748. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  14749. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  14750. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  14751. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  14752. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  14753. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  14754. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  14755. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  14756. memset(gunType, 0, ARRAY_SIZE(gunType));
  14757. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14758. {
  14759. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O')
  14760. {
  14761. // DO series
  14762. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  14763. {
  14764. SystemInitial = SystemInitial + 1;
  14765. gunTotalNumber = gunTotalNumber + 1;
  14766. gunType[connectorIndex] = GUN_TYPE_DO;
  14767. connectorIndex = connectorIndex + 1;
  14768. }
  14769. }
  14770. else
  14771. {
  14772. // DM, DW, DS series
  14773. //check connector / socket type (index: 8, 9, 10)
  14774. for(int index=7; index <10 ; index++)
  14775. {
  14776. if(index != 8)
  14777. {
  14778. // DC Connector
  14779. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  14780. {
  14781. SystemInitial = SystemInitial + 1;
  14782. gunTotalNumber = gunTotalNumber + 1;
  14783. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  14784. connectorIndex = connectorIndex + 1;
  14785. }
  14786. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  14787. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  14788. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  14789. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  14790. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  14791. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  14792. {
  14793. SystemInitial = SystemInitial + 1;
  14794. gunTotalNumber = gunTotalNumber + 1;
  14795. gunType[connectorIndex] = GUN_TYPE_CCS;
  14796. connectorIndex = connectorIndex + 1;
  14797. }
  14798. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  14799. {
  14800. SystemInitial = SystemInitial + 1;
  14801. gunTotalNumber = gunTotalNumber + 1;
  14802. gunType[connectorIndex] = GUN_TYPE_GBT;
  14803. connectorIndex = connectorIndex + 1;
  14804. }
  14805. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  14806. {
  14807. SystemInitial = SystemInitial + 1;
  14808. gunTotalNumber = gunTotalNumber + 1;
  14809. gunType[connectorIndex] = GUN_TYPE_DO;
  14810. connectorIndex = connectorIndex + 1;
  14811. }
  14812. }
  14813. else
  14814. {
  14815. // AC Connector
  14816. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14817. {
  14818. SystemInitial = SystemInitial + 1;
  14819. gunTotalNumber = gunTotalNumber + 1;
  14820. gunType[connectorIndex] = GUN_TYPE_AC;
  14821. connectorIndex = connectorIndex + 1;
  14822. }
  14823. }
  14824. }
  14825. }
  14826. //DEBUG_INFO("DC ...\n");
  14827. }
  14828. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  14829. {
  14830. //check connector / socket type (index: 8, 9, 10)
  14831. for(int index=7; index <10 ; index++)
  14832. {
  14833. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14834. {
  14835. SystemInitial = SystemInitial + 1;
  14836. gunTotalNumber = gunTotalNumber + 1;
  14837. gunType[connectorIndex] = GUN_TYPE_AC;
  14838. connectorIndex = connectorIndex + 1;
  14839. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  14840. }
  14841. }
  14842. }
  14843. //Status && ConnectorPlugIn Setting
  14844. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14845. {
  14846. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  14847. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  14848. }
  14849. for (int index = 0; index < CCS_QUANTITY; index++)
  14850. {
  14851. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  14852. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  14853. }
  14854. for (int index = 0; index < GB_QUANTITY; index++)
  14855. {
  14856. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  14857. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  14858. }
  14859. for (int index = 0; index < AC_QUANTITY; index++)
  14860. {
  14861. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  14862. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  14863. }
  14864. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14865. {
  14866. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  14867. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  14868. }
  14869. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  14870. {
  14871. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  14872. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  14873. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  14874. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  14875. }
  14876. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  14877. clientTime.Heartbeat=time((time_t*)NULL);
  14878. sleep(1);
  14879. }
  14880. void LWS_Send(char * str)
  14881. {
  14882. //=====================================================
  14883. // Check InternetConn 0: disconnected, 1: connected
  14884. //====================================================
  14885. if(GetOcppConnStatus() == 0)
  14886. {
  14887. DEBUG_INFO("offline now !!!\n");
  14888. return;
  14889. }
  14890. pthread_mutex_lock(&lock_send);
  14891. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14892. sprintf((char *)SendBuffer, "%s", str);
  14893. SendBufLen = strlen(str);
  14894. pthread_mutex_unlock(&lock_send);
  14895. lws_callback_on_writable(wsi_client);
  14896. //lws_service(context, 0);
  14897. //sleep(1);
  14898. }
  14899. void LWS_SendNow(char * str)
  14900. {
  14901. //=====================================================
  14902. // Check InternetConn 0: disconnected, 1: connected
  14903. //====================================================
  14904. if(GetOcppConnStatus() == 0)
  14905. {
  14906. DEBUG_INFO("offline now !!!\n");
  14907. return;
  14908. }
  14909. pthread_mutex_lock(&lock_send);
  14910. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14911. sprintf((char *)SendBuffer, "%s", str);
  14912. SendBufLen = strlen(str);
  14913. pthread_mutex_unlock(&lock_send);
  14914. lws_callback_on_writable(wsi_client);
  14915. lws_service(context, 0);
  14916. //sleep(1);
  14917. }