MessageHandler.c 764 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971
  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[21];
  75. char parentIdTag[21];
  76. char expiryDate[36];
  77. char idTagstatus[16];
  78. }idTagQuery;
  79. //=============================================
  80. // OCPP HeartBeat Response Not Receive Counts
  81. //============================================
  82. static int HeartBeatWithNOResponse = 0;
  83. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  84. extern sqlite3 *db;
  85. int TransactionMessageAttemptsGet(void);
  86. int TransactionMessageRetryIntervalGet(void);
  87. int GetOcppConnStatus(void);
  88. void SetOcppConnStatus(uint8_t status);
  89. int setKeyValue(char *key, char *value);
  90. void OCPP_get_TableAuthlocalAllData(void);
  91. void processUnkownKey(void);
  92. struct StructOCPPMeterValue
  93. {
  94. unsigned char TimeStamp[28];
  95. struct StructSampledValue SampledValue[10];
  96. };
  97. struct ClientTime
  98. {
  99. unsigned int Heartbeat;
  100. unsigned int StatusNotification[CONNECTOR_QUANTITY];
  101. unsigned int StartTransaction;
  102. unsigned int StopTransaction;
  103. unsigned int MeterValues[CONNECTOR_QUANTITY];
  104. }clientTime;
  105. typedef union
  106. {
  107. //Operations Initiated by Central System
  108. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  109. struct
  110. {
  111. //CsMsgValue[0]
  112. unsigned char StatusNotificationReq:1; //bit 0,
  113. unsigned char StatusNotificationConf:1; //bit 1,
  114. unsigned char TriggerMeterValue:1; //bit 2,
  115. unsigned char :5; //bit 5~7
  116. }bits[CONNECTOR_QUANTITY];
  117. }CpinitiateMsg;
  118. CpinitiateMsg cpinitateMsg;
  119. //GetConfiguration Array
  120. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  121. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  122. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  123. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  124. #if 0
  125. static char *ChargePointErrorCodeStr[] = {
  126. MACROSTR(ConnectorLockFailure),
  127. MACROSTR(EVCommunicationError),
  128. MACROSTR(GroundFailure),
  129. MACROSTR(HighTemperature),
  130. MACROSTR(InternalError),
  131. MACROSTR(LocalListConflict),
  132. MACROSTR(NoError),
  133. MACROSTR(OtherError),
  134. MACROSTR(OverCurrentFailure),
  135. MACROSTR(OverVoltage),
  136. MACROSTR(PowerMeterFailure),
  137. MACROSTR(PowerSwitchFailure),
  138. MACROSTR(ReaderFailure),
  139. MACROSTR(ResetFailure),
  140. MACROSTR(UnderVoltage),
  141. MACROSTR(WeakSignal)
  142. };
  143. #endif
  144. static char * ChargePointStatusStr[] = {
  145. MACROSTR(Available),
  146. MACROSTR(Preparing),
  147. MACROSTR(Charging),
  148. MACROSTR(SuspendedEVSE),
  149. MACROSTR(SuspendedEV),
  150. MACROSTR(Finishing),
  151. MACROSTR(Reserved),
  152. MACROSTR(Unavailable),
  153. MACROSTR(Faulted)
  154. };
  155. static char *RegistrationStatusStr[] = {
  156. MACROSTR(Accepted),
  157. MACROSTR(Pending),
  158. MACROSTR(Rejected)
  159. };
  160. static char *AvailabilityTypeStr[] = {
  161. MACROSTR(Inoperative),
  162. MACROSTR(Operative)
  163. };
  164. static char *AvailabilityStatusStr[] = {
  165. MACROSTR(Accepted),
  166. MACROSTR(Rejected),
  167. MACROSTR(Scheduled)
  168. };
  169. static char *ConfigurationStatusStr[] = {
  170. MACROSTR(Accepted),
  171. MACROSTR(Rejected),
  172. MACROSTR(RebootRequired),
  173. MACROSTR(NotSupported)
  174. };
  175. static char *ClearCacheStatusStr[] = {
  176. MACROSTR(Accepted),
  177. MACROSTR(Rejected)
  178. };
  179. static char *ChargingProfilePurposeTypeStr[] = {
  180. MACROSTR(ChargePointMaxProfile),
  181. MACROSTR(TxDefaultProfile),
  182. MACROSTR(TxProfile)
  183. };
  184. static char *ChargingProfileStatusStr[] = {
  185. MACROSTR(Accepted),
  186. MACROSTR(Rejected),
  187. MACROSTR(NotSupported)
  188. };
  189. static char *ClearChargingProfileStatusStr[] = {
  190. MACROSTR(Accepted),
  191. MACROSTR(Unknown)
  192. };
  193. static char *GetCompositeScheduleStatusStr[] = {
  194. MACROSTR(Accepted),
  195. MACROSTR(Rejected)
  196. };
  197. static char *UpdateTypeStr[] = {
  198. MACROSTR(Differential),
  199. MACROSTR(Full)
  200. };
  201. static char *UpdateStatusStr[] = {
  202. MACROSTR(Accepted),
  203. MACROSTR(Failed),
  204. MACROSTR(NotSupported),
  205. MACROSTR(VersionMismatch)
  206. };
  207. static char *RemoteStartStopStatusStr[] = {
  208. MACROSTR(Accepted),
  209. MACROSTR(Rejected)
  210. };
  211. static char *ReservationStatusStr[] = {
  212. MACROSTR(Accepted),
  213. MACROSTR(Faulted),
  214. MACROSTR(Occupied),
  215. MACROSTR(Rejected),
  216. MACROSTR(Unavailable)
  217. };
  218. static char *ResetTypeStr[] = {
  219. MACROSTR(Hard),
  220. MACROSTR(Soft)
  221. };
  222. static char *ResetStatusStr[] = {
  223. MACROSTR(Accepted),
  224. MACROSTR(Rejected)
  225. };
  226. static char * DiagnosticsStatusStr[] = {
  227. MACROSTR(Idle),
  228. MACROSTR(Uploaded),
  229. MACROSTR(UploadFailed),
  230. MACROSTR(Uploading)
  231. };
  232. static char * FirmwareStatusStr[] = {
  233. MACROSTR(Downloaded),
  234. MACROSTR(DownloadFailed),
  235. MACROSTR(Downloading),
  236. MACROSTR(Idle),
  237. MACROSTR(InstallationFailed),
  238. MACROSTR(Installing),
  239. MACROSTR(Installed)
  240. };
  241. static char * MessageTriggerStr[] = {
  242. MACROSTR(BootNotification),
  243. MACROSTR(DiagnosticsStatusNotification),
  244. MACROSTR(FirmwareStatusNotification),
  245. MACROSTR(Heartbeat),
  246. MACROSTR(MeterValues),
  247. MACROSTR(StatusNotification)
  248. };
  249. static char * TriggerMessageStatusStr[] = {
  250. MACROSTR(Accepted),
  251. MACROSTR(Rejected),
  252. MACROSTR(NotImplemented)
  253. };
  254. static char * UnlockStatusStr[] = {
  255. MACROSTR(Unlocked),
  256. MACROSTR(UnlockFailed),
  257. MACROSTR(NotSupported)
  258. };
  259. #if 0
  260. static char * StopTransactionReasonStr[] = {
  261. MACROSTR(EmergencyStop),
  262. MACROSTR(EVDisconnected),
  263. MACROSTR(HardReset),
  264. MACROSTR(Local),
  265. MACROSTR(Other),
  266. MACROSTR(PowerLoss),
  267. MACROSTR(Reboot),
  268. MACROSTR(Remote),
  269. MACROSTR(SoftReset),
  270. MACROSTR(UnlockCommand),
  271. MACROSTR(DeAuthorized)
  272. };
  273. #endif
  274. static char * CancelReservationStatusStr[] = {
  275. MACROSTR(Accepted),
  276. MACROSTR(Rejected)
  277. };
  278. static char * ReadingContextStr[] = {
  279. MACROSTR(Interruption.Begin),
  280. MACROSTR(Interruption.End),
  281. MACROSTR(Other),
  282. MACROSTR(Sample.Clock),
  283. MACROSTR(Sample.Periodic),
  284. MACROSTR(Transaction.Begin),
  285. MACROSTR(Transaction.End),
  286. MACROSTR(Trigger)
  287. };
  288. static char * ValueFormatStr[] = {
  289. MACROSTR(Raw),
  290. MACROSTR(SignedData)
  291. };
  292. static char * MeasurandStr[] = {
  293. MACROSTR(Current.Export),
  294. MACROSTR(Current.Import),
  295. MACROSTR(Current.Offered),
  296. MACROSTR(Energy.Active.Export.Register),
  297. MACROSTR(Energy.Active.Import.Register),
  298. MACROSTR(Energy.Reactive.Export.Register),
  299. MACROSTR(Energy.Reactive.Import.Register),
  300. MACROSTR(Energy.Active.Export.Interval),
  301. MACROSTR(Energy.Active.Import.Interval),
  302. MACROSTR(Energy.Reactive.Export.Interval),
  303. MACROSTR(Energy.Reactive.Import.Interval),
  304. MACROSTR(Frequency),
  305. MACROSTR(Power.Active.Export),
  306. MACROSTR(Power.Active.Import),
  307. MACROSTR(Power.Factor),
  308. MACROSTR(Power.Offered),
  309. MACROSTR(Power.Reactive.ExportMACROSTR),
  310. MACROSTR(Power.Reactive.Import),
  311. MACROSTR(RPM),
  312. MACROSTR(SoC),
  313. MACROSTR(Temperature),
  314. MACROSTR(Voltage)
  315. };
  316. static char * LocationStr[] = {
  317. MACROSTR(Body),
  318. MACROSTR(Cable),
  319. MACROSTR(EV),
  320. MACROSTR(Inlet),
  321. MACROSTR(Outlet)
  322. };
  323. static char * PhaseStr[] = {
  324. MACROSTR(L1),
  325. MACROSTR(L2),
  326. MACROSTR(L3),
  327. MACROSTR(N),
  328. MACROSTR(L1-N),
  329. MACROSTR(L2-N),
  330. MACROSTR(L3-N),
  331. MACROSTR(L1-L2),
  332. MACROSTR(L2-L3),
  333. MACROSTR(L3-L1)
  334. };
  335. static char * UnitOfMeasureStr[] = {
  336. MACROSTR(Wh),
  337. MACROSTR(kWh),
  338. MACROSTR(varh),
  339. MACROSTR(kvarh),
  340. MACROSTR(W),
  341. MACROSTR(kW),
  342. MACROSTR(VA),
  343. MACROSTR(kVA),
  344. MACROSTR(var),
  345. MACROSTR(kvar),
  346. MACROSTR(A),
  347. MACROSTR(V),
  348. MACROSTR(Celsius),
  349. MACROSTR(Fahrenheit),
  350. MACROSTR(K),
  351. MACROSTR(Percent)
  352. };
  353. //=========================================
  354. // Sqlite3 related function
  355. //=========================================
  356. static int selectSqlCount = 0;
  357. static int callback(void *data, int argc, char **argv, char **azColName){
  358. int i;
  359. //printf("%s: ", (const char*)data);
  360. selectSqlCount = argc;
  361. for(i = 0; i<argc; i++){
  362. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  363. }
  364. //printf("\n");
  365. return 0;
  366. }
  367. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  368. //int i;
  369. //printf("%s:\n", (const char*)data);
  370. localversion = argv[5] ? atoi(argv[5]) : 0;
  371. //printf("localversion=%d\n", localversion);
  372. return 0;
  373. }
  374. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  375. //printf("%s:\n", (const char*)data);
  376. //idTag
  377. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  378. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  379. //parentIdTag
  380. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  381. //expir_date
  382. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  383. //status
  384. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  385. //version
  386. if(columenCount > 5)
  387. idTagQuery.listVersionInt = atoi(columnValue[5]);
  388. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  389. return 0;
  390. }
  391. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  392. {
  393. // localversion = argv[5] ? atoi(argv[5]) : 0;
  394. // printf("localversion=%d\n", localversion);
  395. return 0;
  396. }
  397. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  398. {
  399. for (int i = 0; i < n_columns; i++)
  400. {
  401. DEBUG_INFO("%s\t", col_values[i]);
  402. }
  403. DEBUG_INFO("\n");
  404. return 0;
  405. }
  406. int OCPP_cleanLocalCache()
  407. {
  408. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  409. char *errMsg = 0;
  410. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  411. if (SQLITE_OK != rc)
  412. {
  413. DEBUG_INFO("SQL error: %s\n",errMsg);
  414. return FALSE;
  415. }
  416. return TRUE;
  417. }
  418. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  419. {
  420. int isSuccess = TRUE;
  421. int ret = 0;
  422. //const char* data = "Callback function called";
  423. char sql[300];
  424. char zErrMsg[200];
  425. memset(sql, 0, 300);
  426. memset(zErrMsg, 0, 200);
  427. sprintf(sql, "insert or replace into ocpp_auth_cache (idtag, parent_idtag, expir_date, status) " "VALUES ('%s', '%s', '%s', '%s'); ""SELECT * from ocpp_auth_cache", idTag, parentTage, expiryDate, status);
  428. //* Execute SQL statement */
  429. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  430. if( ret != SQLITE_OK )
  431. {
  432. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  433. isSuccess = FALSE;
  434. }
  435. return isSuccess;
  436. }
  437. void OCPP_getIdTagFromLocalCache(char idTag[])
  438. {
  439. int rc = 0;
  440. char sql[100];
  441. char zErrMsg[100];
  442. memset(sql, 0, 100);
  443. memset(zErrMsg, 0, 100);
  444. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  445. memset(&idTagQuery, 0, sizeof(idTagQuery));
  446. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  447. /* Execute SQL statement */
  448. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  449. if( rc != SQLITE_OK )
  450. {
  451. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  452. }
  453. }
  454. void OCPP_getListVerion()
  455. {
  456. int rc = 0;
  457. // const char* data = "Callback function called";
  458. char sql[100];
  459. char zErrMsg[100];
  460. memset(sql, 0, 100);
  461. memset(zErrMsg, 0, 100);
  462. strcpy(sql, "select * from ocpp_auth_local order by idx");
  463. /* Execute SQL statement */
  464. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  465. if( rc != SQLITE_OK )
  466. {
  467. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  468. }
  469. }
  470. void OCPP_get_TableAuthlocalAllData(void)
  471. {
  472. int rc = 0;
  473. char sql[100];
  474. char zErrMsg[100];
  475. memset(sql, 0, 100);
  476. memset(zErrMsg, 0, 100);
  477. sprintf(sql,"select * from ocpp_auth_local ");
  478. /* Execute SQL statement */
  479. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  480. if( rc != SQLITE_OK )
  481. {
  482. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  483. }
  484. //return ver;
  485. }
  486. int OCPP_cleanLocalList()
  487. {
  488. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  489. char *errMsg = 0;
  490. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  491. if (SQLITE_OK != rc)
  492. {
  493. DEBUG_INFO("%s\n",errMsg);
  494. return FALSE;
  495. }
  496. return TRUE;
  497. }
  498. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  499. {
  500. int isSuccess = FALSE;
  501. int ret = 0;
  502. //const char* data = "Callback function called";
  503. char sql[300];
  504. char zErrMsg[200];
  505. memset(sql, 0, 300);
  506. memset(zErrMsg, 0, 200);
  507. sprintf(sql,"insert or replace into ocpp_auth_local (idtag, parent_idtag, expir_date, status, version) " "VALUES ('%s', '%s', '%s', '%s', %d ); ""SELECT * from ocpp_auth_local", idTag, parentTage, expiryDate, status, version);
  508. //* Execute SQL statement */
  509. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  510. if( ret != SQLITE_OK )
  511. {
  512. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  513. return isSuccess;
  514. }
  515. memset(sql, 0, 300);
  516. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  517. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  518. if( ret != SQLITE_OK )
  519. {
  520. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  521. return isSuccess;
  522. }
  523. isSuccess = TRUE;
  524. return isSuccess;
  525. }
  526. void OCPP_getIdTagFromLocalList(char idTag[])
  527. {
  528. int rc = 0;
  529. // const char* data = "Callback function called";
  530. char sql[100];
  531. char zErrMsg[100];
  532. memset(sql, 0, 100);
  533. memset(zErrMsg, 0, 100);
  534. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  535. memset(&idTagQuery, 0, sizeof(idTagQuery));
  536. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  537. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  538. /* Execute SQL statement */
  539. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  540. if( rc != SQLITE_OK )
  541. {
  542. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  543. }
  544. //return ver;
  545. }
  546. void OCPP_deleteIdTagFromLocalList(char idTag[])
  547. {
  548. //int ver = 0;
  549. //int isSuccess = FALSE;
  550. int rc = 0;
  551. char sql[100];
  552. char zErrMsg[100];
  553. memset(sql, 0, 100);
  554. memset(zErrMsg, 0, 100);
  555. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  556. //* Execute SQL statement */
  557. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  558. if( rc != SQLITE_OK )
  559. {
  560. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  561. }
  562. }
  563. int getCurrentYear()
  564. {
  565. int result = 0;
  566. time_t CurrentTime;
  567. struct tm *tm;
  568. CurrentTime = time(NULL);
  569. tm=localtime(&CurrentTime);
  570. result = (tm->tm_year + 1900);
  571. return result;
  572. }
  573. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  574. {
  575. int result = PASS;
  576. char* errMsg = NULL;
  577. char sqlStr[8192];
  578. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  579. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  580. {
  581. result = FAIL;
  582. DEBUG_INFO( "Insert local transaction record error message: %s\n", errMsg);
  583. }
  584. sprintf(sqlStr, "delete from ocpp_transaction_record where (idx < (select idx from ocpp_transaction_record order by idx desc limit 1)-2000) and (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  585. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  586. {
  587. result = FAIL;
  588. DEBUG_INFO( "delete local transaction record error message: %s\n", errMsg);
  589. }
  590. return result;
  591. }
  592. //==========================================
  593. // Check time passed since today
  594. //==========================================
  595. long long DiffTimebWithNow(struct timeb ST)
  596. {
  597. //return milli-second
  598. struct timeb ET;
  599. long long StartTime,StopTime;
  600. ftime(&ET);
  601. StartTime=(long long)ST.time;
  602. StopTime=(long long)ET.time;
  603. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  604. }
  605. int getTimePassSinceToday()
  606. {
  607. int result = -1;
  608. static time_t lastTime;
  609. time_t t;
  610. struct tm *tmStartToday;
  611. struct timeb tbStartToday;
  612. t=time(NULL);
  613. if(difftime(t, lastTime)>0)
  614. {
  615. tmStartToday=localtime(&t);
  616. tmStartToday->tm_hour = 0;
  617. tmStartToday->tm_min = 0;
  618. tmStartToday->tm_sec = 0;
  619. tbStartToday.time = mktime(tmStartToday);
  620. tbStartToday.millitm = 0;
  621. result = DiffTimebWithNow(tbStartToday)/1000;
  622. lastTime = t;
  623. }
  624. return result;
  625. }
  626. void getNowDatetime(uint8_t *data)
  627. {
  628. time_t t = time(NULL);
  629. struct tm tm = *localtime(&t);
  630. sprintf((char*)data, "%04d-%02d-%02dT%02d:%02d:%02dZ", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
  631. }
  632. int syncDateTimeRTC(uint8_t *data)
  633. {
  634. struct ParsingResult
  635. {
  636. int result;
  637. int scanedElement;
  638. int year;
  639. int month;
  640. int mday;
  641. int hour;
  642. int min;
  643. int sec;
  644. int tz_hour;
  645. int tz_min;
  646. float minSec;
  647. }result;
  648. struct tm tmOrg;
  649. struct tm *tmTarget;
  650. struct timeb tbTarget;
  651. char buf[128];
  652. memset(&result, 0x00, sizeof(struct ParsingResult));
  653. result.result = PASS;
  654. if(strstr((char*)data, ".") != NULL)
  655. {
  656. // Original data with mini second
  657. if(strstr((char*)data, "Z") != NULL)
  658. {
  659. // Original data with Z
  660. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  661. &result.year,
  662. &result.month,
  663. &result.mday,
  664. &result.hour,
  665. &result.min,
  666. &result.sec,
  667. &result.minSec);
  668. }
  669. else
  670. {
  671. // Original data without Z
  672. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  673. &result.year,
  674. &result.month,
  675. &result.mday,
  676. &result.hour,
  677. &result.min,
  678. &result.sec,
  679. &result.minSec,
  680. &result.tz_hour,
  681. &result.tz_min);
  682. }
  683. }
  684. else
  685. {
  686. // Original data without mini second
  687. if(strstr((char*)data, "Z") != NULL)
  688. {
  689. // Original data with Z
  690. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  691. &result.year,
  692. &result.month,
  693. &result.mday,
  694. &result.hour,
  695. &result.min,
  696. &result.sec);
  697. }
  698. else
  699. {
  700. // Original data without Z
  701. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  702. &result.year,
  703. &result.month,
  704. &result.mday,
  705. &result.hour,
  706. &result.min,
  707. &result.sec,
  708. &result.tz_hour,
  709. &result.tz_min);
  710. }
  711. }
  712. tmOrg.tm_year = result.year - 1900;
  713. tmOrg.tm_mon = result.month - 1;
  714. tmOrg.tm_mday = result.mday;
  715. tmOrg.tm_hour = result.hour;
  716. tmOrg.tm_min = result.min;
  717. tmOrg.tm_sec = result.sec;
  718. tmOrg.tm_gmtoff = 0;
  719. tbTarget.time = mktime(&tmOrg);
  720. tbTarget.timezone = 0;
  721. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  722. tmTarget = gmtime(&tbTarget.time);
  723. sprintf(buf, "date -s '%04d-%02d-%02d %02d:%02d:%02d'", (tmTarget->tm_year+1900), (tmTarget->tm_mon+1), tmTarget->tm_mday, tmTarget->tm_hour, tmTarget->tm_min, tmTarget->tm_sec);
  724. //DEBUG_INFO(" org date time: %s\n", data);
  725. //DEBUG_INFO("parse date time: %s\n", buf);
  726. system(buf);
  727. system("/sbin/hwclock -w --systohc");
  728. if(result.scanedElement < 6)
  729. result.result = FAIL;
  730. return result.result;
  731. }
  732. //==========================================
  733. // GetCompositeSchedule logic related function
  734. //==========================================
  735. int DiffTimebSec(struct timeb ST, struct timeb ET)
  736. {
  737. //return milli-second
  738. unsigned int StartTime,StopTime;
  739. StartTime=(unsigned int)ST.time;
  740. StopTime=(unsigned int)ET.time;
  741. return (StopTime-StartTime);
  742. }
  743. int DiffTimebWithNowSec(struct timeb ST)
  744. {
  745. //return milli-second
  746. struct timeb ET;
  747. unsigned int StartTime,StopTime;
  748. ftime(&ET);
  749. StartTime=(unsigned int)ST.time;
  750. StopTime=(unsigned int)ET.time;
  751. return (StopTime-StartTime);
  752. }
  753. int getStartStop(uint8_t *start, uint8_t *stop)
  754. {
  755. int result = -1;
  756. struct tm tmStart;
  757. struct timeb tbStart;
  758. struct tm tmStop;
  759. struct timeb tbStop;
  760. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  761. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  762. {
  763. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  764. //DEBUG_INFO("Stop: %d-%d-%d %d:%d:%d\n", tmStop.tm_year, tmStop.tm_mon, tmStop.tm_mday, tmStop.tm_hour, tmStop.tm_min, tmStop.tm_sec);
  765. tmStart.tm_year -= 1900;
  766. tmStart.tm_mon -= 1;
  767. tbStart.time = mktime(&tmStart);
  768. tbStart.millitm = 0;
  769. tmStop.tm_year -= 1900;
  770. tmStop.tm_mon -= 1;
  771. tbStop.time = mktime(&tmStop);
  772. tbStop.millitm = 0;
  773. result = DiffTimebSec(tbStart, tbStop);
  774. //DEBUG_INFO("getStartStop(): %d\n", result);
  775. }
  776. else
  777. {
  778. DEBUG_WARN("Start or stop date parsing error.\r\n");
  779. }
  780. return result;
  781. }
  782. int isOvertNow(uint8_t *start)
  783. {
  784. int result = NO;
  785. struct tm tmStart;
  786. struct timeb tbStart;
  787. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6))
  788. {
  789. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  790. tmStart.tm_year -= 1900;
  791. tmStart.tm_mon -= 1;
  792. tbStart.time = mktime(&tmStart);
  793. tbStart.millitm = 0;
  794. if(DiffTimebWithNowSec(tbStart) <= 0)
  795. result = NO;
  796. else
  797. result = YES;
  798. }
  799. else
  800. {
  801. DEBUG_WARN("Start date parsing error.\n");
  802. }
  803. return result;
  804. }
  805. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  806. {
  807. int result = -1;
  808. struct tm tmStart;
  809. struct timeb tbStart;
  810. struct tm tmStop;
  811. struct timeb tbStop;
  812. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  813. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  814. {
  815. tmStart.tm_year -= 1900;
  816. tmStart.tm_mon -= 1;
  817. tbStart.time = mktime(&tmStart);
  818. tbStart.millitm = 0;
  819. tmStop.tm_year -= 1900;
  820. tmStop.tm_mon -= 1;
  821. tbStop.time = mktime(&tmStop);
  822. tbStop.millitm = 0;
  823. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  824. }
  825. return result;
  826. }
  827. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  828. {
  829. FILE *fp;
  830. char profileFileName[128];
  831. char *line = NULL;
  832. size_t len = 0;
  833. time_t CurrentTime;
  834. struct tm *tmComposite;
  835. struct StructChargingProfile maxProfile;
  836. struct StructChargingProfile defaultTxProfile;
  837. struct StructChargingProfile txProfile;
  838. struct StructChargingSchedulePeriod tmpPeriod;
  839. uint8_t limitMax=0;
  840. uint8_t limitDef=0;
  841. uint8_t limitTx=0;
  842. int compositePeriodIdx = 0;
  843. CurrentTime = time(NULL);
  844. tmComposite=localtime(&CurrentTime);
  845. sprintf((char*)compositeProfile->ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec);
  846. if(isUnitA)
  847. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  848. else
  849. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  850. compositeProfile->ChargingSchedule.Duration = durationReq;
  851. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  852. {
  853. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  854. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  855. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  856. }
  857. compositeProfile->ChargingProfileId = 0;
  858. compositeProfile->StackLevel = 99 ;
  859. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  860. maxProfile.ChargingProfileId = -1;
  861. defaultTxProfile.ChargingProfileId = -1;
  862. txProfile.ChargingProfileId = -1;
  863. maxProfile.ChargingSchedule.Duration = -1;
  864. defaultTxProfile.ChargingSchedule.Duration = -1;
  865. txProfile.ChargingSchedule.Duration = -1;
  866. system("yes|rm /tmp/*.json");
  867. system("cp /Storage/OCPP/*.json /tmp");
  868. /*
  869. * Search valid charging profile
  870. */
  871. //DEBUG_INFO("====================================\n");
  872. // Search tx profile
  873. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  874. if((access(profileFileName, F_OK))!=-1)
  875. {
  876. fp = fopen(profileFileName, "r");
  877. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  878. {
  879. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  880. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  881. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  882. }
  883. txProfile.ChargingProfileId = -1;
  884. txProfile.StackLevel = -1;
  885. while(getline(&line, &len, fp) != -1)
  886. {
  887. json_object *obj = NULL;
  888. obj = json_tokener_parse(line);
  889. if(is_error(obj))
  890. {
  891. DEBUG_ERROR("Parse txProfile from file error.\n");
  892. }
  893. else
  894. {
  895. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  896. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  897. )
  898. {
  899. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  900. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  901. )
  902. {
  903. struct tm tmFrom, tmTo;
  904. struct timeb tbFrom, tbTo;
  905. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  906. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  907. {
  908. tmFrom.tm_year -= 1900;
  909. tmFrom.tm_mon -= 1;
  910. tbFrom.time = mktime(&tmFrom);
  911. tmTo.tm_year -= 1900;
  912. tmTo.tm_mon -= 1;
  913. tbTo.time = mktime(&tmTo);
  914. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  915. {
  916. if(txProfile.ChargingProfileId == -1)
  917. DEBUG_INFO("TxProfile found.\n");
  918. else
  919. DEBUG_INFO("TxProfile updated.\n");
  920. // Required item
  921. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  922. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  923. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  924. if(isUnitA)
  925. {
  926. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  927. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  928. {
  929. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  930. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  931. 3:
  932. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  933. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  934. }
  935. }
  936. else
  937. {
  938. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  939. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  940. {
  941. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  942. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  943. 3:
  944. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  945. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  946. }
  947. }
  948. // Optional item
  949. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  950. {
  951. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  952. }
  953. else
  954. {
  955. sprintf((char*)txProfile.ValidFrom, " ");
  956. }
  957. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  958. {
  959. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  960. }
  961. else
  962. {
  963. sprintf((char*)txProfile.ValidTo, " ");
  964. }
  965. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  966. {
  967. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  968. }
  969. else
  970. {
  971. sprintf((char*)txProfile.RecurrencyKind, " ");
  972. }
  973. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  974. {
  975. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  976. }
  977. else
  978. {
  979. txProfile.TransactionId = -1;
  980. }
  981. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  982. {
  983. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  984. }
  985. else
  986. {
  987. txProfile.ChargingSchedule.Duration = 86400;
  988. }
  989. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  990. {
  991. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  992. }
  993. else
  994. {
  995. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  996. }
  997. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  998. {
  999. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1000. }
  1001. else
  1002. {
  1003. txProfile.ChargingSchedule.MinChargingRate = -1;
  1004. }
  1005. }
  1006. }
  1007. }
  1008. else
  1009. {
  1010. if(txProfile.ChargingProfileId == -1)
  1011. DEBUG_INFO("TxProfile found.\n");
  1012. else
  1013. DEBUG_INFO("TxProfile updated.\n");
  1014. // Required item
  1015. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1016. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1017. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1018. if(isUnitA)
  1019. {
  1020. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1021. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1022. {
  1023. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1024. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1025. 3:
  1026. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1027. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1028. }
  1029. }
  1030. else
  1031. {
  1032. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1033. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1034. {
  1035. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1036. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1037. 3:
  1038. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1039. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1040. }
  1041. }
  1042. // Optional item
  1043. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1044. {
  1045. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1046. }
  1047. else
  1048. {
  1049. sprintf((char*)txProfile.ValidFrom, " ");
  1050. }
  1051. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1052. {
  1053. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1054. }
  1055. else
  1056. {
  1057. sprintf((char*)txProfile.ValidTo, " ");
  1058. }
  1059. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1060. {
  1061. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1062. }
  1063. else
  1064. {
  1065. sprintf((char*)txProfile.RecurrencyKind, " ");
  1066. }
  1067. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1068. {
  1069. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1070. }
  1071. else
  1072. {
  1073. txProfile.TransactionId = -1;
  1074. }
  1075. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1076. {
  1077. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1078. }
  1079. else
  1080. {
  1081. txProfile.ChargingSchedule.Duration = 86400;
  1082. }
  1083. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1084. {
  1085. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1086. }
  1087. else
  1088. {
  1089. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1090. }
  1091. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1092. {
  1093. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1094. }
  1095. else
  1096. {
  1097. txProfile.ChargingSchedule.MinChargingRate = -1;
  1098. }
  1099. }
  1100. }
  1101. }
  1102. json_object_put(obj);
  1103. }
  1104. fclose(fp);
  1105. /*
  1106. if(txProfile.ChargingProfileId != -1)
  1107. {
  1108. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1109. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1110. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1111. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1112. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1113. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1114. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1115. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1116. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1117. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1118. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1119. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1120. {
  1121. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1122. {
  1123. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1124. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1125. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1126. }
  1127. }
  1128. }
  1129. else
  1130. DEBUG_INFO("TxProfile not found.\n");*/
  1131. }
  1132. // Search default tx profile
  1133. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1134. if((access(profileFileName, F_OK))==-1)
  1135. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1136. if((access(profileFileName, F_OK))!=-1)
  1137. {
  1138. fp = fopen(profileFileName, "r");
  1139. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1140. {
  1141. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1142. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1143. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1144. }
  1145. defaultTxProfile.ChargingProfileId = -1;
  1146. defaultTxProfile.StackLevel = -1;
  1147. while(getline(&line, &len, fp) != -1)
  1148. {
  1149. json_object *obj = NULL;
  1150. obj = json_tokener_parse(line);
  1151. if(is_error(obj))
  1152. {
  1153. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1154. }
  1155. else
  1156. {
  1157. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1158. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1159. )
  1160. {
  1161. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1162. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1163. )
  1164. {
  1165. struct tm tmFrom, tmTo;
  1166. struct timeb tbFrom, tbTo;
  1167. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  1168. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  1169. {
  1170. tmFrom.tm_year -= 1900;
  1171. tmFrom.tm_mon -= 1;
  1172. tbFrom.time = mktime(&tmFrom);
  1173. tmTo.tm_year -= 1900;
  1174. tmTo.tm_mon -= 1;
  1175. tbTo.time = mktime(&tmTo);
  1176. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1177. {
  1178. if(defaultTxProfile.ChargingProfileId == -1)
  1179. DEBUG_INFO("TxDefaultProfile found.\n");
  1180. else
  1181. DEBUG_INFO("TxDefaultProfile updated.\n");
  1182. // Required item
  1183. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1184. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1185. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1186. if(isUnitA)
  1187. {
  1188. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1189. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1190. {
  1191. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1192. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1193. 3:
  1194. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1195. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1196. }
  1197. }
  1198. else
  1199. {
  1200. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1201. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1202. {
  1203. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1204. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1205. 3:
  1206. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1207. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1208. }
  1209. }
  1210. // Optional item
  1211. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1212. {
  1213. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1214. }
  1215. else
  1216. {
  1217. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1218. }
  1219. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1220. {
  1221. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1222. }
  1223. else
  1224. {
  1225. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1226. }
  1227. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1228. {
  1229. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1230. }
  1231. else
  1232. {
  1233. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1234. }
  1235. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1236. {
  1237. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1238. }
  1239. else
  1240. {
  1241. defaultTxProfile.TransactionId = -1;
  1242. }
  1243. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1244. {
  1245. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1246. }
  1247. else
  1248. {
  1249. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1250. }
  1251. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1252. {
  1253. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1254. }
  1255. else
  1256. {
  1257. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1258. }
  1259. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1260. {
  1261. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1262. }
  1263. else
  1264. {
  1265. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1266. }
  1267. }
  1268. }
  1269. }
  1270. else
  1271. {
  1272. if(defaultTxProfile.ChargingProfileId == -1)
  1273. DEBUG_INFO("TxDefaultProfile found.\n");
  1274. else
  1275. DEBUG_INFO("TxDefaultProfile updated.\n");
  1276. // Required item
  1277. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1278. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1279. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1280. if(isUnitA)
  1281. {
  1282. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1283. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1284. {
  1285. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1286. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1287. 3:
  1288. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1289. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1290. }
  1291. }
  1292. else
  1293. {
  1294. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1295. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1296. {
  1297. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1298. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1299. 3:
  1300. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1301. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1302. }
  1303. }
  1304. // Optional item
  1305. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1306. {
  1307. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1308. }
  1309. else
  1310. {
  1311. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1312. }
  1313. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1314. {
  1315. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1316. }
  1317. else
  1318. {
  1319. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1320. }
  1321. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1322. {
  1323. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1324. }
  1325. else
  1326. {
  1327. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1328. }
  1329. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1330. {
  1331. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1332. }
  1333. else
  1334. {
  1335. defaultTxProfile.TransactionId = -1;
  1336. }
  1337. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1338. {
  1339. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1340. }
  1341. else
  1342. {
  1343. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1344. }
  1345. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1346. {
  1347. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1348. }
  1349. else
  1350. {
  1351. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1352. }
  1353. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1354. {
  1355. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1356. }
  1357. else
  1358. {
  1359. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1360. }
  1361. }
  1362. }
  1363. }
  1364. json_object_put(obj);
  1365. }
  1366. fclose(fp);
  1367. /*
  1368. if(defaultTxProfile.ChargingProfileId != -1)
  1369. {
  1370. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1371. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1372. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1373. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1374. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1375. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1376. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1377. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  1378. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1379. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1380. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1381. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1382. {
  1383. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1384. {
  1385. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1386. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1387. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1388. }
  1389. }
  1390. }
  1391. else
  1392. DEBUG_INFO("TxDefaultProfile not found.\n");
  1393. DEBUG_INFO("------------------------------------\n");*/
  1394. }
  1395. // Search max profile
  1396. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1397. if((access(profileFileName, F_OK))!=-1)
  1398. {
  1399. fp = fopen(profileFileName, "r");
  1400. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1401. {
  1402. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1403. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1404. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1405. }
  1406. maxProfile.ChargingProfileId = -1;
  1407. maxProfile.StackLevel = -1;
  1408. while(getline(&line, &len, fp) != -1)
  1409. {
  1410. json_object *obj = NULL;
  1411. obj = json_tokener_parse(line);
  1412. if(is_error(obj))
  1413. {
  1414. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1415. }
  1416. else
  1417. {
  1418. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  1419. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1420. )
  1421. {
  1422. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1423. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1424. )
  1425. {
  1426. struct tm tmFrom, tmTo;
  1427. struct timeb tbFrom, tbTo;
  1428. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  1429. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  1430. {
  1431. tmFrom.tm_year -= 1900;
  1432. tmFrom.tm_mon -= 1;
  1433. tbFrom.time = mktime(&tmFrom);
  1434. tmTo.tm_year -= 1900;
  1435. tmTo.tm_mon -= 1;
  1436. tbTo.time = mktime(&tmTo);
  1437. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1438. {
  1439. if(maxProfile.ChargingProfileId == -1)
  1440. DEBUG_INFO("MaxProfile found.\n");
  1441. else
  1442. DEBUG_INFO("MaxProfile updated.\n");
  1443. // Required item
  1444. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1445. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1446. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1447. if(isUnitA)
  1448. {
  1449. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1450. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1451. {
  1452. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1453. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1454. 3:
  1455. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1456. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1457. }
  1458. }
  1459. else
  1460. {
  1461. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1462. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1463. {
  1464. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1465. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1466. 3:
  1467. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1468. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1469. }
  1470. }
  1471. // Optional item
  1472. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1473. {
  1474. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1475. }
  1476. else
  1477. {
  1478. sprintf((char*)maxProfile.ValidFrom, " ");
  1479. }
  1480. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1481. {
  1482. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1483. }
  1484. else
  1485. {
  1486. sprintf((char*)maxProfile.ValidTo, " ");
  1487. }
  1488. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1489. {
  1490. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1491. }
  1492. else
  1493. {
  1494. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1495. }
  1496. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1497. {
  1498. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1499. }
  1500. else
  1501. {
  1502. maxProfile.TransactionId = -1;
  1503. }
  1504. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1505. {
  1506. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1507. }
  1508. else
  1509. {
  1510. maxProfile.ChargingSchedule.Duration = 86400;
  1511. }
  1512. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1513. {
  1514. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1515. }
  1516. else
  1517. {
  1518. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1519. }
  1520. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1521. {
  1522. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1523. }
  1524. else
  1525. {
  1526. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1527. }
  1528. }
  1529. }
  1530. }
  1531. else
  1532. {
  1533. if(maxProfile.ChargingProfileId == -1)
  1534. DEBUG_INFO("MaxProfile found.\n");
  1535. else
  1536. DEBUG_INFO("MaxProfile updated.\n");
  1537. // Required item
  1538. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1539. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1540. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1541. if(isUnitA)
  1542. {
  1543. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1544. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1545. {
  1546. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1547. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1548. 3:
  1549. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1550. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1551. }
  1552. }
  1553. else
  1554. {
  1555. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1556. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1557. {
  1558. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1559. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1560. 3:
  1561. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1562. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1563. }
  1564. }
  1565. // Optional item
  1566. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1567. {
  1568. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1569. }
  1570. else
  1571. {
  1572. sprintf((char*)maxProfile.ValidFrom, " ");
  1573. }
  1574. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1575. {
  1576. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1577. }
  1578. else
  1579. {
  1580. sprintf((char*)maxProfile.ValidTo, " ");
  1581. }
  1582. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1583. {
  1584. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1585. }
  1586. else
  1587. {
  1588. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1589. }
  1590. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1591. {
  1592. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1593. }
  1594. else
  1595. {
  1596. maxProfile.TransactionId = -1;
  1597. }
  1598. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1599. {
  1600. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1601. }
  1602. else
  1603. {
  1604. maxProfile.ChargingSchedule.Duration = 86400;
  1605. }
  1606. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1607. {
  1608. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1609. }
  1610. else
  1611. {
  1612. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1613. }
  1614. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1615. {
  1616. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1617. }
  1618. else
  1619. {
  1620. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1621. }
  1622. }
  1623. }
  1624. }
  1625. json_object_put(obj);
  1626. }
  1627. fclose(fp);
  1628. /*
  1629. if(maxProfile.ChargingProfileId !=-1)
  1630. {
  1631. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1632. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1633. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1634. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1635. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1636. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1637. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1638. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1639. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1640. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1641. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1642. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1643. {
  1644. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1645. {
  1646. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1647. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1648. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1649. }
  1650. }
  1651. }
  1652. else
  1653. DEBUG_INFO("MaxProfile not found.\n");
  1654. DEBUG_INFO("------------------------------------\n");*/
  1655. }
  1656. /*
  1657. * Align found profile start schedule & periods
  1658. */
  1659. //DEBUG_INFO("====================================\n");
  1660. /*
  1661. // For local test usage, force modify found profile start schedule info
  1662. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-10);
  1663. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-5);
  1664. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-3);
  1665. */
  1666. if(txProfile.ChargingProfileId != -1)
  1667. {
  1668. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  1669. {
  1670. if(txProfile.ChargingSchedule.Duration != -1)
  1671. {
  1672. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1673. 0:
  1674. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1675. }
  1676. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1677. {
  1678. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1679. {
  1680. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1681. 0:
  1682. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1683. if(idxPeriod > 0)
  1684. {
  1685. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1686. {
  1687. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1688. }
  1689. }
  1690. }
  1691. }
  1692. }
  1693. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  1694. {
  1695. if(txProfile.ChargingSchedule.Duration != -1)
  1696. {
  1697. txProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?txProfile.ChargingSchedule.Duration:((txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1698. 0:
  1699. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1700. }
  1701. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1702. {
  1703. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1704. {
  1705. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1706. 0:
  1707. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1708. if(idxPeriod > 0)
  1709. {
  1710. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1711. {
  1712. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1713. }
  1714. }
  1715. }
  1716. }
  1717. }
  1718. else
  1719. {
  1720. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  1721. {
  1722. if(txProfile.ChargingSchedule.Duration != -1)
  1723. {
  1724. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1725. 0:
  1726. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1727. }
  1728. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1729. {
  1730. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1731. {
  1732. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1733. 0:
  1734. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1735. if(idxPeriod > 0)
  1736. {
  1737. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1738. {
  1739. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1740. }
  1741. }
  1742. }
  1743. }
  1744. }
  1745. else
  1746. {
  1747. if(txProfile.ChargingSchedule.Duration != -1)
  1748. {
  1749. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1750. 0:
  1751. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1752. }
  1753. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1754. {
  1755. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1756. {
  1757. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1758. 0:
  1759. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1760. if(idxPeriod > 0)
  1761. {
  1762. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1763. {
  1764. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1765. }
  1766. }
  1767. }
  1768. }
  1769. }
  1770. }
  1771. /*
  1772. DEBUG_INFO("txProfile after align.\n");
  1773. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1774. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1775. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1776. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1777. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1778. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1779. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1780. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1781. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1782. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1783. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1784. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1785. {
  1786. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1787. {
  1788. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1789. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1790. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1791. }
  1792. }*/
  1793. }
  1794. if(defaultTxProfile.ChargingProfileId != -1)
  1795. {
  1796. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  1797. {
  1798. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1799. {
  1800. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1801. 0:
  1802. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1803. }
  1804. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1805. {
  1806. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1807. {
  1808. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1809. 0:
  1810. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1811. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1812. {
  1813. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1814. }
  1815. if(idxPeriod > 0)
  1816. {
  1817. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1818. {
  1819. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1820. }
  1821. }
  1822. }
  1823. }
  1824. }
  1825. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  1826. {
  1827. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1828. {
  1829. defaultTxProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?defaultTxProfile.ChargingSchedule.Duration:((defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1830. 0:
  1831. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1832. }
  1833. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1834. {
  1835. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1836. {
  1837. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1838. 0:
  1839. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1840. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1841. {
  1842. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1843. }
  1844. if(idxPeriod > 0)
  1845. {
  1846. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1847. {
  1848. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1849. }
  1850. }
  1851. }
  1852. }
  1853. }
  1854. else
  1855. {
  1856. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  1857. {
  1858. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1859. {
  1860. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1861. 0:
  1862. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1863. }
  1864. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1865. {
  1866. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1867. {
  1868. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1869. 0:
  1870. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1871. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1872. {
  1873. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1874. }
  1875. if(idxPeriod > 0)
  1876. {
  1877. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1878. {
  1879. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1880. }
  1881. }
  1882. }
  1883. }
  1884. }
  1885. else
  1886. {
  1887. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1888. {
  1889. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1890. 0:
  1891. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1892. }
  1893. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1894. {
  1895. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1896. {
  1897. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1898. 0:
  1899. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1900. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1901. {
  1902. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1903. }
  1904. if(idxPeriod > 0)
  1905. {
  1906. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1907. {
  1908. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1909. }
  1910. }
  1911. }
  1912. }
  1913. }
  1914. }
  1915. /*
  1916. DEBUG_INFO("defaultTxProfile after align.\n");
  1917. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1918. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1919. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1920. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1921. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1922. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1923. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1924. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1925. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1926. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1927. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1928. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1929. {
  1930. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1931. {
  1932. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1933. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1934. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1935. }
  1936. }
  1937. DEBUG_INFO("------------------------------------\n");*/
  1938. }
  1939. if(maxProfile.ChargingProfileId != -1)
  1940. {
  1941. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1942. {
  1943. if(maxProfile.ChargingSchedule.Duration != -1)
  1944. {
  1945. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1946. 0:
  1947. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1948. }
  1949. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1950. {
  1951. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1952. {
  1953. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1954. 0:
  1955. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1956. if(idxPeriod > 0)
  1957. {
  1958. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1959. {
  1960. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1961. }
  1962. }
  1963. }
  1964. }
  1965. }
  1966. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1967. {
  1968. if(maxProfile.ChargingSchedule.Duration != -1)
  1969. {
  1970. maxProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?maxProfile.ChargingSchedule.Duration:((maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1971. 0:
  1972. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1973. }
  1974. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1975. {
  1976. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1977. {
  1978. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1979. 0:
  1980. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1981. if(idxPeriod > 0)
  1982. {
  1983. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1984. {
  1985. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1986. }
  1987. }
  1988. }
  1989. }
  1990. }
  1991. else
  1992. {
  1993. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1994. {
  1995. if(maxProfile.ChargingSchedule.Duration != -1)
  1996. {
  1997. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1998. 0:
  1999. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2000. }
  2001. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2002. {
  2003. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2004. {
  2005. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2006. 0:
  2007. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2008. if(idxPeriod > 0)
  2009. {
  2010. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2011. {
  2012. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2013. }
  2014. }
  2015. }
  2016. }
  2017. }
  2018. else
  2019. {
  2020. if(maxProfile.ChargingSchedule.Duration != -1)
  2021. {
  2022. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2023. 0:
  2024. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2025. }
  2026. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2027. {
  2028. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2029. {
  2030. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2031. 0:
  2032. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2033. if(idxPeriod > 0)
  2034. {
  2035. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2036. {
  2037. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2038. }
  2039. }
  2040. }
  2041. }
  2042. }
  2043. }
  2044. /*
  2045. DEBUG_INFO("MaxProfile after align.\n");
  2046. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2047. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2048. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2049. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2050. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2051. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2052. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2053. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2054. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2055. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2056. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2057. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2058. {
  2059. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2060. {
  2061. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2062. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2063. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2064. }
  2065. }
  2066. DEBUG_INFO("------------------------------------\n");*/
  2067. }
  2068. /*
  2069. * Merge to conposite schedule
  2070. */
  2071. //DEBUG_INFO("====================================\n");
  2072. // Find each profile period quantity
  2073. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2074. {
  2075. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2076. limitMax = idx+1;
  2077. }
  2078. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2079. {
  2080. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2081. limitDef = idx+1;
  2082. }
  2083. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2084. {
  2085. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2086. limitTx = idx+1;
  2087. }
  2088. // TxProfile found, composite schedule based on it
  2089. if(txProfile.ChargingProfileId != -1)
  2090. {
  2091. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2092. {
  2093. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  2094. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  2095. (txProfile.ChargingSchedule.Duration > 0))
  2096. {
  2097. if(maxProfile.ChargingProfileId != -1)
  2098. {
  2099. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2100. {
  2101. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2102. {
  2103. if((maxProfile.ChargingSchedule.Duration > 0))
  2104. {
  2105. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2106. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2107. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2108. }
  2109. else
  2110. {
  2111. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2112. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2113. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2114. }
  2115. }
  2116. if(idxMaxPeriod == (limitMax-1))
  2117. {
  2118. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2119. {
  2120. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2121. {
  2122. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2123. compositePeriodIdx++;
  2124. }
  2125. else
  2126. {
  2127. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2128. }
  2129. }
  2130. }
  2131. }
  2132. }
  2133. else
  2134. {
  2135. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2136. {
  2137. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2138. compositePeriodIdx++;
  2139. }
  2140. else
  2141. {
  2142. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2143. }
  2144. }
  2145. }
  2146. if(idxTxPeriod == (limitTx-1))
  2147. {
  2148. if(defaultTxProfile.ChargingProfileId != -1)
  2149. {
  2150. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2151. {
  2152. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  2153. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2154. (defaultTxProfile.ChargingSchedule.Duration>0))
  2155. {
  2156. if(maxProfile.ChargingProfileId != -1)
  2157. {
  2158. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2159. {
  2160. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2161. {
  2162. if((maxProfile.ChargingSchedule.Duration > 0))
  2163. {
  2164. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2165. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2166. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2167. }
  2168. else
  2169. {
  2170. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2171. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2172. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2173. }
  2174. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2175. {
  2176. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2177. {
  2178. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2179. compositePeriodIdx++;
  2180. }
  2181. else
  2182. {
  2183. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2184. }
  2185. }
  2186. break;
  2187. }
  2188. }
  2189. }
  2190. else
  2191. {
  2192. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2193. {
  2194. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2195. compositePeriodIdx++;
  2196. }
  2197. else
  2198. {
  2199. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2200. }
  2201. }
  2202. }
  2203. }
  2204. }
  2205. }
  2206. }
  2207. }
  2208. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  2209. else if(defaultTxProfile.ChargingProfileId != -1)
  2210. {
  2211. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2212. {
  2213. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  2214. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2215. (defaultTxProfile.ChargingSchedule.Duration > 0))
  2216. {
  2217. if(maxProfile.ChargingProfileId != -1)
  2218. {
  2219. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2220. {
  2221. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2222. {
  2223. if((maxProfile.ChargingSchedule.Duration > 0))
  2224. {
  2225. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2226. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2227. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  2228. }
  2229. else
  2230. {
  2231. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2232. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2233. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2234. }
  2235. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2236. {
  2237. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2238. {
  2239. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2240. compositePeriodIdx++;
  2241. }
  2242. else
  2243. {
  2244. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2245. }
  2246. }
  2247. break;
  2248. }
  2249. }
  2250. }
  2251. else
  2252. {
  2253. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2254. {
  2255. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2256. compositePeriodIdx++;
  2257. }
  2258. else
  2259. {
  2260. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2261. }
  2262. }
  2263. }
  2264. }
  2265. }
  2266. // Fill other period by MaxProfile
  2267. if(maxProfile.ChargingProfileId != -1)
  2268. {
  2269. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2270. {
  2271. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2272. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2273. (maxProfile.ChargingSchedule.Duration > 0))
  2274. {
  2275. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  2276. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2277. {
  2278. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  2279. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  2280. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2281. }
  2282. if((maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2283. {
  2284. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.Duration;
  2285. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  2286. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2287. }
  2288. if(tmpPeriod.Limit != -1)
  2289. {
  2290. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2291. {
  2292. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2293. {
  2294. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2295. compositePeriodIdx++;
  2296. }
  2297. else
  2298. {
  2299. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2300. }
  2301. }
  2302. }
  2303. }
  2304. }
  2305. }
  2306. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  2307. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2308. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  2309. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  2310. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2311. {
  2312. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2313. {
  2314. compositeProfile->ChargingProfileId = 1;
  2315. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2316. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2317. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2318. }
  2319. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2320. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2321. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2322. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2323. }
  2324. if(line)
  2325. free(line);
  2326. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  2327. }
  2328. //==========================================
  2329. // Init all share memory
  2330. //==========================================
  2331. int InitShareMemory()
  2332. {
  2333. int result = PASS;
  2334. int MeterSMId;
  2335. //creat ShmSysConfigAndInfo
  2336. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  2337. {
  2338. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  2339. result = FAIL;
  2340. }
  2341. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2342. {
  2343. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  2344. result = FAIL;
  2345. }
  2346. else
  2347. {}
  2348. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  2349. {
  2350. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  2351. result = FAIL;
  2352. }
  2353. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2354. {
  2355. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  2356. result = FAIL;
  2357. }
  2358. else
  2359. {}
  2360. //creat ShmPsuData
  2361. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  2362. {
  2363. DEBUG_ERROR("shmget ShmPsuData NG\n");
  2364. result = FAIL;
  2365. }
  2366. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2367. {
  2368. DEBUG_ERROR("shmat ShmPsuData NG\n");
  2369. result = FAIL;
  2370. }
  2371. else
  2372. {}
  2373. //creat ShmOCPP16Data
  2374. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  2375. {
  2376. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  2377. result = FAIL;
  2378. }
  2379. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2380. {
  2381. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  2382. result = FAIL;
  2383. }
  2384. else
  2385. {}
  2386. /****************************** For Initial Settings************************************************/
  2387. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  2388. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  2389. // allocate Configuration memory address
  2390. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  2391. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  2392. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  2393. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  2394. //offline MeterValue Interval
  2395. TempMeterValueInterval = 0;
  2396. return result;
  2397. }
  2398. int ProcessShareMemory()
  2399. {
  2400. if(InitShareMemory() == FAIL)
  2401. {
  2402. DEBUG_ERROR("InitShareMemory NG\n");
  2403. if(ShmStatusCodeData!=NULL)
  2404. {
  2405. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  2406. }
  2407. sleep(5);
  2408. return FAIL;
  2409. }
  2410. return PASS;
  2411. }
  2412. void CheckSystemValue(void)
  2413. {
  2414. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  2415. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  2416. char filenmae[100]={0};
  2417. char str[100]={0};
  2418. int tempIndex = 0;
  2419. //===============================
  2420. // send Heartbeat
  2421. //===============================
  2422. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2423. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  2424. {
  2425. clientTime.Heartbeat=time((time_t*)NULL);
  2426. if(server_sign == TRUE)
  2427. {
  2428. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2429. }
  2430. else
  2431. {
  2432. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  2433. }
  2434. }
  2435. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  2436. {
  2437. //parameter for test
  2438. sendHeartbeatRequest(0);
  2439. //==============================================
  2440. // Reset Waiting Time
  2441. //==============================================
  2442. HeartBeatWithNOResponse += 1;
  2443. }
  2444. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  2445. {
  2446. //==========================================
  2447. // csu trigger DataTransferReq
  2448. //==========================================
  2449. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  2450. {
  2451. sendDataTransferRequest(gun_index);
  2452. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  2453. }
  2454. //===============================
  2455. // CSU Trigger Authorize Request
  2456. //===============================
  2457. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  2458. {
  2459. sendAuthorizeRequest(0);
  2460. authorizeRetryTimes = authorizeRetryTimes + 1;
  2461. if(authorizeRetryTimes < 3)
  2462. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2463. }
  2464. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  2465. {
  2466. authorizeRetryTimes = 0;
  2467. SetOcppConnStatus(FALSE);
  2468. server_sign = FALSE;
  2469. }
  2470. 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))
  2471. {
  2472. sendAuthorizeRequest(0);
  2473. }
  2474. //==============================================
  2475. // CSU Trigger Smart Charging Profilw
  2476. //==============================================
  2477. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  2478. {
  2479. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  2480. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  2481. }
  2482. //==============================================
  2483. // Charger start transaction
  2484. //==============================================
  2485. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2486. {
  2487. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  2488. sendStartTransactionRequest(gun_index);
  2489. clientTime.StartTransaction = time((time_t*)NULL);
  2490. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2491. storeTempStopTransaction(gun_index);
  2492. }
  2493. //==============================================
  2494. // Charger stop transaction
  2495. //==============================================
  2496. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2497. {
  2498. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2499. sendStopTransactionRequest(gun_index);
  2500. clientTime.StopTransaction = time((time_t*)NULL);
  2501. }
  2502. //==============================================
  2503. // Charger status report
  2504. //==============================================
  2505. //--- Check Mode Change ---//
  2506. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2507. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2508. {
  2509. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2510. {
  2511. tempIndex = ((gun_index==2) ? 1: 0);
  2512. }
  2513. else
  2514. {
  2515. tempIndex = gun_index;
  2516. }
  2517. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2518. {
  2519. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2520. {
  2521. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  2522. {
  2523. // Sent unplug message for California pricing logic
  2524. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  2525. {
  2526. uint8_t ts[20];
  2527. getNowDatetime(ts);
  2528. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2529. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2530. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2531. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2532. }
  2533. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2534. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2535. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2536. statusModeChage[gun_index] = TRUE;
  2537. }
  2538. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2539. {
  2540. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2541. if((access(filenmae,F_OK))!=-1)
  2542. {
  2543. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2544. sprintf(str,"rm -f %s",filenmae);
  2545. system(str);
  2546. }
  2547. }
  2548. #if 1 // for TempStopTransaction
  2549. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2550. {
  2551. checkTempStopTransaction(gun_index);
  2552. }
  2553. #endif
  2554. }
  2555. }
  2556. }
  2557. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2558. {
  2559. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2560. {
  2561. tempIndex = ((gun_index==2) ? 1: 0);
  2562. }
  2563. else
  2564. {
  2565. tempIndex = gun_index;
  2566. }
  2567. for (int index = 0; index < CCS_QUANTITY; index++)
  2568. {
  2569. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2570. {
  2571. 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]*/ )
  2572. {
  2573. // Sent unplug message for California pricing logic
  2574. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].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. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2584. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2585. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2586. statusModeChage[gun_index] = TRUE;
  2587. }
  2588. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].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.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2600. {
  2601. checkTempStopTransaction(gun_index);
  2602. }
  2603. #endif
  2604. }
  2605. }
  2606. }
  2607. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2608. {
  2609. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2610. {
  2611. tempIndex = ((gun_index==2) ? 1: 0);
  2612. }
  2613. else
  2614. {
  2615. tempIndex = gun_index;
  2616. }
  2617. for (int index = 0; index < GB_QUANTITY; index++)
  2618. {
  2619. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2620. {
  2621. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  2622. {
  2623. // Sent unplug message for California pricing logic
  2624. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  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. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2634. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2635. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2636. statusModeChage[gun_index] = TRUE;
  2637. }
  2638. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[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.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2650. {
  2651. checkTempStopTransaction(gun_index);
  2652. }
  2653. #endif
  2654. }
  2655. }
  2656. }
  2657. else if(gunType[gun_index] == GUN_TYPE_DO)
  2658. {
  2659. tempIndex = gun_index;
  2660. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2661. {
  2662. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2663. {
  2664. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  2665. {
  2666. // Sent unplug message for California pricing logic
  2667. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  2668. {
  2669. uint8_t ts[20];
  2670. getNowDatetime(ts);
  2671. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2672. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2673. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2674. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2675. }
  2676. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  2677. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  2678. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2679. statusModeChage[gun_index] = TRUE;
  2680. }
  2681. 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
  2682. {
  2683. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2684. if((access(filenmae,F_OK))!=-1)
  2685. {
  2686. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2687. sprintf(str,"rm -f %s",filenmae);
  2688. system(str);
  2689. }
  2690. }
  2691. #if 1 // for TempStopTransaction
  2692. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2693. {
  2694. checkTempStopTransaction(gun_index);
  2695. }
  2696. #endif
  2697. }
  2698. }
  2699. }
  2700. else
  2701. {
  2702. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2703. {
  2704. tempIndex = 2;
  2705. }
  2706. else
  2707. {
  2708. tempIndex = gun_index;
  2709. }
  2710. for (int index = 0; index < AC_QUANTITY; index++)
  2711. {
  2712. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2713. {
  2714. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  2715. {
  2716. // Sent unplug message for California pricing logic
  2717. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)
  2718. {
  2719. uint8_t ts[20];
  2720. getNowDatetime(ts);
  2721. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2722. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2723. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2724. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2725. }
  2726. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2727. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2728. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2729. statusModeChage[gun_index] = TRUE;
  2730. }
  2731. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2732. {
  2733. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2734. if((access(filenmae,F_OK))!=-1)
  2735. {
  2736. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2737. sprintf(str,"rm -f %s",filenmae);
  2738. system(str);
  2739. }
  2740. }
  2741. #if 1 // for TempStopTransaction
  2742. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2743. {
  2744. checkTempStopTransaction(gun_index);
  2745. }
  2746. #endif
  2747. }
  2748. }// END
  2749. }
  2750. if(isWebsocketSendable && (server_sign == TRUE) &&
  2751. (
  2752. (statusModeChage[gun_index] == TRUE) ||
  2753. //((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index))) ||
  2754. ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 5))
  2755. )
  2756. )
  2757. {
  2758. if(SystemInitial > 0)
  2759. SystemInitial -= 1;
  2760. sendStatusNotificationRequest(gun_index);
  2761. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2762. statusModeChage[gun_index] = FALSE;
  2763. }
  2764. //==============================================
  2765. // Meter report
  2766. //==============================================
  2767. // Trigger MeterValue
  2768. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  2769. {
  2770. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  2771. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  2772. }
  2773. // ClockAlign MeterValue
  2774. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  2775. {
  2776. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2777. {
  2778. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2779. {
  2780. tempIndex = ((gun_index==2) ? 1: 0);
  2781. }
  2782. else
  2783. {
  2784. tempIndex = gun_index;
  2785. }
  2786. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2787. {
  2788. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2789. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2790. {
  2791. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2792. {
  2793. reqClockAlignMeter[gun_index] = 1;
  2794. }
  2795. }
  2796. }// End for CHAdeMO
  2797. }
  2798. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2799. {
  2800. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2801. {
  2802. tempIndex = ((gun_index==2) ? 1: 0);
  2803. }
  2804. else
  2805. {
  2806. tempIndex = gun_index;
  2807. }
  2808. for (int index = 0; index < CCS_QUANTITY; index++)
  2809. {
  2810. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2811. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2812. {
  2813. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2814. {
  2815. reqClockAlignMeter[gun_index] = 1;
  2816. }
  2817. }
  2818. } // End for CCS
  2819. }
  2820. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2821. {
  2822. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2823. {
  2824. tempIndex = ((gun_index==2) ? 1: 0);
  2825. }
  2826. else
  2827. {
  2828. tempIndex = gun_index;
  2829. }
  2830. for (int index = 0; index < GB_QUANTITY; index++)
  2831. {
  2832. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2833. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2834. {
  2835. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2836. {
  2837. reqClockAlignMeter[gun_index] = 1;
  2838. }
  2839. }
  2840. }// End for GB
  2841. }
  2842. else if(gunType[gun_index] == GUN_TYPE_DO)
  2843. {
  2844. tempIndex = gun_index;
  2845. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2846. {
  2847. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2848. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2849. {
  2850. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_CHARGING)
  2851. {
  2852. reqClockAlignMeter[gun_index] = 1;
  2853. }
  2854. }
  2855. }
  2856. }
  2857. else
  2858. {
  2859. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2860. {
  2861. tempIndex = 2;
  2862. }
  2863. else
  2864. {
  2865. tempIndex = gun_index;
  2866. }
  2867. for (int index = 0; index < AC_QUANTITY; index++)
  2868. {
  2869. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2870. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2871. {
  2872. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2873. {
  2874. reqClockAlignMeter[gun_index] = 1;
  2875. }
  2876. }
  2877. }//End for AC
  2878. }
  2879. if(reqClockAlignMeter[gun_index] == 1)
  2880. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  2881. }
  2882. // Sample period MeterValue
  2883. if((((time((time_t*)NULL) - clientTime.MeterValues[gun_index]) > (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1))))
  2884. {
  2885. //check Transaction active
  2886. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2887. {
  2888. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2889. {
  2890. tempIndex = ((gun_index==2) ? 1: 0);
  2891. }
  2892. else
  2893. {
  2894. tempIndex = gun_index;
  2895. }
  2896. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2897. {
  2898. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2899. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2900. {
  2901. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2902. {
  2903. reqSampleMeter[gun_index] = 1;
  2904. }
  2905. }
  2906. }// End for CHAdeMO
  2907. }
  2908. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2909. {
  2910. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2911. {
  2912. tempIndex = ((gun_index==2) ? 1: 0);
  2913. }
  2914. else
  2915. {
  2916. tempIndex = gun_index;
  2917. }
  2918. for (int index = 0; index < CCS_QUANTITY; index++)
  2919. {
  2920. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2921. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2922. {
  2923. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2924. {
  2925. reqSampleMeter[gun_index] = 1;
  2926. }
  2927. }
  2928. } // End for CCS
  2929. }
  2930. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2931. {
  2932. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2933. {
  2934. tempIndex = ((gun_index==2) ? 1: 0);
  2935. }
  2936. else
  2937. {
  2938. tempIndex = gun_index;
  2939. }
  2940. for (int index = 0; index < GB_QUANTITY; index++)
  2941. {
  2942. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2943. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2944. {
  2945. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2946. {
  2947. reqSampleMeter[gun_index] = 1;
  2948. }
  2949. }
  2950. }// End for GB
  2951. }
  2952. else if(gunType[gun_index] == GUN_TYPE_DO)
  2953. {
  2954. tempIndex = gun_index;
  2955. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2956. {
  2957. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2958. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2959. {
  2960. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  2961. {
  2962. reqSampleMeter[gun_index] = 1;
  2963. }
  2964. }
  2965. }
  2966. }
  2967. else
  2968. {
  2969. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2970. {
  2971. tempIndex = 2;
  2972. }
  2973. else
  2974. {
  2975. tempIndex = gun_index;
  2976. }
  2977. for (int index = 0; index < AC_QUANTITY; index++)
  2978. {
  2979. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2980. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2981. {
  2982. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  2983. {
  2984. reqSampleMeter[gun_index] = 1;
  2985. }
  2986. }
  2987. }//End for AC
  2988. }
  2989. if(reqSampleMeter[gun_index] == 1)
  2990. {
  2991. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  2992. storeTempStopTransaction(gun_index);
  2993. }
  2994. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2995. }
  2996. //==============================================
  2997. // Check Connector reserved
  2998. //==============================================
  2999. //===============================
  3000. // Check if Reserve is expired
  3001. //===============================
  3002. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  3003. {
  3004. double diff_t;
  3005. struct tm tp;
  3006. // current time
  3007. time_t t = time(NULL);
  3008. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  3009. tp.tm_isdst = -1;
  3010. time_t utc = mktime(&tp);
  3011. diff_t = difftime(utc, t);
  3012. if(diff_t <= 0)
  3013. {
  3014. DEBUG_INFO("reserve expired.\n");
  3015. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  3016. }
  3017. }//END OF Check if Reserve is expired
  3018. //==========================================
  3019. // csu trigger FirmwareStatusNotificationReq
  3020. //==========================================
  3021. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  3022. {
  3023. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  3024. }
  3025. //==========================================
  3026. // csu trigger DiagnosticsStatusNotificationReq
  3027. //==========================================
  3028. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  3029. {
  3030. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  3031. }
  3032. //==========================================
  3033. // csu trigger CancelReservationConf
  3034. //==========================================
  3035. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  3036. {
  3037. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  3038. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  3039. }
  3040. //==========================================
  3041. // csu trigger ChangeAvailabilityConf
  3042. //==========================================
  3043. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  3044. {
  3045. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  3046. }
  3047. //==========================================
  3048. // csu trigger UnlockConnectorConf
  3049. //==========================================
  3050. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  3051. {
  3052. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  3053. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  3054. }
  3055. //==========================================
  3056. // csu trigger ReserveNowConf
  3057. //==========================================
  3058. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  3059. {
  3060. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  3061. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  3062. }
  3063. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  3064. {
  3065. sendSignCertificateRequest();
  3066. }
  3067. }
  3068. }
  3069. //==========================================
  3070. // send request routine
  3071. //==========================================
  3072. int sendAuthorizeRequest(int gun_index)
  3073. {
  3074. mtrace();
  3075. int result = FAIL;
  3076. char message[100]={0};
  3077. char guid[37];
  3078. char tempdata[65]={0};
  3079. DEBUG_INFO("sendAuthorizeRequest...\n");
  3080. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  3081. //Local Authorize
  3082. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  3083. {
  3084. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  3085. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  3086. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  3087. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  3088. result = PASS;
  3089. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3090. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3091. authorizeRetryTimes = 0;
  3092. return result;
  3093. }
  3094. 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))||
  3095. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  3096. {
  3097. // Query from cache
  3098. DEBUG_INFO("Authorize from cache.\n");
  3099. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3100. // Query from list
  3101. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3102. {
  3103. DEBUG_INFO("Authorize from list.\n");
  3104. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3105. }
  3106. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3107. {
  3108. if(strcmp(idTagQuery.idTagstr,"") == 0)
  3109. {
  3110. DEBUG_INFO("off-line Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  3111. }
  3112. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  3113. {
  3114. DEBUG_INFO("off-line Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  3115. }
  3116. DEBUG_INFO("off-line Local Authorization Fail !!!!\n");
  3117. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3118. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3119. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  3120. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  3121. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3122. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3123. authorizeRetryTimes = 0;
  3124. return result;
  3125. }
  3126. else
  3127. {
  3128. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  3129. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3130. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3131. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  3132. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  3133. else
  3134. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  3135. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  3136. result = PASS;
  3137. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3138. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3139. authorizeRetryTimes = 0;
  3140. return result;
  3141. }
  3142. }
  3143. //initialize struct Authorize
  3144. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  3145. //get data from shared memory
  3146. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3147. random_uuid(guid);
  3148. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  3149. LWS_Send(message);
  3150. sprintf(tempdata, "Authorize,%d", gun_index);
  3151. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3152. {
  3153. result = PASS;
  3154. DEBUG_INFO("Authorize mapItem pass\n");
  3155. }
  3156. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3157. return result;
  3158. }
  3159. int sendBootNotificationRequest(void)
  3160. {
  3161. mtrace();
  3162. int result = FAIL;
  3163. char message[500]={0}, payload[700]={0};
  3164. char guid[37]={0};
  3165. char tempdata[65]={0};
  3166. // Fill BootNotification fields
  3167. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  3168. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  3169. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  3170. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3171. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  3172. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  3173. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  3174. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  3175. ShmOCPP16Data->ChargeBoxId
  3176. ,ShmSysConfigAndInfo->SysConfig.ModelName
  3177. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  3178. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  3179. ,ShmOCPP16Data->BootNotification.CpFwVersion
  3180. ,ShmOCPP16Data->BootNotification.CpIccid
  3181. ,ShmOCPP16Data->BootNotification.CpImsi);
  3182. random_uuid(guid);
  3183. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  3184. LWS_Send(message);
  3185. sprintf(tempdata, "BootNotification,0");
  3186. 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*/)
  3187. {
  3188. result = PASS;
  3189. }
  3190. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3191. strcpy(queuedata,message);
  3192. return result;
  3193. }
  3194. int sendDataTransferRequest(int gun_index)
  3195. {
  3196. mtrace();
  3197. char message[1000]={0};
  3198. char guid[37]={0};
  3199. char tempdata[65]={0};
  3200. int result = FAIL;
  3201. random_uuid(guid);
  3202. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  3203. MESSAGE_TYPE_CALL,
  3204. guid,
  3205. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  3206. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  3207. ShmOCPP16Data->DataTransfer[gun_index].Data);
  3208. LWS_Send(message);
  3209. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  3210. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3211. {
  3212. result = PASS;
  3213. DEBUG_INFO("DataTransfer mapItem pass\n");
  3214. }
  3215. return result;
  3216. }
  3217. int sendDiagnosticsStatusNotificationRequest(char *status)
  3218. {
  3219. mtrace();
  3220. int result = FAIL;
  3221. char message[110]={0};
  3222. char guid[37]={0};
  3223. char tempdata[65]={0};
  3224. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  3225. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  3226. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  3227. random_uuid(guid);
  3228. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  3229. LWS_SendNow(message);
  3230. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  3231. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3232. {
  3233. result = PASS;
  3234. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  3235. }
  3236. //#ifdef SystemLogMessage
  3237. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  3238. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3239. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  3240. //#endif
  3241. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  3242. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  3243. //record status
  3244. if(strcmp(status,"Idle")==0)
  3245. {
  3246. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  3247. }
  3248. else if(strcmp(status,"Uploaded")==0)
  3249. {
  3250. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  3251. }
  3252. else if(strcmp(status,"UploadFailed")==0)
  3253. {
  3254. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  3255. }
  3256. else if(strcmp(status,"Uploading")==0)
  3257. {
  3258. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  3259. }
  3260. return result;
  3261. }
  3262. int sendFirmwareStatusNotificationRequest(char *status)
  3263. {
  3264. mtrace();
  3265. int result = FAIL;
  3266. char message[110]={0};
  3267. char guid[37]={0};
  3268. char tempdata[65]={0};
  3269. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  3270. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  3271. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  3272. random_uuid(guid);
  3273. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  3274. LWS_SendNow(message);
  3275. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  3276. 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*/)
  3277. {
  3278. result = PASS;
  3279. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  3280. }
  3281. //#ifdef SystemLogMessage
  3282. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  3283. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3284. //#endif
  3285. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  3286. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  3287. //record status
  3288. if(strcmp(status,"Downloaded")==0)
  3289. {
  3290. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  3291. }
  3292. else if(strcmp(status,"DownloadFailed")==0)
  3293. {
  3294. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  3295. }
  3296. else if(strcmp(status,"Downloading")==0)
  3297. {
  3298. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  3299. }
  3300. else if(strcmp(status,"Idle")==0)
  3301. {
  3302. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  3303. }
  3304. else if(strcmp(status,"InstallationFailed")==0)
  3305. {
  3306. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  3307. }
  3308. else if(strcmp(status,"Installing")==0)
  3309. {
  3310. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  3311. }
  3312. else if(strcmp(status,"Installed")==0)
  3313. {
  3314. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  3315. }
  3316. return result;
  3317. }
  3318. int sendHeartbeatRequest(int gun_index)
  3319. {
  3320. mtrace();
  3321. int result = FAIL;
  3322. char message[80]={0};
  3323. char guid[37]={0};
  3324. char tempdata[65]={0};
  3325. random_uuid(guid);
  3326. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  3327. , MESSAGE_TYPE_CALL
  3328. , guid );
  3329. LWS_Send(message);
  3330. sprintf(tempdata, "Heartbeat,%d", 0);
  3331. 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*/)
  3332. {
  3333. result = PASS;
  3334. }
  3335. return result;
  3336. }
  3337. int sendStartTransactionRequest(int gun_index)
  3338. {
  3339. mtrace();
  3340. int result = FAIL;
  3341. char message[250]={0};
  3342. char guid[37]={0};
  3343. struct timeval tmnow;
  3344. struct tm *tm;
  3345. char buf[28];//, usec_buf[6];
  3346. char tempdata[65]={0};
  3347. int tempIndex = 0;
  3348. DEBUG_INFO("sendStartTransactionRequest...\n");
  3349. gettimeofday(&tmnow, NULL);
  3350. time_t t;
  3351. t = time(NULL);
  3352. /*UTC time and date*/
  3353. tm = gmtime(&t);
  3354. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3355. #if 0 // remove temporally
  3356. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3357. strcat(buf,".");
  3358. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3359. strcat(buf,usec_buf);
  3360. #endif
  3361. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  3362. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  3363. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3364. // clear StartTransaction Response
  3365. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  3366. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  3367. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  3368. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  3369. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3370. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3371. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3372. {
  3373. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3374. {
  3375. tempIndex = ((gun_index==2) ? 1: 0);
  3376. }
  3377. else
  3378. {
  3379. tempIndex = gun_index;
  3380. }
  3381. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3382. {
  3383. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3384. {
  3385. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3386. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  3387. }
  3388. }
  3389. }
  3390. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3391. {
  3392. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3393. {
  3394. tempIndex = ((gun_index==2) ? 1: 0);
  3395. }
  3396. else
  3397. {
  3398. tempIndex = gun_index;
  3399. }
  3400. for (int index = 0; index < CCS_QUANTITY; index++)
  3401. {
  3402. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3403. {
  3404. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3405. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  3406. }
  3407. }
  3408. }
  3409. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3410. {
  3411. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3412. {
  3413. tempIndex = ((gun_index==2) ? 1: 0);
  3414. }
  3415. else
  3416. {
  3417. tempIndex = gun_index;
  3418. }
  3419. for (int index = 0; index < GB_QUANTITY; index++)
  3420. {
  3421. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3422. {
  3423. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3424. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  3425. }
  3426. }
  3427. }
  3428. else if(gunType[gun_index] == GUN_TYPE_DO)
  3429. {
  3430. tempIndex = gun_index;
  3431. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3432. {
  3433. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3434. {
  3435. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3436. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  3437. }
  3438. }
  3439. }
  3440. else
  3441. {
  3442. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3443. {
  3444. tempIndex = 2;
  3445. }
  3446. else
  3447. {
  3448. tempIndex = gun_index;
  3449. }
  3450. for (int index = 0; index < AC_QUANTITY; index++)
  3451. {
  3452. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3453. {
  3454. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3455. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  3456. }
  3457. }
  3458. }
  3459. random_uuid(guid);
  3460. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  3461. {
  3462. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  3463. , gun_index +1
  3464. , MESSAGE_TYPE_CALL
  3465. , guid
  3466. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3467. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3468. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3469. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3470. }
  3471. else
  3472. {
  3473. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  3474. , gun_index +1
  3475. , MESSAGE_TYPE_CALL
  3476. , guid
  3477. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3478. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3479. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3480. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  3481. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3482. }
  3483. #if 1
  3484. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  3485. 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*/)
  3486. {
  3487. result = PASS;
  3488. }
  3489. #endif
  3490. strcpy(queuedata, message);
  3491. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3492. OCPP_insert_transaction_msg(YES, queuedata);
  3493. return result;
  3494. }
  3495. int sendStatusNotificationRequest(int gun_index)
  3496. {
  3497. mtrace();
  3498. int result = FAIL;
  3499. char message[600]={0};
  3500. char guid[37];
  3501. int currentStatus = 0;
  3502. struct timeval tmnow;
  3503. struct tm *tm;
  3504. char buf[28];//, usec_buf[6];
  3505. char tempdata[65]={0};
  3506. int tempIndex = 0;
  3507. uint8_t isStateChanged = TRUE;
  3508. DEBUG_INFO("sendStatusNotificationRequest...\n");
  3509. gettimeofday(&tmnow, NULL);
  3510. time_t t;
  3511. t = time(NULL);
  3512. /*UTC time and date*/
  3513. tm = gmtime(&t);
  3514. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3515. #if 0 // remove temporally
  3516. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3517. strcat(buf,".");
  3518. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3519. strcat(buf,usec_buf);
  3520. #endif
  3521. printf("%s",buf);
  3522. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  3523. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  3524. // it's option
  3525. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  3526. /*
  3527. enum _SYSTEM_STATUS
  3528. {
  3529. S_BOOTING = 0,
  3530. S_IDLE, = 1
  3531. S_AUTHORIZING, =2
  3532. S_REASSIGN_CHECK, =3
  3533. S_REASSIGN, =4
  3534. S_PRECHARGE, =5
  3535. S_PREPARING_FOR_EV, =6
  3536. S_PREPARING_FOR_EVSE, =7
  3537. S_CHARGING, =8
  3538. S_TERMINATING, =9
  3539. S_COMPLETE, =10
  3540. S_ALARM, =11
  3541. S_FAULT =12
  3542. }
  3543. */
  3544. //check Transaction active
  3545. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3546. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3547. {
  3548. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3549. {
  3550. tempIndex = ((gun_index==2) ? 1: 0);
  3551. }
  3552. else
  3553. {
  3554. tempIndex = gun_index;
  3555. }
  3556. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3557. {
  3558. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  3559. {
  3560. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  3561. {
  3562. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3563. {
  3564. currentStatus = Preparing; //OCPP Status: Preparing
  3565. }
  3566. else
  3567. {
  3568. currentStatus = Available; //OCPP Status: Available
  3569. }
  3570. }
  3571. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3572. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3573. ) //S_PRECHARGE
  3574. {
  3575. currentStatus = Preparing; //OCPP Status: Preparing
  3576. }
  3577. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3578. {
  3579. currentStatus = Charging; //OCPP Status: Charging
  3580. }
  3581. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3582. {
  3583. currentStatus = Finishing; //OCPP Status: Finishing
  3584. }
  3585. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3586. {
  3587. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3588. }
  3589. 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
  3590. {
  3591. currentStatus = Unavailable; //OCPP Status: Unavailable
  3592. }
  3593. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3594. {
  3595. currentStatus = Faulted; //OCPP Status: Faulted
  3596. }
  3597. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3598. {
  3599. currentStatus = Reserved; //OCPP Status: Reserved
  3600. }
  3601. } //end of the same index
  3602. }//end of for CHAdeMO_QUANTITY
  3603. }
  3604. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3605. {
  3606. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3607. {
  3608. tempIndex = ((gun_index==2) ? 1: 0);
  3609. }
  3610. else
  3611. {
  3612. tempIndex = gun_index;
  3613. }
  3614. for (int index = 0; index < CCS_QUANTITY; index++)
  3615. {
  3616. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3617. {
  3618. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3619. {
  3620. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3621. {
  3622. currentStatus = Preparing; //OCPP Status: Preparing
  3623. }
  3624. else
  3625. {
  3626. currentStatus = Available; //OCPP Status: Available
  3627. }
  3628. }
  3629. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3630. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3631. ) //S_PRECHARGE
  3632. {
  3633. currentStatus = Preparing; //OCPP Status: Preparing
  3634. }
  3635. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3636. {
  3637. currentStatus = Charging; //OCPP Status: Charging
  3638. }
  3639. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3640. {
  3641. currentStatus = Finishing; //OCPP Status: Finishing
  3642. }
  3643. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3644. {
  3645. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3646. }
  3647. 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
  3648. {
  3649. currentStatus = Unavailable; //OCPP Status : Unavailable
  3650. }
  3651. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3652. {
  3653. currentStatus = Faulted; //OCPP Status: Faulted
  3654. }
  3655. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3656. {
  3657. currentStatus = Reserved; //OCPP Status: Reserved
  3658. }
  3659. } //end of the same index
  3660. } // end of for CCS_QUANTITY
  3661. }
  3662. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3663. {
  3664. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3665. {
  3666. tempIndex = ((gun_index==2) ? 1: 0);
  3667. }
  3668. else
  3669. {
  3670. tempIndex = gun_index;
  3671. }
  3672. for (int index = 0; index < GB_QUANTITY; index++)
  3673. {
  3674. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3675. {
  3676. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3677. {
  3678. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3679. {
  3680. currentStatus = Preparing; //OCPP Status: Preparing
  3681. }
  3682. else
  3683. {
  3684. currentStatus = Available; //OCPP Status: Available
  3685. }
  3686. }
  3687. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3688. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3689. ) //S_PRECHARGE
  3690. {
  3691. currentStatus = Preparing; //OCPP Status: Preparing
  3692. }
  3693. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3694. {
  3695. currentStatus = Charging; //OCPP Status: Charging
  3696. }
  3697. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3698. {
  3699. currentStatus = Finishing; //OCPP Status: Finishing
  3700. }
  3701. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3702. {
  3703. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3704. }
  3705. 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
  3706. {
  3707. currentStatus = Unavailable; //OCPP Status: Unavailable
  3708. }
  3709. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3710. {
  3711. currentStatus = Faulted; //OCPP Status: Faulted
  3712. }
  3713. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3714. {
  3715. currentStatus = Reserved; //OCPP Status: Reserved
  3716. }
  3717. } //end of the same index
  3718. } // end of for GB_QUANTITY
  3719. }
  3720. else if(gunType[gun_index] == GUN_TYPE_DO)
  3721. {
  3722. tempIndex = gun_index;
  3723. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3724. {
  3725. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3726. {
  3727. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3728. {
  3729. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3730. {
  3731. currentStatus = Preparing; //OCPP Status: Preparing
  3732. }
  3733. else
  3734. {
  3735. currentStatus = Available; //OCPP Status: Available
  3736. }
  3737. }
  3738. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3739. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3740. ) //S_PRECHARGE
  3741. {
  3742. currentStatus = Preparing; //OCPP Status: Preparing
  3743. }
  3744. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3745. {
  3746. currentStatus = Charging; //OCPP Status: Charging
  3747. }
  3748. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3749. {
  3750. currentStatus = Finishing; //OCPP Status: Finishing
  3751. }
  3752. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3753. {
  3754. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3755. }
  3756. 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
  3757. {
  3758. currentStatus = Unavailable; //OCPP Status: Unavailable
  3759. }
  3760. 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
  3761. {
  3762. currentStatus = Faulted; //OCPP Status: Faulted
  3763. }
  3764. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3765. {
  3766. currentStatus = Reserved; //OCPP Status: Reserved
  3767. }
  3768. } //end of the same index
  3769. }
  3770. }
  3771. else
  3772. {
  3773. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3774. {
  3775. tempIndex = 2;
  3776. }
  3777. else
  3778. {
  3779. tempIndex = gun_index;
  3780. }
  3781. for (int index = 0; index < AC_QUANTITY; index++)
  3782. {
  3783. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3784. {
  3785. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3786. {
  3787. 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))
  3788. {
  3789. currentStatus = Preparing; //OCPP Status: Preparing
  3790. }
  3791. else
  3792. {
  3793. currentStatus = Available; //OCPP Status: Available
  3794. }
  3795. }
  3796. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  3797. {
  3798. currentStatus = Preparing; //OCPP Status: Preparing
  3799. }
  3800. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3801. {
  3802. currentStatus = Charging; //OCPP Status: Charging
  3803. }
  3804. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3805. {
  3806. currentStatus = Finishing; //OCPP Status: Finishing
  3807. }
  3808. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3809. {
  3810. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3811. }
  3812. 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
  3813. {
  3814. currentStatus = Unavailable; //OCPP Status: Unavailable
  3815. }
  3816. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3817. {
  3818. currentStatus = Faulted; //OCPP Status: Faulted
  3819. }
  3820. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3821. {
  3822. currentStatus = Reserved; //OCPP Status: Reserved
  3823. }
  3824. }//end of the same index
  3825. }//end of for AC_QUANTITY
  3826. }
  3827. //it's option
  3828. if((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) &&
  3829. !ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq)
  3830. {
  3831. isStateChanged = FALSE;
  3832. }
  3833. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  3834. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3835. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3836. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3837. random_uuid(guid);
  3838. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3839. , MESSAGE_TYPE_CALL
  3840. , guid
  3841. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3842. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3843. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3844. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3845. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3846. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3847. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3848. if((server_sign == TRUE) && isStateChanged)
  3849. {
  3850. LWS_Send(message);
  3851. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3852. 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*/)
  3853. {
  3854. //DEBUG_ERROR("statusNotification mapitem pass");
  3855. result = PASS;
  3856. }
  3857. }
  3858. else
  3859. {
  3860. result = PASS;
  3861. }
  3862. return result;
  3863. }
  3864. int sendStopTransactionRequest(int gun_index)
  3865. {
  3866. mtrace();
  3867. int result = FAIL;
  3868. //char message[1500]={0};
  3869. char guid[37]={0};
  3870. char tempdata[65]={0};
  3871. int tempIndex = 0;
  3872. char TempStopTransaction[256];
  3873. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  3874. //int idx_sample=0;
  3875. DEBUG_INFO("sendStopTransactionRequest \n");
  3876. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3877. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  3878. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  3879. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3880. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3881. {
  3882. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3883. {
  3884. tempIndex = ((gun_index==2) ? 1: 0);
  3885. }
  3886. else
  3887. {
  3888. tempIndex = gun_index;
  3889. }
  3890. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3891. {
  3892. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3893. {
  3894. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3895. }
  3896. }// END OF CHAdeMO_QUANTITY
  3897. }
  3898. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3899. {
  3900. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3901. {
  3902. tempIndex = ((gun_index==2) ? 1: 0);
  3903. }
  3904. else
  3905. {
  3906. tempIndex = gun_index;
  3907. }
  3908. for (int index = 0; index < CCS_QUANTITY; index++)
  3909. {
  3910. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3911. {
  3912. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3913. }
  3914. }// END OF CCS_QUANTITY
  3915. }
  3916. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3917. {
  3918. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3919. {
  3920. tempIndex = ((gun_index==2) ? 1: 0);
  3921. }
  3922. else
  3923. {
  3924. tempIndex = gun_index;
  3925. }
  3926. for (int index = 0; index < GB_QUANTITY; index++)
  3927. {
  3928. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3929. {
  3930. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3931. }
  3932. }// END OF GB_QUANTITY
  3933. }
  3934. else if(gunType[gun_index] == GUN_TYPE_DO)
  3935. {
  3936. tempIndex = gun_index;
  3937. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3938. {
  3939. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3940. {
  3941. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3942. }
  3943. }// END OF GB_QUANTITY
  3944. }
  3945. else
  3946. {
  3947. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3948. {
  3949. tempIndex = 2;
  3950. }
  3951. else
  3952. {
  3953. tempIndex = gun_index;
  3954. }
  3955. for (int index = 0; index < AC_QUANTITY; index++)
  3956. {
  3957. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3958. {
  3959. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3960. }
  3961. }// END OF AC_QUANTITY
  3962. }
  3963. //====================================== Stop Transaction Time =====================================================
  3964. struct timeval tmnow;
  3965. struct tm *tm;
  3966. char buf[28];//, usec_buf[6];
  3967. gettimeofday(&tmnow, NULL);
  3968. time_t t;
  3969. t = time(NULL);
  3970. /*UTC time and date*/
  3971. tm = gmtime(&t);
  3972. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3973. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  3974. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  3975. random_uuid(guid);
  3976. /***********************************transactionData******************************************************/
  3977. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  3978. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  3979. //=================================
  3980. // Transaction_Begin
  3981. //=================================
  3982. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  3983. {
  3984. //============================================ Energy.Active.Import.Interval ================================
  3985. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  3986. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  3987. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  3988. 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*/]);
  3989. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3990. 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))
  3991. {
  3992. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  3993. }
  3994. else
  3995. {
  3996. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  3997. }
  3998. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  3999. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4000. }
  4001. //=================================
  4002. // Transaction_End
  4003. //=================================
  4004. // ================================= Current.Import L1 ===============================================
  4005. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4006. {
  4007. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  4008. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4009. {
  4010. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4011. {
  4012. tempIndex = ((gun_index==2) ? 1: 0);
  4013. }
  4014. else
  4015. {
  4016. tempIndex = gun_index;
  4017. }
  4018. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4019. {
  4020. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4021. {
  4022. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4023. }
  4024. }// End of for CHAdeMO_QUANTITY
  4025. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4026. }
  4027. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4028. {
  4029. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4030. {
  4031. tempIndex = ((gun_index==2) ? 1: 0);
  4032. }
  4033. else
  4034. {
  4035. tempIndex = gun_index;
  4036. }
  4037. for (int index = 0; index < CCS_QUANTITY; index++)
  4038. {
  4039. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4040. {
  4041. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4042. }
  4043. }// End of for CCS_QUANTITY
  4044. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4045. }
  4046. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4047. {
  4048. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4049. {
  4050. tempIndex = ((gun_index==2) ? 1: 0);
  4051. }
  4052. else
  4053. {
  4054. tempIndex = gun_index;
  4055. }
  4056. for (int index = 0; index < GB_QUANTITY; index++)
  4057. {
  4058. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4059. {
  4060. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4061. }
  4062. }// End of for GB_QUANTITY
  4063. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4064. }
  4065. else if(gunType[gun_index] == GUN_TYPE_DO)
  4066. {
  4067. tempIndex = gun_index;
  4068. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4069. {
  4070. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4071. {
  4072. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4073. }
  4074. }
  4075. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4076. }
  4077. else
  4078. {
  4079. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4080. {
  4081. tempIndex = 2;
  4082. }
  4083. else
  4084. {
  4085. tempIndex = gun_index;
  4086. }
  4087. for (int index = 0; index < AC_QUANTITY; index++)
  4088. {
  4089. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4090. {
  4091. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  4092. }
  4093. }// End of for AC_QUANTITY
  4094. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  4095. }
  4096. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4097. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  4098. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  4099. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  4100. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4101. }
  4102. // ================================= Energy.Active.Import.Interval ==============================================
  4103. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4104. {
  4105. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4106. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4107. {
  4108. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4109. {
  4110. tempIndex = ((gun_index==2) ? 1: 0);
  4111. }
  4112. else
  4113. {
  4114. tempIndex = gun_index;
  4115. }
  4116. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4117. {
  4118. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4119. {
  4120. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4121. }
  4122. }// END OF CHAdeMO_QUANTITY
  4123. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4124. }
  4125. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4126. {
  4127. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4128. {
  4129. tempIndex = ((gun_index==2) ? 1: 0);
  4130. }
  4131. else
  4132. {
  4133. tempIndex = gun_index;
  4134. }
  4135. for (int index = 0; index < CCS_QUANTITY; index++)
  4136. {
  4137. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4138. {
  4139. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4140. }
  4141. }// END OF CCS_QUANTITY
  4142. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4143. }
  4144. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4145. {
  4146. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4147. {
  4148. tempIndex = ((gun_index==2) ? 1: 0);
  4149. }
  4150. else
  4151. {
  4152. tempIndex = gun_index;
  4153. }
  4154. for (int index = 0; index < GB_QUANTITY; index++)
  4155. {
  4156. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4157. {
  4158. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4159. }
  4160. }// END OF GB_QUANTITY
  4161. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4162. }
  4163. else if(gunType[gun_index] == GUN_TYPE_DO)
  4164. {
  4165. tempIndex = gun_index;
  4166. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4167. {
  4168. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4169. {
  4170. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4171. }
  4172. }
  4173. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4174. }
  4175. else
  4176. {
  4177. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4178. {
  4179. tempIndex = 2;
  4180. }
  4181. else
  4182. {
  4183. tempIndex = gun_index;
  4184. }
  4185. for (int index = 0; index < AC_QUANTITY; index++)
  4186. {
  4187. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4188. {
  4189. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4190. }
  4191. }// END OF AC_QUANTITY
  4192. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  4193. }
  4194. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4195. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  4196. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  4197. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  4198. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4199. }
  4200. //=================================== Power.Active.Import ==================================================
  4201. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  4202. {
  4203. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4204. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4205. {
  4206. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4207. {
  4208. tempIndex = ((gun_index==2) ? 1: 0);
  4209. }
  4210. else
  4211. {
  4212. tempIndex = gun_index;
  4213. }
  4214. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4215. {
  4216. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4217. {
  4218. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4219. }
  4220. } // End for CHAdeMO_QUANTITY
  4221. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4222. }
  4223. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4224. {
  4225. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4226. {
  4227. tempIndex = ((gun_index==2) ? 1: 0);
  4228. }
  4229. else
  4230. {
  4231. tempIndex = gun_index;
  4232. }
  4233. for (int index = 0; index < CCS_QUANTITY; index++)
  4234. {
  4235. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4236. {
  4237. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4238. }
  4239. } // END for CCS_QUANTITY
  4240. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4241. }
  4242. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4243. {
  4244. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4245. {
  4246. tempIndex = ((gun_index==2) ? 1: 0);
  4247. }
  4248. else
  4249. {
  4250. tempIndex = gun_index;
  4251. }
  4252. for (int index = 0; index < GB_QUANTITY; index++)
  4253. {
  4254. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4255. {
  4256. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4257. }
  4258. }// END for GB_QUANTITY
  4259. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4260. }
  4261. else if(gunType[gun_index] == GUN_TYPE_DO)
  4262. {
  4263. tempIndex = gun_index;
  4264. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4265. {
  4266. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4267. {
  4268. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4269. }
  4270. }
  4271. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4272. }
  4273. else
  4274. {
  4275. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4276. {
  4277. tempIndex = 2;
  4278. }
  4279. else
  4280. {
  4281. tempIndex = gun_index;
  4282. }
  4283. for (int index = 0; index < AC_QUANTITY; index++)
  4284. {
  4285. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4286. {
  4287. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4288. }
  4289. } // END for AC_QUANTITY
  4290. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  4291. }
  4292. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4293. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  4294. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  4295. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  4296. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  4297. }
  4298. //============================ Voltage L1 ====================================
  4299. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4300. {
  4301. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4302. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4303. {
  4304. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4305. {
  4306. tempIndex = ((gun_index==2) ? 1: 0);
  4307. }
  4308. else
  4309. {
  4310. tempIndex = gun_index;
  4311. }
  4312. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4313. {
  4314. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4315. {
  4316. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4317. }
  4318. } // END OF FOR CHAdeMO_QUANTITY
  4319. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4320. }
  4321. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4322. {
  4323. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4324. {
  4325. tempIndex = ((gun_index==2) ? 1: 0);
  4326. }
  4327. else
  4328. {
  4329. tempIndex = gun_index;
  4330. }
  4331. for (int index = 0; index < CCS_QUANTITY; index++)
  4332. {
  4333. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4334. {
  4335. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4336. }
  4337. } // END OF FOR CCS_QUANTITY
  4338. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4339. }
  4340. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4341. {
  4342. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4343. {
  4344. tempIndex = ((gun_index==2) ? 1: 0);
  4345. }
  4346. else
  4347. {
  4348. tempIndex = gun_index;
  4349. }
  4350. for (int index = 0; index < GB_QUANTITY; index++)
  4351. {
  4352. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4353. {
  4354. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4355. }
  4356. } // END OF FOR GB_QUANTITY
  4357. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4358. }
  4359. else if(gunType[gun_index] == GUN_TYPE_DO)
  4360. {
  4361. tempIndex = gun_index;
  4362. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4363. {
  4364. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4365. {
  4366. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4367. }
  4368. }
  4369. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4370. }
  4371. else
  4372. {
  4373. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4374. {
  4375. tempIndex = 2;
  4376. }
  4377. else
  4378. {
  4379. tempIndex = gun_index;
  4380. }
  4381. for (int index = 0; index < AC_QUANTITY; index++)
  4382. {
  4383. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4384. {
  4385. 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
  4386. }
  4387. } // END OF FOR AC_QUANTITY
  4388. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  4389. }
  4390. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4391. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  4392. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  4393. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  4394. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4395. }
  4396. //====================== End SoC ================================
  4397. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4398. {
  4399. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4400. 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))
  4401. {
  4402. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4403. {
  4404. tempIndex = ((gun_index==2) ? 1: 0);
  4405. }
  4406. else
  4407. {
  4408. tempIndex = gun_index;
  4409. }
  4410. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4411. {
  4412. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4413. {
  4414. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4415. {
  4416. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  4417. }
  4418. }
  4419. }
  4420. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4421. {
  4422. for (int index = 0; index < CCS_QUANTITY; index++)
  4423. {
  4424. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4425. {
  4426. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  4427. }
  4428. }
  4429. }
  4430. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4431. {
  4432. for (int index = 0; index < GB_QUANTITY; index++)
  4433. {
  4434. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4435. {
  4436. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  4437. }
  4438. }
  4439. }
  4440. else if(gunType[gun_index] == GUN_TYPE_DO)
  4441. {
  4442. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4443. {
  4444. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4445. {
  4446. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  4447. }
  4448. }
  4449. }
  4450. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4451. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  4452. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4453. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  4454. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  4455. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4456. } // END FOR DC CASE
  4457. }
  4458. // ================================= Current.Import L2 ===============================================
  4459. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4460. {
  4461. // AC 3 phse L2 current
  4462. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4463. {
  4464. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4465. {
  4466. tempIndex = 2;
  4467. }
  4468. else
  4469. {
  4470. tempIndex = gun_index;
  4471. }
  4472. for (int index = 0; index < AC_QUANTITY; index++)
  4473. {
  4474. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4475. {
  4476. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  4477. }
  4478. }// End of for AC_QUANTITY
  4479. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  4480. }
  4481. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4482. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  4483. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  4484. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  4485. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4486. }
  4487. // ================================= Current.Import L3 ===============================================
  4488. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4489. {
  4490. // AC 3 phse L3 current
  4491. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4492. {
  4493. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4494. {
  4495. tempIndex = 2;
  4496. }
  4497. else
  4498. {
  4499. tempIndex = gun_index;
  4500. }
  4501. for (int index = 0; index < AC_QUANTITY; index++)
  4502. {
  4503. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4504. {
  4505. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  4506. }
  4507. }// End of for AC_QUANTITY
  4508. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  4509. }
  4510. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4511. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  4512. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  4513. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  4514. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4515. }
  4516. //============================ Voltage L2 ====================================
  4517. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4518. {
  4519. // AC 3 phse L2 voltage
  4520. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4521. {
  4522. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4523. {
  4524. tempIndex = 2;
  4525. }
  4526. else
  4527. {
  4528. tempIndex = gun_index;
  4529. }
  4530. for (int index = 0; index < AC_QUANTITY; index++)
  4531. {
  4532. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4533. {
  4534. 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
  4535. }
  4536. } // END OF FOR AC_QUANTITY
  4537. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  4538. }
  4539. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4540. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  4541. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  4542. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  4543. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4544. }
  4545. //============================ Voltage L3 ====================================
  4546. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4547. {
  4548. // AC 3 phse L3 voltage
  4549. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4550. {
  4551. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4552. {
  4553. tempIndex = 2;
  4554. }
  4555. else
  4556. {
  4557. tempIndex = gun_index;
  4558. }
  4559. for (int index = 0; index < AC_QUANTITY; index++)
  4560. {
  4561. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4562. {
  4563. 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
  4564. }
  4565. } // END OF FOR AC_QUANTITY
  4566. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  4567. }
  4568. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4569. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  4570. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  4571. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  4572. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4573. }
  4574. //====================== Start SoC ================================
  4575. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4576. {
  4577. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4578. 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))
  4579. {
  4580. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4581. {
  4582. tempIndex = ((gun_index==2) ? 1: 0);
  4583. }
  4584. else
  4585. {
  4586. tempIndex = gun_index;
  4587. }
  4588. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4589. {
  4590. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4591. {
  4592. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4593. {
  4594. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  4595. }
  4596. }
  4597. }
  4598. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4599. {
  4600. for (int index = 0; index < CCS_QUANTITY; index++)
  4601. {
  4602. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4603. {
  4604. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  4605. }
  4606. }
  4607. }
  4608. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4609. {
  4610. for (int index = 0; index < GB_QUANTITY; index++)
  4611. {
  4612. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4613. {
  4614. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  4615. }
  4616. }
  4617. }
  4618. else if(gunType[gun_index] == GUN_TYPE_DO)
  4619. {
  4620. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4621. {
  4622. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4623. {
  4624. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  4625. }
  4626. }
  4627. }
  4628. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4629. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  4630. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4631. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  4632. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  4633. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4634. } // END FOR DC CASE
  4635. }
  4636. //================================================ Message create ====================================================
  4637. json_object *StopTransaction = json_object_new_object();
  4638. json_object *transactionDatas = json_object_new_array();
  4639. json_object *sampledValues = json_object_new_array();
  4640. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  4641. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  4642. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  4643. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  4644. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  4645. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  4646. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  4647. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  4648. {
  4649. json_object *transactionData = json_object_new_object();
  4650. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  4651. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  4652. {
  4653. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  4654. {
  4655. json_object *sampledValue = json_object_new_object();
  4656. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  4657. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  4658. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  4659. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  4660. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  4661. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  4662. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  4663. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  4664. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  4665. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  4666. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  4667. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  4668. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  4669. json_object_array_add(sampledValues, sampledValue);
  4670. }
  4671. }
  4672. json_object_object_add(transactionData, "sampledValue", sampledValues);
  4673. json_object_array_add(transactionDatas, transactionData);
  4674. }
  4675. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  4676. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  4677. ,MESSAGE_TYPE_CALL
  4678. ,guid
  4679. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  4680. json_object_put(StopTransaction);
  4681. #if 1 // for TempStopTransaction
  4682. //Delete TempStopTransaction
  4683. if((access(TempStopTransaction,F_OK))!=-1)
  4684. {
  4685. remove(TempStopTransaction); // remove file "TempStopTransaction"
  4686. }
  4687. #endif
  4688. #if 1
  4689. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4690. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4691. {
  4692. result = PASS;
  4693. //DEBUG_INFO("StopTransaction mapitem pass\n");
  4694. }
  4695. #endif
  4696. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4697. OCPP_insert_transaction_msg(NO, queuedata);
  4698. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4699. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  4700. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  4701. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4702. {
  4703. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  4704. }
  4705. //for test
  4706. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4707. return result;
  4708. }
  4709. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  4710. {
  4711. mtrace();
  4712. int result = FAIL;
  4713. char guid[37]={0};
  4714. char tempdata[65]={0};
  4715. int tempIndex = 0;
  4716. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4717. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4718. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  4719. //set value
  4720. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4721. 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) )?
  4722. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  4723. -1);
  4724. random_uuid(guid);
  4725. //UTC Date time
  4726. struct timeval tmnow;
  4727. struct tm *tm;
  4728. char buf[28];//, usec_buf[6];
  4729. gettimeofday(&tmnow, NULL);
  4730. time_t t;
  4731. t = time(NULL);
  4732. /*UTC time and date*/
  4733. tm = gmtime(&t);
  4734. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4735. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4736. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4737. //********************************(1)Current.Import L1************************************************/
  4738. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  4739. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  4740. (dataType == ReadingContext_Trigger))
  4741. {
  4742. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4743. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4744. {
  4745. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4746. {
  4747. tempIndex = ((gun_index==2) ? 1: 0);
  4748. }
  4749. else
  4750. {
  4751. tempIndex = gun_index;
  4752. }
  4753. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4754. {
  4755. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4756. {
  4757. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4758. }
  4759. }
  4760. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4761. }
  4762. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4763. {
  4764. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4765. {
  4766. tempIndex = ((gun_index==2) ? 1: 0);
  4767. }
  4768. else
  4769. {
  4770. tempIndex = gun_index;
  4771. }
  4772. for (int index = 0; index < CCS_QUANTITY; index++)
  4773. {
  4774. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4775. {
  4776. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4777. }
  4778. }
  4779. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4780. }
  4781. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4782. {
  4783. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4784. {
  4785. tempIndex = ((gun_index==2) ? 1: 0);
  4786. }
  4787. else
  4788. {
  4789. tempIndex = gun_index;
  4790. }
  4791. for (int index = 0; index < GB_QUANTITY; index++)
  4792. {
  4793. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4794. {
  4795. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4796. }
  4797. }
  4798. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4799. }
  4800. else if(gunType[gun_index] == GUN_TYPE_DO)
  4801. {
  4802. tempIndex = gun_index;
  4803. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4804. {
  4805. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4806. {
  4807. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  4808. }
  4809. }
  4810. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4811. }
  4812. else
  4813. {
  4814. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4815. {
  4816. tempIndex = 2;
  4817. }
  4818. else
  4819. {
  4820. tempIndex = gun_index;
  4821. }
  4822. for (int index = 0; index < AC_QUANTITY; index++)
  4823. {
  4824. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4825. {
  4826. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4827. }
  4828. }
  4829. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4830. }
  4831. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4832. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4833. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4834. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4835. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4836. }
  4837. //********************************(2)Energy.Active.Import.Register ************************************************/
  4838. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4839. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4840. (dataType == ReadingContext_Trigger))
  4841. {
  4842. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4843. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4844. {
  4845. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4846. {
  4847. tempIndex = ((gun_index==2) ? 1: 0);
  4848. }
  4849. else
  4850. {
  4851. tempIndex = gun_index;
  4852. }
  4853. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4854. {
  4855. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4856. {
  4857. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4858. }
  4859. }
  4860. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4861. }
  4862. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4863. {
  4864. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4865. {
  4866. tempIndex = ((gun_index==2) ? 1: 0);
  4867. }
  4868. else
  4869. {
  4870. tempIndex = gun_index;
  4871. }
  4872. for (int index = 0; index < CCS_QUANTITY; index++)
  4873. {
  4874. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4875. {
  4876. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4877. }
  4878. }
  4879. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4880. }
  4881. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4882. {
  4883. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4884. {
  4885. tempIndex = ((gun_index==2) ? 1: 0);
  4886. }
  4887. else
  4888. {
  4889. tempIndex = gun_index;
  4890. }
  4891. for (int index = 0; index < GB_QUANTITY; index++)
  4892. {
  4893. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4894. {
  4895. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4896. }
  4897. }
  4898. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4899. }
  4900. else if(gunType[gun_index] == GUN_TYPE_DO)
  4901. {
  4902. tempIndex = gun_index;
  4903. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4904. {
  4905. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4906. {
  4907. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  4908. }
  4909. }
  4910. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4911. }
  4912. else
  4913. {
  4914. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4915. {
  4916. tempIndex = 2;
  4917. }
  4918. else
  4919. {
  4920. tempIndex = gun_index;
  4921. }
  4922. for (int index = 0; index < AC_QUANTITY; index++)
  4923. {
  4924. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4925. {
  4926. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  4927. }
  4928. }
  4929. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4930. }
  4931. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  4932. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  4933. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  4934. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  4935. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4936. }
  4937. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  4938. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  4939. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  4940. (dataType == ReadingContext_Trigger))
  4941. {
  4942. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4943. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4944. {
  4945. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4946. {
  4947. tempIndex = ((gun_index==2) ? 1: 0);
  4948. }
  4949. else
  4950. {
  4951. tempIndex = gun_index;
  4952. }
  4953. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4954. {
  4955. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4956. {
  4957. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  4958. }
  4959. } // END OF FOR CHAdeMO_QUANTITY
  4960. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4961. }
  4962. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4963. {
  4964. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4965. {
  4966. tempIndex = ((gun_index==2) ? 1: 0);
  4967. }
  4968. else
  4969. {
  4970. tempIndex = gun_index;
  4971. }
  4972. for (int index = 0; index < CCS_QUANTITY; index++)
  4973. {
  4974. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4975. {
  4976. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  4977. }
  4978. } // END OF CCS_QUANTITY
  4979. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4980. }
  4981. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4982. {
  4983. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4984. {
  4985. tempIndex = ((gun_index==2) ? 1: 0);
  4986. }
  4987. else
  4988. {
  4989. tempIndex = gun_index;
  4990. }
  4991. for (int index = 0; index < GB_QUANTITY; index++)
  4992. {
  4993. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4994. {
  4995. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  4996. }
  4997. } // END OF GB_QUANTITY
  4998. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4999. }
  5000. else if(gunType[gun_index] == GUN_TYPE_DO)
  5001. {
  5002. tempIndex = gun_index;
  5003. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5004. {
  5005. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5006. {
  5007. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  5008. }
  5009. }
  5010. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5011. }
  5012. else
  5013. {
  5014. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5015. {
  5016. tempIndex = 2;
  5017. }
  5018. else
  5019. {
  5020. tempIndex = gun_index;
  5021. }
  5022. for (int index = 0; index < AC_QUANTITY; index++)
  5023. {
  5024. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5025. {
  5026. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  5027. }
  5028. }
  5029. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  5030. }
  5031. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  5032. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  5033. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  5034. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  5035. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5036. }
  5037. //********************************(4)Power.Active.Import************************************************/
  5038. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Power.Active.Import") != NULL)) ||
  5039. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Power.Active.Import") != NULL)) ||
  5040. (dataType == ReadingContext_Trigger))
  5041. {
  5042. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5043. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5044. {
  5045. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5046. {
  5047. tempIndex = ((gun_index==2) ? 1: 0);
  5048. }
  5049. else
  5050. {
  5051. tempIndex = gun_index;
  5052. }
  5053. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5054. {
  5055. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5056. {
  5057. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  5058. }
  5059. } // END OF FOR
  5060. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5061. }
  5062. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5063. {
  5064. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5065. {
  5066. tempIndex = ((gun_index==2) ? 1: 0);
  5067. }
  5068. else
  5069. {
  5070. tempIndex = gun_index;
  5071. }
  5072. for (int index = 0; index < CCS_QUANTITY; index++)
  5073. {
  5074. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5075. {
  5076. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  5077. }
  5078. }
  5079. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5080. }
  5081. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5082. {
  5083. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5084. {
  5085. tempIndex = ((gun_index==2) ? 1: 0);
  5086. }
  5087. else
  5088. {
  5089. tempIndex = gun_index;
  5090. }
  5091. for (int index = 0; index < GB_QUANTITY; index++)
  5092. {
  5093. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5094. {
  5095. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5096. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  5097. }
  5098. }
  5099. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5100. }
  5101. else if(gunType[gun_index] == GUN_TYPE_DO)
  5102. {
  5103. tempIndex = gun_index;
  5104. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5105. {
  5106. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5107. {
  5108. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5109. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  5110. }
  5111. }
  5112. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5113. }
  5114. else
  5115. {
  5116. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5117. {
  5118. tempIndex = 2;
  5119. }
  5120. else
  5121. {
  5122. tempIndex = gun_index;
  5123. }
  5124. for (int index = 0; index < AC_QUANTITY; index++)
  5125. {
  5126. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5127. {
  5128. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  5129. }
  5130. }
  5131. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  5132. }
  5133. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  5134. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  5135. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  5136. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  5137. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  5138. }
  5139. //***********************************************(5)VOLTAGE L1******************************************************/
  5140. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5141. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5142. (dataType == ReadingContext_Trigger))
  5143. {
  5144. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5145. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5146. {
  5147. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5148. {
  5149. tempIndex = ((gun_index==2) ? 1: 0);
  5150. }
  5151. else
  5152. {
  5153. tempIndex = gun_index;
  5154. }
  5155. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5156. {
  5157. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5158. {
  5159. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  5160. }
  5161. }
  5162. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5163. }
  5164. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5165. {
  5166. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5167. {
  5168. tempIndex = ((gun_index==2) ? 1: 0);
  5169. }
  5170. else
  5171. {
  5172. tempIndex = gun_index;
  5173. }
  5174. for (int index = 0; index < CCS_QUANTITY; index++)
  5175. {
  5176. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5177. {
  5178. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  5179. }
  5180. }
  5181. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5182. }
  5183. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5184. {
  5185. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5186. {
  5187. tempIndex = ((gun_index==2) ? 1: 0);
  5188. }
  5189. else
  5190. {
  5191. tempIndex = gun_index;
  5192. }
  5193. for (int index = 0; index < GB_QUANTITY; index++)
  5194. {
  5195. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5196. {
  5197. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  5198. }
  5199. }
  5200. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5201. }
  5202. else if(gunType[gun_index] == GUN_TYPE_DO)
  5203. {
  5204. tempIndex = gun_index;
  5205. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5206. {
  5207. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5208. {
  5209. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  5210. }
  5211. }
  5212. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5213. }
  5214. else
  5215. {
  5216. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5217. {
  5218. tempIndex = 2;
  5219. }
  5220. else
  5221. {
  5222. tempIndex = gun_index;
  5223. }
  5224. for (int index = 0; index < AC_QUANTITY; index++)
  5225. {
  5226. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5227. {
  5228. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  5229. }
  5230. }
  5231. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  5232. }
  5233. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  5234. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  5235. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  5236. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  5237. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5238. }
  5239. //***********************************************(6)SOC******************************************************/
  5240. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "SOC") != NULL)) ||
  5241. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "SOC") != NULL)) ||
  5242. (dataType == ReadingContext_Trigger))
  5243. {
  5244. 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))
  5245. {
  5246. //idx_sample=5;
  5247. //sampledValue = NULL;
  5248. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5249. {
  5250. tempIndex = ((gun_index==2) ? 1: 0);
  5251. }
  5252. else
  5253. {
  5254. tempIndex = gun_index;
  5255. }
  5256. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5257. {
  5258. //tempIndex = ((gun_index==2) ? 1: 0);
  5259. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5260. {
  5261. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5262. {
  5263. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  5264. }
  5265. }
  5266. }
  5267. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5268. {
  5269. //tempIndex = ((gun_index==2) ? 1: 0);
  5270. for (int index = 0; index < CCS_QUANTITY; index++)
  5271. {
  5272. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5273. {
  5274. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  5275. }
  5276. }
  5277. }
  5278. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5279. {
  5280. //tempIndex = ((gun_index==2) ? 1: 0);
  5281. for (int index = 0; index < GB_QUANTITY; index++)
  5282. {
  5283. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5284. {
  5285. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  5286. }
  5287. }
  5288. }
  5289. else if(gunType[gun_index] == GUN_TYPE_DO)
  5290. {
  5291. //tempIndex = ((gun_index==2) ? 1: 0);
  5292. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5293. {
  5294. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5295. {
  5296. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  5297. }
  5298. }
  5299. }
  5300. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  5301. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  5302. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  5303. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  5304. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  5305. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  5306. }
  5307. }
  5308. //********************************(7)Current.Import L2************************************************/
  5309. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5310. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5311. (dataType == ReadingContext_Trigger))
  5312. {
  5313. // Only for AC 3 phase
  5314. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5315. {
  5316. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5317. {
  5318. tempIndex = 2;
  5319. }
  5320. else
  5321. {
  5322. tempIndex = gun_index;
  5323. }
  5324. for (int index = 0; index < AC_QUANTITY; index++)
  5325. {
  5326. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5327. {
  5328. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  5329. }
  5330. }
  5331. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  5332. }
  5333. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  5334. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  5335. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  5336. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  5337. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5338. }
  5339. //********************************(8)Current.Import L3************************************************/
  5340. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5341. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5342. (dataType == ReadingContext_Trigger))
  5343. {
  5344. // Only for AC 3 phase
  5345. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5346. {
  5347. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5348. {
  5349. tempIndex = 2;
  5350. }
  5351. else
  5352. {
  5353. tempIndex = gun_index;
  5354. }
  5355. for (int index = 0; index < AC_QUANTITY; index++)
  5356. {
  5357. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5358. {
  5359. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  5360. }
  5361. }
  5362. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  5363. }
  5364. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  5365. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  5366. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  5367. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  5368. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5369. }
  5370. //***********************************************(9)VOLTAGE L2******************************************************/
  5371. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5372. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5373. (dataType == ReadingContext_Trigger))
  5374. {
  5375. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5376. {
  5377. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5378. {
  5379. tempIndex = 2;
  5380. }
  5381. else
  5382. {
  5383. tempIndex = gun_index;
  5384. }
  5385. for (int index = 0; index < AC_QUANTITY; index++)
  5386. {
  5387. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5388. {
  5389. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  5390. }
  5391. }
  5392. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  5393. }
  5394. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  5395. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  5396. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  5397. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  5398. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5399. }
  5400. //***********************************************(10)VOLTAGE L3******************************************************/
  5401. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5402. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5403. (dataType == ReadingContext_Trigger))
  5404. {
  5405. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5406. {
  5407. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5408. {
  5409. tempIndex = 2;
  5410. }
  5411. else
  5412. {
  5413. tempIndex = gun_index;
  5414. }
  5415. for (int index = 0; index < AC_QUANTITY; index++)
  5416. {
  5417. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5418. {
  5419. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  5420. }
  5421. }
  5422. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  5423. }
  5424. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  5425. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  5426. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  5427. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  5428. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5429. }
  5430. // Message create ====================================================================================================
  5431. if(TRUE)
  5432. {
  5433. json_object *MeterValueReq = json_object_new_object();
  5434. json_object *MeterValues = json_object_new_array();
  5435. json_object *sampledValues = json_object_new_array();
  5436. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  5437. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  5438. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  5439. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  5440. {
  5441. json_object *MeterValue = json_object_new_object();
  5442. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  5443. {
  5444. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  5445. {
  5446. json_object *sampledValue = json_object_new_object();
  5447. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  5448. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  5449. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  5450. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  5451. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  5452. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  5453. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  5454. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  5455. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  5456. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  5457. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  5458. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  5459. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  5460. json_object_array_add(sampledValues, sampledValue);
  5461. }
  5462. }
  5463. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  5464. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  5465. json_object_array_add(MeterValues, MeterValue);
  5466. }
  5467. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  5468. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  5469. ,gun_index + 1
  5470. ,MESSAGE_TYPE_CALL
  5471. ,guid
  5472. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  5473. json_object_put(MeterValueReq);
  5474. }
  5475. // Put request guid to hash map
  5476. sprintf(tempdata, "MeterValues,%d", (gun_index));
  5477. 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*/)
  5478. {
  5479. result = PASS;
  5480. //DEBUG_INFO("MeterValues mapitem pass\n");
  5481. }
  5482. if((dataType != ReadingContext_Trigger) &&
  5483. (dataType != ReadingContext_Sample_Clock) &&
  5484. (ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1))
  5485. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  5486. else
  5487. {
  5488. if(FirstHeartBeat)
  5489. LWS_Send(queuedata +2);
  5490. }
  5491. return result;
  5492. }
  5493. int sendLogStatusNotificationRequest(char *status)
  5494. {
  5495. mtrace();
  5496. int result = PASS;
  5497. char message[4096]={0};
  5498. char guid[37]={0};
  5499. char tempdata[128]={0};
  5500. json_object *LogStatusNotification = json_object_new_object();
  5501. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  5502. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  5503. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  5504. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  5505. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  5506. random_uuid(guid);
  5507. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  5508. json_object_put(LogStatusNotification);
  5509. LWS_Send(message);
  5510. sprintf(tempdata, "LogStatusNotification,%d", 0);
  5511. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5512. {
  5513. result = PASS;
  5514. }
  5515. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  5516. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  5517. return result;
  5518. }
  5519. int sendSecurityEventNotificationRequest()
  5520. {
  5521. mtrace();
  5522. int result = PASS;
  5523. char message[4096]={0};
  5524. char guid[37]={0};
  5525. char tempdata[128]={0};
  5526. json_object *SecurityEventNotification = json_object_new_object();
  5527. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  5528. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  5529. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  5530. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  5531. random_uuid(guid);
  5532. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  5533. json_object_put(SecurityEventNotification);
  5534. LWS_Send(message);
  5535. sprintf(tempdata, "SecurityEventNotification,0");
  5536. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5537. {
  5538. result = PASS;
  5539. }
  5540. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  5541. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  5542. return result;
  5543. }
  5544. int sendSignCertificateRequest()
  5545. {
  5546. mtrace();
  5547. int result = PASS;
  5548. char message[4096]={0};
  5549. char guid[37]={0};
  5550. char tempdata[128]={0};
  5551. json_object *SignCertificate = json_object_new_object();
  5552. DEBUG_INFO("sendSignCertificateRequest...\n");
  5553. // Read csr file content
  5554. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  5555. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  5556. char *line = NULL;
  5557. size_t len = 0;
  5558. while(getline(&line, &len, fp) != -1)
  5559. {
  5560. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  5561. {
  5562. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  5563. }
  5564. }
  5565. fclose(fp);
  5566. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  5567. random_uuid(guid);
  5568. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  5569. json_object_put(SignCertificate);
  5570. LWS_Send(message);
  5571. sprintf(tempdata, "SignCertificate,0");
  5572. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5573. {
  5574. result = PASS;
  5575. }
  5576. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  5577. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  5578. return result;
  5579. }
  5580. int sendSignedFirmwareStatusNotificationRequest(char *status)
  5581. {
  5582. mtrace();
  5583. int result = PASS;
  5584. char message[110]={0};
  5585. char guid[37]={0};
  5586. char tempdata[65]={0};
  5587. json_object *FirmwareStatusNotification = json_object_new_object();
  5588. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  5589. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  5590. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  5591. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  5592. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  5593. random_uuid(guid);
  5594. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  5595. json_object_put(FirmwareStatusNotification);
  5596. LWS_Send(message);
  5597. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  5598. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5599. {
  5600. result = PASS;
  5601. }
  5602. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  5603. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  5604. return result;
  5605. }
  5606. //==========================================
  5607. // send confirm routine
  5608. //==========================================
  5609. int sendCancelReservationConfirmation(char *uuid,char *payload)
  5610. {
  5611. mtrace();
  5612. int result = FAIL;
  5613. char message[100]={0};
  5614. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  5615. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5616. LWS_Send(message);
  5617. result = TRUE;
  5618. return result;
  5619. }
  5620. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  5621. {
  5622. mtrace();
  5623. int result = FAIL;
  5624. char message[100]={0};
  5625. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  5626. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5627. LWS_Send(message);
  5628. result = TRUE;
  5629. return result;
  5630. }
  5631. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  5632. {
  5633. mtrace();
  5634. int result = FAIL;
  5635. char message[100]={0};
  5636. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  5637. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5638. LWS_Send(message);
  5639. result = TRUE;
  5640. return result;
  5641. }
  5642. int sendClearCacheConfirmation(char *uuid,char *payload)
  5643. {
  5644. mtrace();
  5645. int result = FAIL;
  5646. char message[500]={0};
  5647. DEBUG_INFO("sendClearCacheConfirmation...\n");
  5648. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5649. LWS_Send(message);
  5650. return result;
  5651. }
  5652. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  5653. {
  5654. mtrace();
  5655. int result = FAIL;
  5656. char message[500]={0};
  5657. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  5658. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5659. LWS_Send(message);
  5660. return result;
  5661. }
  5662. int sendDataTransferConfirmation(char *uuid,char *payload)
  5663. {
  5664. mtrace();
  5665. char statusStr[20]={0};
  5666. char dataStr[10]={0};
  5667. char sstr[20]={0};
  5668. int c = 0;
  5669. char *loc;
  5670. int result = FAIL;
  5671. DEBUG_INFO("sendDataTransferConfirmation...\n");
  5672. /**********************status**************************/
  5673. loc = strstr(payload, "status");
  5674. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5675. c = 0;
  5676. while (loc[3+strlen("status")+c] != '\"')
  5677. {
  5678. sstr[c] = loc[3+strlen("status")+c];
  5679. c++;
  5680. }
  5681. sstr[c] = '\0';
  5682. strcpy(statusStr, sstr);
  5683. /**********************data**************************/
  5684. loc = strstr(payload, "data");
  5685. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5686. c = 0;
  5687. while (loc[3+strlen("data")+c] != '\"')
  5688. {
  5689. sstr[c] = loc[3+strlen("data")+c];
  5690. c++;
  5691. }
  5692. sstr[c] = '\0';
  5693. strcpy(dataStr, sstr);
  5694. return result;
  5695. }
  5696. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  5697. {
  5698. mtrace();
  5699. int result = FAIL;
  5700. char message[1000]={0};
  5701. int CompositeScheduleIndex = 0;
  5702. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  5703. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  5704. if(nPeriod == 0)
  5705. {
  5706. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  5707. {
  5708. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  5709. ,MESSAGE_TYPE_CALLRESULT
  5710. ,uuid
  5711. ,payload
  5712. ,connectorIdInt);
  5713. }
  5714. else
  5715. {
  5716. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  5717. ,MESSAGE_TYPE_CALLRESULT
  5718. ,uuid
  5719. ,payload
  5720. ,connectorIdInt
  5721. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5722. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5723. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5724. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  5725. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  5726. }
  5727. }
  5728. else
  5729. {
  5730. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  5731. ,MESSAGE_TYPE_CALLRESULT
  5732. ,uuid
  5733. ,payload
  5734. ,connectorIdInt
  5735. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5736. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5737. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5738. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  5739. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  5740. {
  5741. if (idx_sample == 0)
  5742. {
  5743. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5744. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5745. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5746. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5747. }
  5748. else
  5749. {
  5750. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5751. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5752. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5753. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5754. }
  5755. }
  5756. sprintf(message + strlen(message), "]}}]");
  5757. }
  5758. LWS_Send(message);
  5759. result = TRUE;
  5760. return result;
  5761. }
  5762. int sendGetConfigurationConfirmation(char *uuid)
  5763. {
  5764. mtrace();
  5765. int result = FAIL;
  5766. int MaxKeySupported = 0;
  5767. int sentConfigurationNumber= 0;
  5768. int sentunConfigurationNumber= 0;
  5769. char message[4000]={0};
  5770. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  5771. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  5772. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  5773. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  5774. ,MESSAGE_TYPE_CALLRESULT
  5775. ,uuid );
  5776. //configuration key
  5777. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  5778. {
  5779. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  5780. {
  5781. if (sentConfigurationNumber == 0)
  5782. {
  5783. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5784. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5785. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5786. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5787. }
  5788. else
  5789. {
  5790. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5791. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5792. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5793. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5794. }
  5795. sentConfigurationNumber = sentConfigurationNumber + 1;
  5796. }
  5797. }
  5798. sprintf(message + strlen(message), "]");
  5799. if(UnknownKeynum != 0)
  5800. {
  5801. sprintf(message + strlen(message), ",\"unknownKey\":[");
  5802. //unkown key
  5803. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  5804. {
  5805. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  5806. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  5807. if(sentunConfigurationNumber == 0)
  5808. {
  5809. sprintf(message + strlen(message), "\"%s\""
  5810. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5811. }
  5812. else
  5813. {
  5814. sprintf(message + strlen(message), ",\"%s\""
  5815. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5816. }
  5817. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  5818. }
  5819. sprintf(message + strlen(message), "]");
  5820. }
  5821. sprintf(message + strlen(message), "}]");
  5822. LWS_Send(message);
  5823. return result;
  5824. }
  5825. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  5826. {
  5827. mtrace();
  5828. int result = FAIL;
  5829. char message[400]={0};
  5830. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  5831. if(strcmp(payload,"")==0)
  5832. {
  5833. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5834. }
  5835. else
  5836. {
  5837. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5838. }
  5839. LWS_Send(message);
  5840. result = TRUE;
  5841. return result;
  5842. }
  5843. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  5844. {
  5845. mtrace();
  5846. int result = FAIL;
  5847. char message[80]={0};
  5848. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  5849. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  5850. LWS_Send(message);
  5851. result = TRUE;
  5852. return result;
  5853. }
  5854. int sendRemoteStartConfirmation(char *uuid,char *payload)
  5855. {
  5856. mtrace();
  5857. int result = FAIL;
  5858. char message[80]={0};
  5859. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  5860. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5861. LWS_Send(message);
  5862. result = TRUE;
  5863. return result;
  5864. }
  5865. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5866. {
  5867. mtrace();
  5868. int result = FAIL;
  5869. char message[80]={0};
  5870. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5871. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5872. LWS_Send(message);
  5873. result = TRUE;
  5874. return result;
  5875. }
  5876. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5877. {
  5878. mtrace();
  5879. int result = FAIL;
  5880. char message[80]={0};
  5881. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5882. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  5883. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5884. LWS_Send(message);
  5885. result = TRUE;
  5886. return result;
  5887. }
  5888. int sendResetConfirmation(char *uuid,char *payload)
  5889. {
  5890. mtrace();
  5891. int result = FAIL;
  5892. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  5893. char message[80]={0};
  5894. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  5895. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5896. LWS_Send(message);
  5897. result = TRUE;
  5898. return result;
  5899. }
  5900. int sendSendLocalListConfirmation(char *uuid,char *payload)
  5901. {
  5902. mtrace();
  5903. int result = FAIL;
  5904. char message[500]={0};
  5905. // [ 3, "1571284266109", { "status": "Accepted" } ]
  5906. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5907. LWS_Send(message);
  5908. result = TRUE;
  5909. return result;
  5910. }
  5911. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  5912. {
  5913. mtrace();
  5914. int result = FAIL;
  5915. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  5916. char message[80]={0};
  5917. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  5918. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5919. LWS_Send(message);
  5920. result = TRUE;
  5921. return result;
  5922. }
  5923. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  5924. {
  5925. mtrace();
  5926. int result = FAIL;
  5927. char message[80]={0};
  5928. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  5929. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5930. LWS_Send(message);
  5931. result = TRUE;
  5932. return result;
  5933. }
  5934. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  5935. {
  5936. mtrace();
  5937. int result = FAIL;
  5938. char message[80]={0};
  5939. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5940. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  5941. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5942. LWS_Send(message);
  5943. result = TRUE;
  5944. return result;
  5945. }
  5946. int sendUpdateFirmwareConfirmation(char *uuid)
  5947. {
  5948. mtrace();
  5949. int result = FAIL;
  5950. char message[60]={0};
  5951. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5952. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  5953. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5954. LWS_Send(message);
  5955. result = TRUE;
  5956. return result;
  5957. }
  5958. int sendCertificateSignedConfirmation(char *uuid)
  5959. {
  5960. mtrace();
  5961. int result = PASS;
  5962. char message[4096]={0};
  5963. json_object *CertificateSigned = json_object_new_object();
  5964. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  5965. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  5966. sprintf(message,"[%d,\"%s\",%s]"
  5967. ,MESSAGE_TYPE_CALLRESULT
  5968. ,uuid
  5969. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  5970. json_object_put(CertificateSigned);
  5971. LWS_Send(message);
  5972. return result;
  5973. }
  5974. int sendDeleteCertificateConfirmation(char *uuid)
  5975. {
  5976. mtrace();
  5977. int result = PASS;
  5978. char message[4096]={0};
  5979. json_object *DeleteCertificate = json_object_new_object();
  5980. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  5981. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  5982. sprintf(message,"[%d,\"%s\",%s]"
  5983. ,MESSAGE_TYPE_CALLRESULT
  5984. ,uuid
  5985. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  5986. json_object_put(DeleteCertificate);
  5987. LWS_Send(message);
  5988. return result;
  5989. }
  5990. int sendExtendedTriggerMessageConfirmation(char *uuid)
  5991. {
  5992. mtrace();
  5993. int result = PASS;
  5994. char message[4096]={0};
  5995. json_object *ExtendedTriggerMessage = json_object_new_object();
  5996. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  5997. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  5998. sprintf(message,"[%d,\"%s\",%s]"
  5999. ,MESSAGE_TYPE_CALLRESULT
  6000. ,uuid
  6001. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  6002. json_object_put(ExtendedTriggerMessage);
  6003. LWS_Send(message);
  6004. return result;
  6005. }
  6006. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  6007. {
  6008. mtrace();
  6009. int result = PASS;
  6010. char message[4096]={0};
  6011. json_object *GetInstalledCertificateIds = json_object_new_object();
  6012. json_object *certificateHashDataDatas = json_object_new_array();
  6013. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  6014. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  6015. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  6016. {
  6017. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  6018. {
  6019. json_object *certificateHashData = json_object_new_object();
  6020. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  6021. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  6022. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  6023. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  6024. json_object_array_add(certificateHashDataDatas, certificateHashData);
  6025. }
  6026. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  6027. }
  6028. else
  6029. {
  6030. json_object_put(certificateHashDataDatas);
  6031. }
  6032. sprintf(message,"[%d,\"%s\",%s]"
  6033. ,MESSAGE_TYPE_CALLRESULT
  6034. ,uuid
  6035. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  6036. json_object_put(GetInstalledCertificateIds);
  6037. LWS_Send(message);
  6038. return result;
  6039. }
  6040. int sendGetLogConfirmation(char *uuid)
  6041. {
  6042. mtrace();
  6043. int result = PASS;
  6044. char message[4096]={0};
  6045. json_object *GetLog = json_object_new_object();
  6046. DEBUG_INFO("sendGetLogConfirmation...\n");
  6047. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  6048. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  6049. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  6050. sprintf(message,"[%d,\"%s\",%s]"
  6051. ,MESSAGE_TYPE_CALLRESULT
  6052. ,uuid
  6053. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  6054. json_object_put(GetLog);
  6055. LWS_Send(message);
  6056. return result;
  6057. }
  6058. int sendInstallCertificateConfirmation(char *uuid)
  6059. {
  6060. mtrace();
  6061. int result = PASS;
  6062. char message[4096]={0};
  6063. json_object *InstallCertificate = json_object_new_object();
  6064. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  6065. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  6066. sprintf(message,"[%d,\"%s\",%s]"
  6067. ,MESSAGE_TYPE_CALLRESULT
  6068. ,uuid
  6069. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  6070. json_object_put(InstallCertificate);
  6071. LWS_Send(message);
  6072. return result;
  6073. }
  6074. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  6075. {
  6076. mtrace();
  6077. int result = PASS;
  6078. char message[4096]={0};
  6079. json_object *SignedUpdateFirmware = json_object_new_object();
  6080. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  6081. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  6082. sprintf(message,"[%d,\"%s\",%s]"
  6083. ,MESSAGE_TYPE_CALLRESULT
  6084. ,uuid
  6085. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  6086. json_object_put(SignedUpdateFirmware);
  6087. LWS_Send(message);
  6088. return result;
  6089. }
  6090. int sendUnknownConfirmation(char *uuid)
  6091. {
  6092. mtrace();
  6093. int result = PASS;
  6094. char message[256]={0};
  6095. DEBUG_INFO("sendUnknownConfirmation...\n");
  6096. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  6097. LWS_Send(message);
  6098. return result;
  6099. }
  6100. //==========================================
  6101. // Handle server request routine Start
  6102. //==========================================
  6103. int handleCancelReservationRequest(char *uuid, char *payload)
  6104. {
  6105. mtrace();
  6106. int result = FAIL;
  6107. int gunNO = 0;
  6108. int reservationIdInt = -1;
  6109. char comfirmstr[20];
  6110. DEBUG_INFO("handleCancelReservationRequest...\n");
  6111. json_object *CancelReservation;
  6112. CancelReservation = json_tokener_parse(payload);
  6113. if(!is_error(CancelReservation))
  6114. {
  6115. // Required data
  6116. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  6117. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  6118. }
  6119. json_object_put(CancelReservation);
  6120. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  6121. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6122. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  6123. if(reservationIdInt != -1)
  6124. {
  6125. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6126. //check Transaction active
  6127. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6128. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6129. {
  6130. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  6131. {
  6132. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6133. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6134. if(gunType[2] == GUN_TYPE_CHAdeMO)
  6135. {
  6136. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  6137. }
  6138. else
  6139. {
  6140. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  6141. }
  6142. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6143. goto end;
  6144. }
  6145. }
  6146. for (int index = 0; index < CCS_QUANTITY; index++)
  6147. {
  6148. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  6149. {
  6150. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6151. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6152. if(gunType[2] == GUN_TYPE_CCS)
  6153. {
  6154. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  6155. }
  6156. else
  6157. {
  6158. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  6159. }
  6160. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6161. goto end;
  6162. }
  6163. }
  6164. for (int index = 0; index < GB_QUANTITY; index++)
  6165. {
  6166. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  6167. {
  6168. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6169. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6170. if(gunType[2] == GUN_TYPE_GBT)
  6171. {
  6172. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  6173. }
  6174. else
  6175. {
  6176. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  6177. }
  6178. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6179. goto end;
  6180. }
  6181. }
  6182. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6183. {
  6184. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  6185. {
  6186. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6187. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6188. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  6189. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6190. goto end;
  6191. }
  6192. }
  6193. for (int index = 0; index < AC_QUANTITY; index++)
  6194. {
  6195. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  6196. {
  6197. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6198. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6199. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6200. {
  6201. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  6202. }
  6203. else
  6204. {
  6205. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  6206. }
  6207. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6208. goto end;
  6209. }
  6210. }
  6211. }
  6212. //The reservationId does NOT match the reservationId
  6213. sendCancelReservationConfirmation(uuid, comfirmstr);
  6214. end:
  6215. // Fill in ocpp packet uuid
  6216. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  6217. return result;
  6218. }
  6219. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  6220. {
  6221. mtrace();
  6222. int result = FAIL;
  6223. int gunIndex = 0;
  6224. char typeStr[16]={0};
  6225. char comfirmstr[20];
  6226. int specificId = FALSE;
  6227. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  6228. json_object *ChangeAvailability;
  6229. ChangeAvailability = json_tokener_parse(payload);
  6230. if(!is_error(ChangeAvailability))
  6231. {
  6232. // Required data
  6233. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  6234. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  6235. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  6236. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  6237. }
  6238. json_object_put(ChangeAvailability);
  6239. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6240. {
  6241. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  6242. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  6243. }
  6244. else if(gunIndex == 0)
  6245. {
  6246. for(int i=0; i < gunTotalNumber; i++)
  6247. {
  6248. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  6249. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  6250. }
  6251. }
  6252. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6253. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6254. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  6255. {
  6256. specificId = TRUE;
  6257. }
  6258. if(specificId == FALSE)
  6259. goto end;
  6260. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  6261. {
  6262. //----------------------gunIndex is 0 ------------------------------------------------//
  6263. if(gunIndex == 0)
  6264. {
  6265. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6266. {
  6267. for(int i=0; i < gunTotalNumber; i++)
  6268. {
  6269. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6270. {
  6271. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  6272. {
  6273. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6274. {
  6275. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6276. goto end;
  6277. }
  6278. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6279. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6280. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6281. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6282. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6283. {
  6284. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6285. goto end;
  6286. }
  6287. }
  6288. }//END FOR CHAdeMO_QUANTITY
  6289. for (int index = 0; index < CCS_QUANTITY; index++)
  6290. {
  6291. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  6292. {
  6293. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  6294. {
  6295. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6296. goto end;
  6297. }
  6298. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6299. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6300. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6301. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6302. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6303. {
  6304. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6305. goto end;
  6306. }
  6307. }
  6308. }//END FOR CCS_QUANTITY
  6309. for (int index = 0; index < GB_QUANTITY; index++)
  6310. {
  6311. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  6312. {
  6313. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6314. {
  6315. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6316. goto end;
  6317. }
  6318. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6319. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6320. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6321. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6322. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6323. {
  6324. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6325. goto end;
  6326. }
  6327. }
  6328. }// END FOR GB_QUANTITY
  6329. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6330. {
  6331. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  6332. {
  6333. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6334. {
  6335. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6336. goto end;
  6337. }
  6338. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  6339. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  6340. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  6341. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  6342. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6343. {
  6344. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6345. goto end;
  6346. }
  6347. }
  6348. }// END FOR GENERAL_GUN_QUANTITY
  6349. for (int index = 0; index < AC_QUANTITY; index++)
  6350. {
  6351. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  6352. {
  6353. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6354. {
  6355. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6356. goto end;
  6357. }
  6358. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6359. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6360. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6361. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6362. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6363. {
  6364. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6365. goto end;
  6366. }
  6367. }
  6368. }//END FOR AC_QUANTITY
  6369. }// END FOR gunTotalNumber
  6370. }
  6371. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6372. {
  6373. for(int i=0; i < gunTotalNumber; i++)
  6374. {
  6375. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6376. {
  6377. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6378. goto end;
  6379. }
  6380. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6381. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  6382. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  6383. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  6384. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6385. {
  6386. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6387. goto end;
  6388. }
  6389. }
  6390. }
  6391. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6392. goto end;
  6393. }
  6394. //----------------------gunIndex is not 0 ------------------------------------------------//
  6395. //check Transaction active
  6396. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6397. {
  6398. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  6399. {
  6400. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  6401. {
  6402. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6403. goto end;
  6404. }
  6405. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6406. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6407. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6408. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6409. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6410. {
  6411. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6412. goto end;
  6413. }
  6414. else
  6415. {
  6416. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  6417. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6418. goto end;
  6419. }
  6420. }
  6421. }//END FOR CHAdeMO_QUANTITY
  6422. for (int index = 0; index < CCS_QUANTITY; index++)
  6423. {
  6424. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  6425. {
  6426. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  6427. {
  6428. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6429. goto end;
  6430. }
  6431. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6432. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6433. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6434. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6435. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6436. {
  6437. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6438. goto end;
  6439. }
  6440. else
  6441. {
  6442. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  6443. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6444. goto end;
  6445. }
  6446. }
  6447. }//END FOR CCS_QUANTITY
  6448. for (int index = 0; index < GB_QUANTITY; index++)
  6449. {
  6450. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  6451. {
  6452. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6453. {
  6454. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6455. goto end;
  6456. }
  6457. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6458. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6459. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6460. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6461. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6462. {
  6463. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6464. goto end;
  6465. }
  6466. else
  6467. {
  6468. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  6469. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6470. goto end;
  6471. }
  6472. }
  6473. }// END FOR GB_QUANTITY
  6474. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6475. {
  6476. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  6477. {
  6478. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6479. {
  6480. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6481. goto end;
  6482. }
  6483. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  6484. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  6485. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  6486. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  6487. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6488. {
  6489. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6490. goto end;
  6491. }
  6492. else
  6493. {
  6494. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  6495. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6496. goto end;
  6497. }
  6498. }
  6499. }// END FOR GENERAL_GUN_QUANTITY
  6500. for (int index = 0; index < AC_QUANTITY; index++)
  6501. {
  6502. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  6503. {
  6504. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6505. {
  6506. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6507. goto end;
  6508. }
  6509. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6510. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6511. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6512. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6513. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6514. {
  6515. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6516. goto end;
  6517. }
  6518. else
  6519. {
  6520. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  6521. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6522. goto end;
  6523. }
  6524. }
  6525. }//END FOR AC_QUANTITY
  6526. }//END FOR AvailabilityTypeStr[Inoperative]
  6527. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  6528. {
  6529. //----------------------gunIndex is 0 ------------------------------------------------//
  6530. if(gunIndex == 0)
  6531. {
  6532. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6533. {
  6534. for(int i=0; i < gunTotalNumber; i++)
  6535. {
  6536. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6537. {
  6538. 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
  6539. {
  6540. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6541. goto end;
  6542. }
  6543. }//END FOR CHAdeMO_QUANTITY
  6544. for (int index = 0; index < CCS_QUANTITY; index++)
  6545. {
  6546. 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
  6547. {
  6548. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6549. goto end;
  6550. }
  6551. }//END FOR CCS_QUANTITY
  6552. for (int index = 0; index < GB_QUANTITY; index++)
  6553. {
  6554. 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
  6555. {
  6556. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6557. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6558. goto end;
  6559. }
  6560. }// END FOR GB_QUANTITY
  6561. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6562. {
  6563. 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
  6564. {
  6565. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6566. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6567. goto end;
  6568. }
  6569. }// END FOR GENERAL_GUN_QUANTITY
  6570. for (int index = 0; index < AC_QUANTITY; index++)
  6571. {
  6572. 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
  6573. {
  6574. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6575. goto end;
  6576. }
  6577. }//END FOR CHAdeMO_QUANTITY
  6578. }// END FOR gunTotalNumber
  6579. }
  6580. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6581. {
  6582. for(int i=0; i < gunTotalNumber; i++)
  6583. {
  6584. for (int index = 0; index < AC_QUANTITY; index++)
  6585. {
  6586. 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
  6587. {
  6588. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6589. goto end;
  6590. }
  6591. }//END FOR CHAdeMO_QUANTITY
  6592. } // END FOR gunTotalNumber
  6593. }
  6594. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6595. goto end;
  6596. }
  6597. //----------------------gunIndex is not 0 ------------------------------------------------//
  6598. //check Transaction active
  6599. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6600. {
  6601. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6602. {
  6603. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6604. goto end;
  6605. }
  6606. }//END FOR CHAdeMO_QUANTITY
  6607. for (int index = 0; index < CCS_QUANTITY; index++)
  6608. {
  6609. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6610. {
  6611. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6612. goto end;
  6613. }
  6614. }//END FOR CCS_QUANTITY
  6615. for (int index = 0; index < GB_QUANTITY; index++)
  6616. {
  6617. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6618. {
  6619. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6620. goto end;
  6621. }
  6622. }// END FOR GB_QUANTITY
  6623. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6624. {
  6625. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6626. {
  6627. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6628. goto end;
  6629. }
  6630. }// END FOR GENERAL_GUN_QUANTITY
  6631. for (int index = 0; index < AC_QUANTITY; index++)
  6632. {
  6633. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6634. {
  6635. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6636. goto end;
  6637. }
  6638. }//END FOR AC_QUANTITY
  6639. }//END FOR AvailabilityTypeStr[Operative]
  6640. end:
  6641. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6642. {
  6643. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  6644. }
  6645. else
  6646. {
  6647. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  6648. }
  6649. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6650. {
  6651. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6652. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6653. }
  6654. else if(gunIndex == 0)
  6655. {
  6656. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6657. {
  6658. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  6659. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  6660. }
  6661. }
  6662. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  6663. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6664. return result;
  6665. }
  6666. int handleChangeConfigurationRequest(char *uuid, char *payload)
  6667. {
  6668. mtrace();
  6669. int result = FAIL;
  6670. char keystr[40]={0};
  6671. char valuestr[256]={0};
  6672. char comfirmstr[20]={0};
  6673. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  6674. json_object *ChangeConfiguration;
  6675. ChangeConfiguration = json_tokener_parse(payload);
  6676. if(!is_error(ChangeConfiguration))
  6677. {
  6678. // Required data
  6679. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  6680. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  6681. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  6682. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  6683. }
  6684. json_object_put(ChangeConfiguration);
  6685. if((uuid==NULL) || (payload ==NULL) )
  6686. {
  6687. DEBUG_ERROR("Payload is null\n");
  6688. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6689. }
  6690. else
  6691. {
  6692. int status = setKeyValue(keystr, valuestr);
  6693. switch(status)
  6694. {
  6695. case ConfigurationStatus_Accepted:
  6696. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  6697. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  6698. StoreConfigurationTable();
  6699. break;
  6700. case RebootRequired:
  6701. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  6702. StoreConfigurationTable();
  6703. break;
  6704. case NotSupported:
  6705. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  6706. break;
  6707. case ConfigurationStatus_Rejected:
  6708. default:
  6709. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6710. break;
  6711. }
  6712. }
  6713. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  6714. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  6715. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6716. {
  6717. ChageWebSocketPingInterval(atoi(valuestr));
  6718. }
  6719. if((strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6720. {
  6721. SetOcppConnStatus(FALSE);
  6722. }
  6723. return result;
  6724. }
  6725. int handleClearCacheRequest(char *uuid, char *payload)
  6726. {
  6727. mtrace();
  6728. int result = FAIL;
  6729. char comfirmstr[20];
  6730. char rmFileCmd[100]={0};
  6731. struct stat stats;
  6732. DEBUG_INFO("handleClearCacheRequest...\n");
  6733. stat("/Storage/OCPP", &stats);
  6734. // Check for directory existence
  6735. if (S_ISDIR(stats.st_mode) == 1)
  6736. {}
  6737. else
  6738. {
  6739. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  6740. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  6741. system(rmFileCmd);
  6742. }
  6743. if(OCPP_cleanLocalCache())
  6744. {
  6745. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  6746. }
  6747. else
  6748. {
  6749. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  6750. }
  6751. sendClearCacheConfirmation(uuid, comfirmstr);
  6752. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6753. return result;
  6754. }
  6755. int handleClearChargingProfileRequest(char *uuid, char *payload)
  6756. {
  6757. mtrace();
  6758. int result = FAIL;
  6759. int resultRename;
  6760. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  6761. char chargingProfilePurposeStr[26]={0};
  6762. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  6763. char tempchargingProfilePurposeStr[26]={0};
  6764. char str[100]={0};
  6765. char fname[200]={0};
  6766. char comfirmstr[20]={0};
  6767. char word[1600]={0};
  6768. int clearflag = FALSE;
  6769. int chargingProfileIdIsNULL = FALSE;
  6770. int connectorIsNULL = FALSE;
  6771. int chargingProfilePurposeIsNULL = FALSE;
  6772. int stackLevelIsNULL = FALSE;
  6773. //int GotoEnd = FALSE;
  6774. FILE *fptr1, *fptr2;
  6775. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  6776. int n_chargingProfile=0;
  6777. int isEmptyFile = FALSE;
  6778. char sLineWord[1600]={0};
  6779. char chargingProfiles[10][100]={0};
  6780. int ChargeProfileCount = 0;
  6781. int ch;
  6782. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  6783. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  6784. json_object *ClearChargingProfile;
  6785. ClearChargingProfile = json_tokener_parse(payload);
  6786. if(!is_error(ClearChargingProfile))
  6787. {
  6788. // Optional data
  6789. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  6790. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  6791. else
  6792. chargingProfileIdIsNULL = TRUE;
  6793. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  6794. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  6795. else
  6796. connectorIsNULL = TRUE;
  6797. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  6798. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  6799. else
  6800. chargingProfilePurposeIsNULL = TRUE;
  6801. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  6802. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  6803. else
  6804. stackLevelIsNULL = TRUE;
  6805. }
  6806. json_object_put(ClearChargingProfile);
  6807. if(connectorIsNULL == FALSE)
  6808. {
  6809. switch(connectorIdInt)
  6810. {
  6811. case 0:
  6812. if(chargingProfilePurposeIsNULL == TRUE)
  6813. {
  6814. int l = 0;
  6815. strcpy(fname, ChargePointMaxProfile_JSON);
  6816. if((access(fname,F_OK))!=-1)
  6817. {
  6818. strcpy(chargingProfiles[l], fname);
  6819. l = l + 1;
  6820. }
  6821. strcpy(fname, TxDefaultProfile_0_JSON);
  6822. if((access(fname,F_OK))!=-1)
  6823. {
  6824. strcpy(chargingProfiles[l], fname);
  6825. l = l + 1;
  6826. }
  6827. ChargeProfileCount = l;
  6828. }
  6829. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  6830. {
  6831. strcpy(fname, ChargePointMaxProfile_JSON);
  6832. if((access(fname,F_OK))!=-1)
  6833. {
  6834. strcpy(chargingProfiles[0], fname);
  6835. ChargeProfileCount = 1;
  6836. }
  6837. }
  6838. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6839. {
  6840. strcpy(fname, TxDefaultProfile_0_JSON);
  6841. if((access(fname,F_OK))!=-1)
  6842. {
  6843. strcpy(chargingProfiles[0], fname);
  6844. ChargeProfileCount = 1;
  6845. }
  6846. }
  6847. break;
  6848. default:
  6849. if(chargingProfilePurposeIsNULL == TRUE)
  6850. {
  6851. int m = 0;
  6852. memset(fname, 0, ARRAY_SIZE(fname));
  6853. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6854. if((access(fname,F_OK))!=-1)
  6855. {
  6856. strcpy(chargingProfiles[m], fname);
  6857. m = m + 1;
  6858. }
  6859. memset(fname, 0, ARRAY_SIZE(fname));
  6860. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6861. if((access(fname,F_OK))!=-1)
  6862. {
  6863. strcpy(chargingProfiles[m], fname);
  6864. m = m + 1;
  6865. }
  6866. ChargeProfileCount = m;
  6867. }
  6868. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6869. {
  6870. //strcpy(fname, TxDefaultProfile_1_JSON);
  6871. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6872. if((access(fname,F_OK))!=-1)
  6873. {
  6874. strcpy(chargingProfiles[0], fname);
  6875. ChargeProfileCount = 1;
  6876. }
  6877. }
  6878. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  6879. {
  6880. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6881. if((access(fname,F_OK))!=-1)
  6882. {
  6883. strcpy(chargingProfiles[0], fname);
  6884. ChargeProfileCount = 1;
  6885. }
  6886. //strcpy(fname, TxProfile_1_JSON);
  6887. }
  6888. //strcpy(fname, ChargePointMaxProfile_JSON );
  6889. break;
  6890. }
  6891. }
  6892. else // Check all Charging Profiles
  6893. {
  6894. int i = 0;
  6895. char fnametemp[200]={0};
  6896. ChargeProfileCount = 0;
  6897. //Check ChargePointMaxProfile.json exit
  6898. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  6899. {
  6900. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  6901. i = i + 1;
  6902. }
  6903. //Check TxDefaultProfile_0.json exit
  6904. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  6905. {
  6906. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  6907. i = i + 1;
  6908. }
  6909. //Check TxDefaultProfile_%d.json
  6910. for(int j=1; j <= gunTotalNumber; j++)
  6911. {
  6912. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6913. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  6914. if((access(fnametemp,F_OK))!=-1)
  6915. {
  6916. strcpy(chargingProfiles[i], fnametemp);
  6917. i = i + 1;
  6918. }
  6919. }
  6920. //Check TxProfile_%d.json
  6921. for(int j=1; j <= gunTotalNumber; j++)
  6922. {
  6923. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6924. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  6925. if((access(fnametemp,F_OK))!=-1)
  6926. {
  6927. strcpy(chargingProfiles[i], fnametemp);
  6928. i = i + 1;
  6929. }
  6930. }
  6931. ChargeProfileCount = i;
  6932. }// End connectorIsNULL is TRUE
  6933. if(ChargeProfileCount == 0)
  6934. {
  6935. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6936. goto end;
  6937. }
  6938. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  6939. {
  6940. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6941. goto end;
  6942. }
  6943. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  6944. {
  6945. memset(str, 0, ARRAY_SIZE(str));
  6946. // clear temp file
  6947. sprintf(str,"rm -f %s",temp);
  6948. system(str);
  6949. for(int k=0; k < ChargeProfileCount; k++)
  6950. {
  6951. memset(str, 0, ARRAY_SIZE(str));
  6952. //clear file in C
  6953. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6954. system(str);
  6955. }
  6956. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6957. goto end;
  6958. }
  6959. else if(connectorIsNULL == TRUE)
  6960. {
  6961. for(int k=0; k < ChargeProfileCount; k++)
  6962. {
  6963. fptr1 = fopen(chargingProfiles[k], "r");
  6964. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  6965. //Check Charging Profile Count
  6966. while(fscanf(fptr1, "%s", word) != EOF)
  6967. {
  6968. //DEBUG_INFO("word=%s\n",word);
  6969. if(strstr(word, "chargingProfileId")!= NULL)
  6970. {
  6971. //DEBUG_INFO("test chargingProfileId \n");
  6972. n_chargingProfile = n_chargingProfile + 1;
  6973. //DEBUG_INFO("chargingProfileId Found\n");
  6974. }
  6975. }
  6976. rewind(fptr1);
  6977. //search Charging Profile Element
  6978. //int i= 0;
  6979. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6980. {
  6981. json_object *tmpProfilee;
  6982. tmpProfilee = json_tokener_parse(sLineWord);
  6983. if(!is_error(tmpProfilee))
  6984. {
  6985. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  6986. {
  6987. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  6988. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  6989. }
  6990. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  6991. {
  6992. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  6993. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  6994. }
  6995. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  6996. {
  6997. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  6998. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  6999. }
  7000. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7001. {
  7002. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7003. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7004. }
  7005. }
  7006. json_object_put(tmpProfilee);
  7007. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7008. {
  7009. //------- not write to fptr2-------//
  7010. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7011. //clearflag = TRUE;
  7012. }
  7013. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7014. {
  7015. //------- not write to fptr2-------//
  7016. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7017. }
  7018. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7019. {
  7020. //------- not write to fptr2-------//
  7021. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7022. }
  7023. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  7024. {
  7025. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7026. }
  7027. else
  7028. {
  7029. fprintf(fptr2, sLineWord);//writing data into file
  7030. }
  7031. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7032. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7033. if(clearflag == TRUE)
  7034. {
  7035. fclose(fptr1);
  7036. fclose(fptr2);
  7037. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7038. system(str);
  7039. // clear temp file
  7040. sprintf(str,"rm -f %s",temp);
  7041. system(str);
  7042. }
  7043. else
  7044. {
  7045. fclose(fptr1);
  7046. fclose(fptr2);
  7047. memset(str, 0, ARRAY_SIZE(str));
  7048. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7049. system(str);
  7050. resultRename = rename(temp, chargingProfiles[k]);
  7051. if(resultRename == 0)
  7052. {
  7053. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  7054. }
  7055. else
  7056. {
  7057. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  7058. }
  7059. if(comfirmstr[0]== 0)
  7060. {
  7061. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7062. }
  7063. //Check chargingProfile is empty file
  7064. /*------ Read the file ----------------*/
  7065. fptr1=fopen(chargingProfiles[k],"r");
  7066. ch=fgetc(fptr1);
  7067. rewind(fptr1);
  7068. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7069. if(ch!=EOF)
  7070. {
  7071. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7072. {
  7073. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7074. if(sLineWord[0]=='\0')
  7075. {
  7076. isEmptyFile = TRUE;
  7077. break;
  7078. }
  7079. else
  7080. {
  7081. isEmptyFile = FALSE;
  7082. break;
  7083. }
  7084. }
  7085. }
  7086. else
  7087. isEmptyFile = TRUE;
  7088. fclose(fptr1);
  7089. if(isEmptyFile == TRUE)
  7090. {
  7091. memset(str, 0, ARRAY_SIZE(str));
  7092. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7093. system(str);
  7094. }
  7095. }
  7096. }// End of while(int k=0; k < ChargePointCount; k++)
  7097. }
  7098. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  7099. {
  7100. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  7101. for(int k=0; k < ChargeProfileCount; k++)
  7102. {
  7103. fptr1 = fopen(chargingProfiles[k], "r");
  7104. fptr2 = fopen(temp, "w+");
  7105. //Check Charging Profile Count
  7106. while(fscanf(fptr1, "%s", word) != EOF)
  7107. {
  7108. //DEBUG_INFO("word=%s\n",word);
  7109. if(strstr(word, "chargingProfileId")!= NULL)
  7110. {
  7111. n_chargingProfile = n_chargingProfile + 1;
  7112. }
  7113. }
  7114. rewind(fptr1);
  7115. //search Charging Profile Element
  7116. //int i= 0;
  7117. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7118. {
  7119. json_object *tmpProfilee;
  7120. tmpProfilee = json_tokener_parse(sLineWord);
  7121. if(!is_error(tmpProfilee))
  7122. {
  7123. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7124. {
  7125. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7126. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7127. }
  7128. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7129. {
  7130. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7131. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7132. }
  7133. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7134. {
  7135. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7136. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7137. }
  7138. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7139. {
  7140. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7141. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7142. }
  7143. }
  7144. json_object_put(tmpProfilee);
  7145. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7146. {
  7147. //------- not write to fptr2-------//
  7148. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7149. //clearflag = TRUE;
  7150. }
  7151. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7152. {
  7153. //------- not write to fptr2-------//
  7154. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7155. }
  7156. else if(stackLevelIsNULL == TRUE)
  7157. {
  7158. //Clear Whole File
  7159. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7160. clearflag = TRUE;
  7161. break;
  7162. }
  7163. else
  7164. {
  7165. fprintf(fptr2, sLineWord);//writing data into file
  7166. }
  7167. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7168. }
  7169. if(clearflag == TRUE)
  7170. {
  7171. fclose(fptr1);
  7172. fclose(fptr2);
  7173. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7174. system(str);
  7175. // clear temp file
  7176. sprintf(str,"rm -f %s",temp);
  7177. system(str);
  7178. }
  7179. else
  7180. {
  7181. fclose(fptr1);
  7182. fclose(fptr2);
  7183. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7184. system(str);
  7185. resultRename = rename(temp, chargingProfiles[k]);
  7186. if(resultRename == 0)
  7187. {
  7188. DEBUG_INFO("File ChargingProfile renamed successfully");
  7189. }
  7190. else
  7191. {
  7192. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  7193. }
  7194. if(comfirmstr[0]== 0)
  7195. {
  7196. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7197. }
  7198. //Check chargingProfile is empty file
  7199. /*------ Read the file ----------------*/
  7200. fptr1=fopen(chargingProfiles[k],"r");
  7201. ch=fgetc(fptr1);
  7202. rewind(fptr1);
  7203. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7204. if(ch!=EOF)
  7205. {
  7206. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7207. {
  7208. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7209. if(sLineWord[0]=='\0')
  7210. {
  7211. isEmptyFile = TRUE;
  7212. break;
  7213. }
  7214. else
  7215. {
  7216. isEmptyFile = FALSE;
  7217. break;
  7218. }
  7219. }
  7220. }
  7221. else
  7222. isEmptyFile = TRUE;
  7223. fclose(fptr1);
  7224. if(isEmptyFile == TRUE)
  7225. {
  7226. memset(str, 0, ARRAY_SIZE(str));
  7227. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7228. system(str);
  7229. }
  7230. /*------- End of reading ---------------*/
  7231. }
  7232. } // while(int k=0; k < ChargeProfileCount; k++)
  7233. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  7234. end:
  7235. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  7236. {
  7237. if(connectorIdInt == 0)
  7238. {
  7239. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  7240. {
  7241. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  7242. }
  7243. }
  7244. else
  7245. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  7246. }
  7247. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  7248. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7249. return result;
  7250. }
  7251. void createFirmwareVersionByDataTransfer(void)
  7252. {
  7253. json_object *FirmwareDataTransfer = json_object_new_object();
  7254. // AC & DC model
  7255. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  7256. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  7257. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  7258. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  7259. // DC model
  7260. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O')
  7261. {
  7262. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  7263. {
  7264. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7265. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7266. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  7267. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  7268. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7269. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7270. }
  7271. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  7272. ((gunType[1] != GUN_TYPE_UNKNOWN) || (gunType[2] != GUN_TYPE_UNKNOWN) || (gunType[3] != GUN_TYPE_UNKNOWN)))
  7273. {
  7274. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  7275. }
  7276. }
  7277. else
  7278. {
  7279. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7280. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7281. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7282. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7283. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  7284. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  7285. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  7286. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  7287. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  7288. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  7289. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  7290. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  7291. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  7292. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  7293. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  7294. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  7295. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  7296. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  7297. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  7298. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  7299. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  7300. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  7301. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  7302. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  7303. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  7304. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  7305. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  7306. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  7307. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  7308. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  7309. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  7310. }
  7311. // 4G model
  7312. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  7313. {
  7314. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  7315. }
  7316. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  7317. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  7318. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  7319. json_object_put(FirmwareDataTransfer);
  7320. }
  7321. int handleDataTransferRequest(char *uuid, char *payload)
  7322. {
  7323. mtrace();
  7324. json_object *response = json_object_new_object();
  7325. int result = FAIL;
  7326. char tempvendorId[255]={0};
  7327. char tempmessageId[50]={0};
  7328. char tempdata[512]={0};
  7329. char message[2048]={0};
  7330. DEBUG_INFO("handleDataTransferRequest...\n");
  7331. if((uuid != NULL) && (payload != NULL))
  7332. {
  7333. json_object *DataTransfer;
  7334. DataTransfer = json_tokener_parse(payload);
  7335. if(!is_error(DataTransfer))
  7336. {
  7337. // Required data
  7338. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  7339. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  7340. // Optional data
  7341. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  7342. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  7343. if(json_object_object_get(DataTransfer, "data") != NULL)
  7344. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  7345. result = PASS;
  7346. }
  7347. json_object_put(DataTransfer);
  7348. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  7349. {
  7350. // Send all moudle firmware version on EVSE
  7351. createFirmwareVersionByDataTransfer();
  7352. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7353. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  7354. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7355. json_object_put(response);
  7356. }
  7357. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  7358. {
  7359. system("/usr/bin/run_tmate_restart.sh &");
  7360. }
  7361. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  7362. {
  7363. json_object *data;
  7364. data = json_tokener_parse(tempdata);
  7365. if(!is_error(data))
  7366. {
  7367. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  7368. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  7369. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  7370. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  7371. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  7372. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  7373. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  7374. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  7375. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  7376. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  7377. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7378. }
  7379. else
  7380. {
  7381. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7382. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7383. }
  7384. json_object_put(data);
  7385. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7386. json_object_put(response);
  7387. }
  7388. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  7389. {
  7390. json_object *data;
  7391. data = json_tokener_parse(tempdata);
  7392. if(!is_error(data))
  7393. {
  7394. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  7395. if(json_object_object_get(data, "idToken") != NULL)
  7396. {
  7397. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  7398. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  7399. }
  7400. if(json_object_object_get(data, "price") != NULL)
  7401. {
  7402. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  7403. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  7404. }
  7405. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7406. }
  7407. else
  7408. {
  7409. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7410. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7411. }
  7412. json_object_put(data);
  7413. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7414. json_object_put(response);
  7415. }
  7416. else if(strstr(tempmessageId, "RunningCost") != NULL)
  7417. {
  7418. json_object *data;
  7419. data = json_tokener_parse(tempdata);
  7420. if(!is_error(data))
  7421. {
  7422. if(json_object_object_get(data, "txId") != NULL)
  7423. {
  7424. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7425. for(int idx = 0;idx<gunTotalNumber;idx++)
  7426. {
  7427. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7428. {
  7429. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  7430. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7431. if(json_object_object_get(data, "description") != NULL)
  7432. {
  7433. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7434. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7435. }
  7436. }
  7437. }
  7438. }
  7439. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7440. }
  7441. else
  7442. {
  7443. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7444. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7445. }
  7446. json_object_put(data);
  7447. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7448. json_object_put(response);
  7449. }
  7450. else if(strstr(tempmessageId, "FinalCost") != NULL)
  7451. {
  7452. json_object *data;
  7453. data = json_tokener_parse(tempdata);
  7454. if(!is_error(data))
  7455. {
  7456. if(json_object_object_get(data, "txId") != NULL)
  7457. {
  7458. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7459. for(int idx = 0;idx<gunTotalNumber;idx++)
  7460. {
  7461. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7462. {
  7463. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  7464. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7465. if(json_object_object_get(data, "description") != NULL)
  7466. {
  7467. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7468. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7469. }
  7470. }
  7471. }
  7472. }
  7473. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7474. }
  7475. else
  7476. {
  7477. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7478. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7479. }
  7480. json_object_put(data);
  7481. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7482. json_object_put(response);
  7483. }
  7484. else
  7485. {
  7486. // Can not find valid message id
  7487. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  7488. }
  7489. }
  7490. else
  7491. {
  7492. // Payload is null
  7493. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  7494. }
  7495. LWS_Send(message);
  7496. return result;
  7497. }
  7498. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  7499. {
  7500. mtrace();
  7501. int result = FAIL;
  7502. int connectorIdInt, durationInt;
  7503. char chargingRateUnitStr[4]={0};
  7504. char comfirmstr[20];
  7505. int confirmPeriods = 0;
  7506. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  7507. json_object *GetCompositeSchedule;
  7508. GetCompositeSchedule = json_tokener_parse(payload);
  7509. if(!is_error(GetCompositeSchedule))
  7510. {
  7511. // Required data
  7512. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  7513. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  7514. else
  7515. connectorIdInt = -1;
  7516. if(json_object_object_get(GetCompositeSchedule, "duration"))
  7517. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  7518. else
  7519. durationInt = 86400;
  7520. // Optional data
  7521. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  7522. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  7523. }
  7524. json_object_put(GetCompositeSchedule);
  7525. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  7526. if((connectorIdInt == 0) ||
  7527. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  7528. {
  7529. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  7530. struct StructChargingProfile tmpProfile[1];
  7531. if(strstr(chargingRateUnitStr, "W") != NULL)
  7532. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  7533. else
  7534. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  7535. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7536. {
  7537. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7538. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7539. }
  7540. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  7541. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  7542. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  7543. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7544. {
  7545. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7546. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7547. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  7548. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0))
  7549. {
  7550. confirmPeriods = idx;
  7551. break;
  7552. }
  7553. }
  7554. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  7555. }
  7556. else
  7557. {
  7558. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  7559. }
  7560. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  7561. return result;
  7562. }
  7563. int handleGetConfigurationRequest(char *uuid, char *payload)
  7564. {
  7565. mtrace();
  7566. int result = FAIL;
  7567. int MaxKeySupported = 0;
  7568. int n_keys = 0;
  7569. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  7570. DEBUG_INFO("handleGetConfigurationRequest...\n");
  7571. json_object *GetConfiguration;
  7572. GetConfiguration = json_tokener_parse(payload);
  7573. if(!is_error(GetConfiguration))
  7574. {
  7575. // Optional data
  7576. if(json_object_object_get(GetConfiguration, "key") != NULL)
  7577. {
  7578. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  7579. {
  7580. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  7581. n_keys = idx + 1;
  7582. }
  7583. }
  7584. }
  7585. json_object_put(GetConfiguration);
  7586. UnknownKeynum = 0;
  7587. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  7588. MaxKeySupported = GetConfigurationMaxKeysNUM;
  7589. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  7590. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  7591. if(n_keys != 0)
  7592. {
  7593. for(int i=0;i<n_keys;i++)
  7594. {
  7595. getKeyValue(requestKey[i]);
  7596. }
  7597. }
  7598. else
  7599. {
  7600. DEBUG_INFO("There is no key in Message, get all configuration\n");
  7601. getKeyValue("");
  7602. }
  7603. processUnkownKey();
  7604. sendGetConfigurationConfirmation(uuid);
  7605. return result;
  7606. }
  7607. static char fnamePlusPath[100]={0};
  7608. static char fnamePWithNoPath[60]={0};
  7609. void checkUploadLog(void)
  7610. {
  7611. FILE *fp;
  7612. /* Open the command for reading. */
  7613. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  7614. if (fp == NULL) {
  7615. printf("Failed to run command\n" );
  7616. exit(1);
  7617. }
  7618. int ftppathlen = 0;
  7619. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  7620. int i = 0;
  7621. /* Read the output a line at a time - output it. */
  7622. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  7623. if(i==0)
  7624. {
  7625. ftppathlen = strlen(fnamePlusPath);
  7626. printf("%s\n", fnamePlusPath);
  7627. fnamePlusPath[ftppathlen]='\0';
  7628. break;
  7629. }
  7630. i= i+1;
  7631. }
  7632. /* close */
  7633. pclose(fp);
  7634. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  7635. {
  7636. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  7637. {
  7638. fnamePlusPath[k]='\0';
  7639. }
  7640. }
  7641. i=1;
  7642. //char fname[60]={0};
  7643. while(i < ftppathlen)
  7644. {
  7645. int len=ftppathlen-i;
  7646. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  7647. {
  7648. printf("compare '/' all right\n");
  7649. break;
  7650. }
  7651. i=i+1;
  7652. }
  7653. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  7654. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  7655. fnamePWithNoPath[i+1] = '\0';
  7656. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  7657. {
  7658. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  7659. {
  7660. fnamePWithNoPath[j]='\0';
  7661. }
  7662. }
  7663. FILE* fp1 = fopen(fnamePlusPath, "r");
  7664. if (fp1)
  7665. {
  7666. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  7667. // file exists
  7668. fclose(fp1);
  7669. }
  7670. else
  7671. {
  7672. // file doesn't exist
  7673. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  7674. }
  7675. }
  7676. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  7677. {
  7678. mtrace();
  7679. int result = FAIL;
  7680. time_t CurrentTime;
  7681. struct tm *tm;
  7682. pthread_t th_Status;
  7683. CurrentTime = time(NULL);
  7684. tm = localtime(&CurrentTime);
  7685. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  7686. 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);
  7687. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  7688. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  7689. return result;
  7690. }
  7691. void* GetDiagnosticsProcess(void* data)
  7692. {
  7693. pthread_detach(pthread_self());
  7694. mtrace();
  7695. int retriesInt=0, retryIntervalInt=0;
  7696. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  7697. 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};
  7698. int port=0;
  7699. int isSuccess = FALSE;
  7700. char ftpbuf[200]={0};
  7701. char cmdBuf[2048];
  7702. struct tm *tmNow;
  7703. time_t CurrentTime;
  7704. struct tm tmStart;
  7705. struct tm tmStop;
  7706. CurrentTime = time(NULL);
  7707. tmNow=localtime(&CurrentTime);
  7708. uint16_t targetYear, targetMonth;
  7709. json_object *GetDiagnostics;
  7710. DEBUG_INFO("GetDiagnosticsProcess...\n");
  7711. GetDiagnostics = json_tokener_parse(data);
  7712. if(!is_error(GetDiagnostics))
  7713. {
  7714. // Required data
  7715. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  7716. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  7717. // Optional data
  7718. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  7719. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  7720. else
  7721. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  7722. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  7723. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  7724. else
  7725. retryIntervalInt = 30;
  7726. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  7727. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  7728. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  7729. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  7730. }
  7731. json_object_put(GetDiagnostics);
  7732. // Pack log to compress file
  7733. 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) &&
  7734. (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))
  7735. {
  7736. // Pack system log
  7737. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  7738. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  7739. targetYear = tmStart.tm_year;
  7740. targetMonth = tmStart.tm_mon;
  7741. do
  7742. {
  7743. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7744. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7745. if(targetMonth+1>=13)
  7746. {
  7747. targetYear += 1;
  7748. targetMonth = 1;
  7749. }
  7750. else
  7751. {
  7752. targetMonth += 1;
  7753. }
  7754. }while((targetYear < (tmNow->tm_year+1900)) ||
  7755. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  7756. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  7757. system(cmdBuf);
  7758. // Pack charging & event log
  7759. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  7760. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  7761. targetYear = tmStart.tm_year;
  7762. targetMonth = tmStart.tm_mon;
  7763. do
  7764. {
  7765. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7766. if(targetMonth+1>=13)
  7767. {
  7768. targetYear += 1;
  7769. targetMonth = 1;
  7770. }
  7771. else
  7772. {
  7773. targetMonth += 1;
  7774. }
  7775. }while((targetYear < (tmNow->tm_year+1900)) ||
  7776. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  7777. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  7778. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  7779. system(cmdBuf);
  7780. // Combine log file
  7781. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  7782. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  7783. }
  7784. else
  7785. {
  7786. system("exec /root/logPackTools 'log' 6");
  7787. }
  7788. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  7789. system(cmdBuf);
  7790. checkUploadLog();
  7791. //****************location*******************/
  7792. if(strcmp(locationstr,"")==0)
  7793. {
  7794. DEBUG_INFO("location is <Empty>!\n");
  7795. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7796. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7797. goto end;
  7798. }
  7799. memset(protocol, 0, ARRAY_SIZE(protocol));
  7800. memset(user, 0, ARRAY_SIZE(user) );
  7801. memset(password, 0, ARRAY_SIZE(password));
  7802. memset(host, 0, ARRAY_SIZE(host));
  7803. memset(path, 0, ARRAY_SIZE(path));
  7804. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  7805. memset(host1, 0, ARRAY_SIZE(host1));
  7806. memset(path1, 0, ARRAY_SIZE(path1));
  7807. /*location: ftp://user:password@host:port/path*/
  7808. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  7809. if((access(fnamePlusPath,F_OK))!=-1)
  7810. {
  7811. DEBUG_INFO("fnamePlusPath exist.\n");
  7812. }
  7813. else
  7814. {
  7815. DEBUG_INFO("fnamePlusPath not exist!\n");
  7816. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7817. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7818. goto end;
  7819. }
  7820. if(strchr(locationstr,'@')==NULL)
  7821. {
  7822. sscanf(locationstr,
  7823. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  7824. protocol, host, &port, path);
  7825. strcpy(user,"anonymous");
  7826. strcpy(password,"");
  7827. }
  7828. else
  7829. {
  7830. //DEBUG_INFO("pch=%s\n", pch);
  7831. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  7832. protocol, user, password, host, &port, path);
  7833. }
  7834. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  7835. {
  7836. DEBUG_INFO("protocol is not ftp/http ! \n");
  7837. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7838. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7839. goto end;
  7840. }
  7841. if(strncmp(locationstr,"http", 4) == 0)
  7842. {
  7843. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  7844. sprintf(ftppath,"/%s", path);
  7845. do
  7846. {
  7847. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  7848. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7849. sleep(3);
  7850. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  7851. if(!isSuccess)
  7852. {
  7853. DEBUG_INFO("Diagnostics fail.\n");
  7854. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7855. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7856. sleep(retryIntervalInt);
  7857. }
  7858. else
  7859. {
  7860. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  7861. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  7862. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7863. }
  7864. retriesInt--;
  7865. }while((isSuccess == 0)&&(retriesInt >= 0));
  7866. }
  7867. else
  7868. {
  7869. sscanf(host,"%[^/]%s",host1, path1);
  7870. if(strlen(path) > 0)
  7871. sprintf(ftppath,"/%s", path);
  7872. else
  7873. sprintf(ftppath,"/%s", path1);
  7874. int ftppathlen=strlen(ftppath);
  7875. int i=1;
  7876. char filenametemp[50];
  7877. while(i < ftppathlen)
  7878. {
  7879. int len=ftppathlen-i;
  7880. if(ftppath[len]== 47) // '/' ascll code: 47
  7881. {
  7882. DEBUG_INFO("find '/' all right\n");
  7883. break;
  7884. }
  7885. i=i+1;
  7886. }
  7887. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  7888. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  7889. filenametemp[i+1] = 0;
  7890. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  7891. if(port == 0)
  7892. port = 21;
  7893. do
  7894. {
  7895. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  7896. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7897. sleep(3);
  7898. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  7899. if(!isSuccess)
  7900. {
  7901. DEBUG_INFO("Diagnostics fail.\n");
  7902. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7903. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7904. sleep(retryIntervalInt);
  7905. }
  7906. else
  7907. {
  7908. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  7909. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  7910. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7911. }
  7912. retriesInt--;
  7913. }while((!isSuccess)&&(retriesInt >= 0));
  7914. }
  7915. end:
  7916. system("rm -f /mnt/*");
  7917. sleep(5);
  7918. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  7919. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7920. pthread_exit(NULL);
  7921. }
  7922. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  7923. {
  7924. mtrace();
  7925. int result = FAIL;
  7926. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  7927. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  7928. {
  7929. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  7930. localversion = -1;
  7931. }
  7932. else
  7933. {
  7934. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  7935. OCPP_getListVerion();
  7936. }
  7937. //from db.OCPP_getListVerion
  7938. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  7939. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  7940. sendGetLocalListVersionConfirmation(uuid,"");
  7941. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  7942. return result;
  7943. }
  7944. int handleRemoteStartRequest(char *uuid, char *payload)
  7945. {
  7946. mtrace();
  7947. int result = FAIL;
  7948. int connectorIdInt=0;
  7949. int tempIndex = 0;
  7950. int connectorIdIsNULL, chargingProfileIsNULL;
  7951. char comfirmstr[20]={0};
  7952. char cmdBuf[512];
  7953. json_object *RemoteStartTransaction;
  7954. FILE *fp;
  7955. DEBUG_INFO("handleRemoteStartRequest ...\n");
  7956. if(server_pending == TRUE)
  7957. {
  7958. return 0;
  7959. }
  7960. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  7961. RemoteStartTransaction = json_tokener_parse(payload);
  7962. if(!is_error(RemoteStartTransaction))
  7963. {
  7964. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  7965. {
  7966. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  7967. if(connectorIdInt <= gunTotalNumber)
  7968. {
  7969. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  7970. // Required data
  7971. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  7972. // Optional data
  7973. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  7974. {
  7975. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  7976. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  7977. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  7978. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  7979. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  7980. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  7981. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  7982. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  7983. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  7984. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  7985. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  7986. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  7987. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  7988. {
  7989. 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")));
  7990. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  7991. 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"));
  7992. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  7993. 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"));
  7994. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  7995. 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")));
  7996. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  7997. {
  7998. 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++)
  7999. {
  8000. 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"));
  8001. 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"));
  8002. 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)
  8003. 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"));
  8004. }
  8005. }
  8006. }
  8007. }
  8008. else
  8009. chargingProfileIsNULL = TRUE;
  8010. }
  8011. }
  8012. else
  8013. connectorIdIsNULL = TRUE;
  8014. }
  8015. else
  8016. connectorIdIsNULL = TRUE;
  8017. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  8018. {
  8019. DEBUG_WARN("Connector id is NULL\n.");
  8020. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8021. goto end;
  8022. }
  8023. /*
  8024. enum _SYSTEM_STATUS
  8025. {
  8026. S_BOOTING = 0,
  8027. S_IDLE, = 1
  8028. S_AUTHORIZING, = 2
  8029. S_REASSIGN_CHECK, = 3
  8030. S_REASSIGN, = 4
  8031. S_PRECHARGE, = 5
  8032. S_PREPARING_FOR_EV, = 6
  8033. S_PREPARING_FOR_EVSE, = 7
  8034. S_CHARGING, = 8
  8035. S_TERMINATING, = 9
  8036. S_COMPLETE, = 10
  8037. S_ALARM, = 11
  8038. S_FAULT = 12
  8039. }
  8040. */
  8041. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  8042. {
  8043. //check Transaction active
  8044. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8045. {
  8046. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8047. {
  8048. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8049. }
  8050. else
  8051. {
  8052. tempIndex = connectorIdInt -1;
  8053. }
  8054. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8055. {
  8056. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  8057. {
  8058. 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))
  8059. {
  8060. //Reserved
  8061. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8062. }
  8063. 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))
  8064. {
  8065. //Reserved
  8066. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8067. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8068. goto end;
  8069. }
  8070. else
  8071. {
  8072. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8073. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  8074. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  8075. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  8076. {
  8077. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  8078. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8079. goto end;
  8080. }
  8081. }//END FOR ELSE
  8082. }
  8083. }// END FOR CHAdeMO_QUANTITY
  8084. }
  8085. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8086. {
  8087. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8088. {
  8089. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8090. }
  8091. else
  8092. {
  8093. tempIndex = connectorIdInt -1;
  8094. }
  8095. for (int index = 0; index < CCS_QUANTITY; index++)
  8096. {
  8097. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8098. {
  8099. 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))
  8100. {
  8101. //Reserved
  8102. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8103. }
  8104. 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))
  8105. {
  8106. //Reserved
  8107. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8108. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8109. goto end;
  8110. }
  8111. else
  8112. {
  8113. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8114. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8115. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8116. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8117. {
  8118. DEBUG_WARN("CCS connector not allow start\n.");
  8119. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8120. goto end;
  8121. }
  8122. }// END FOR ELSE
  8123. }
  8124. }// END FOR CCS_QUANTITY
  8125. }
  8126. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8127. {
  8128. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8129. {
  8130. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8131. }
  8132. else
  8133. {
  8134. tempIndex = connectorIdInt -1;
  8135. }
  8136. for (int index = 0; index < GB_QUANTITY; index++)
  8137. {
  8138. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  8139. {
  8140. 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))
  8141. {
  8142. //Reserved
  8143. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8144. }
  8145. 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))
  8146. {
  8147. //Reserved
  8148. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8149. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8150. goto end;
  8151. }
  8152. else
  8153. {
  8154. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8155. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8156. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8157. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8158. {
  8159. DEBUG_WARN("GB connector not allow start\n.");
  8160. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8161. goto end;
  8162. }
  8163. }// END FOR ELSE
  8164. }
  8165. } // END FOR GB_QUANTITY
  8166. }
  8167. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8168. {
  8169. tempIndex = connectorIdInt -1;
  8170. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8171. {
  8172. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  8173. {
  8174. 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))
  8175. {
  8176. //Reserved
  8177. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8178. }
  8179. 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))
  8180. {
  8181. //Reserved
  8182. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8183. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8184. goto end;
  8185. }
  8186. else
  8187. {
  8188. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8189. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8190. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8191. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8192. {
  8193. DEBUG_WARN("GB connector not allow start\n.");
  8194. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8195. goto end;
  8196. }
  8197. }// END FOR ELSE
  8198. }
  8199. } // END FOR GB_QUANTITY
  8200. }
  8201. else
  8202. {
  8203. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8204. {
  8205. tempIndex = 2;
  8206. }
  8207. else
  8208. {
  8209. tempIndex = connectorIdInt -1;
  8210. }
  8211. for (int index = 0; index < AC_QUANTITY; index++)
  8212. {
  8213. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  8214. {
  8215. 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))
  8216. {
  8217. //Reserved
  8218. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8219. }
  8220. 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))
  8221. {
  8222. //Reserved
  8223. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8224. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8225. goto end;
  8226. }
  8227. else
  8228. {
  8229. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8230. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8231. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8232. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8233. {
  8234. DEBUG_WARN("AC connector not allow start\n.");
  8235. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8236. goto end;
  8237. }
  8238. }//END FOR ELSE
  8239. }
  8240. }// END FOR AC_QUANTITY
  8241. }
  8242. if(chargingProfileIsNULL == FALSE)
  8243. {
  8244. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8245. {
  8246. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  8247. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8248. //memset idTag
  8249. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  8250. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8251. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  8252. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8253. // Save profile to file
  8254. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8255. system(cmdBuf);
  8256. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8257. fp = fopen(cmdBuf, "w");
  8258. 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));
  8259. fclose(fp);
  8260. }
  8261. else
  8262. {
  8263. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  8264. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8265. }
  8266. }
  8267. else
  8268. {
  8269. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  8270. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8271. //memset idTag
  8272. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  8273. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8274. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  8275. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8276. }
  8277. }
  8278. else
  8279. {
  8280. DEBUG_WARN("Connector id over\n.");
  8281. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8282. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  8283. }
  8284. end:
  8285. json_object_put(RemoteStartTransaction);
  8286. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  8287. {
  8288. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  8289. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  8290. }
  8291. //OCPP send RemoteStartConfirmation by first.
  8292. sendRemoteStartConfirmation(uuid, comfirmstr);
  8293. return result;
  8294. }
  8295. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  8296. {
  8297. mtrace();
  8298. int result = FAIL;
  8299. int match = FALSE;
  8300. int GunNO = 0;
  8301. int tempIndex = 0;
  8302. int transactionIdInt=0;
  8303. int transactionIdIsNULL= TRUE;
  8304. char comfirmstr[20];
  8305. json_object *RemoteStopTransaction;
  8306. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  8307. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  8308. if(server_pending == TRUE)
  8309. {
  8310. return 0;
  8311. }
  8312. RemoteStopTransaction = json_tokener_parse(payload);
  8313. if(!is_error(RemoteStopTransaction))
  8314. {
  8315. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  8316. {
  8317. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  8318. transactionIdIsNULL = FALSE;
  8319. }
  8320. }
  8321. json_object_put(RemoteStopTransaction);
  8322. if(transactionIdIsNULL == FALSE)
  8323. {
  8324. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  8325. {
  8326. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  8327. {
  8328. //check Transaction active
  8329. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  8330. {
  8331. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8332. {
  8333. tempIndex = ((gun_index==2) ? 1: 0);
  8334. }
  8335. else
  8336. {
  8337. tempIndex = gun_index;
  8338. }
  8339. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8340. {
  8341. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8342. {
  8343. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8344. {
  8345. match = TRUE;
  8346. GunNO = gun_index;
  8347. }
  8348. }
  8349. }// END FOR CHAdeMO_QUANTITY
  8350. }
  8351. else if(gunType[gun_index] == GUN_TYPE_CCS)
  8352. {
  8353. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8354. {
  8355. tempIndex = ((gun_index==2) ? 1: 0);
  8356. }
  8357. else
  8358. {
  8359. tempIndex = gun_index;
  8360. }
  8361. for (int index = 0; index < CCS_QUANTITY; index++)
  8362. {
  8363. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8364. {
  8365. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8366. {
  8367. match = TRUE;
  8368. GunNO = gun_index;
  8369. }
  8370. }
  8371. }// END FOR CCS_QUANTITY
  8372. }
  8373. else if(gunType[gun_index] == GUN_TYPE_GBT)
  8374. {
  8375. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8376. {
  8377. tempIndex = ((gun_index==2) ? 1: 0);
  8378. }
  8379. else
  8380. {
  8381. tempIndex = gun_index;
  8382. }
  8383. for (int index = 0; index < GB_QUANTITY; index++)
  8384. {
  8385. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8386. {
  8387. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8388. {
  8389. match = TRUE;
  8390. GunNO = gun_index;
  8391. }
  8392. }
  8393. }// END FOR GB_QUANTITY
  8394. }
  8395. else if(gunType[gun_index] == GUN_TYPE_DO)
  8396. {
  8397. tempIndex = gun_index;
  8398. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8399. {
  8400. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8401. {
  8402. 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
  8403. {
  8404. match = TRUE;
  8405. GunNO = gun_index;
  8406. }
  8407. }
  8408. }// END FOR GB_QUANTITY
  8409. }
  8410. else
  8411. {
  8412. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8413. {
  8414. tempIndex = 2;
  8415. }
  8416. else
  8417. {
  8418. tempIndex = gun_index;
  8419. }
  8420. for (int index = 0; index < AC_QUANTITY; index++)
  8421. {
  8422. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8423. {
  8424. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8425. {
  8426. match = TRUE;
  8427. GunNO = gun_index;
  8428. }
  8429. }
  8430. }// END FOR CHAdeMO_QUANTITY
  8431. } // END FOR AC ELSE
  8432. }// CHECK IF ResponseTransactionId == transactionIdInt
  8433. }//END FOR
  8434. if( match == TRUE)
  8435. {
  8436. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  8437. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8438. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  8439. }
  8440. else
  8441. {
  8442. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8443. }
  8444. }
  8445. else
  8446. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8447. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  8448. return result;
  8449. }
  8450. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  8451. {
  8452. mtrace();
  8453. int result = FAIL;
  8454. int connectorIdInt=0, reservationIdInt=0;
  8455. int tempIndex = 0;
  8456. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  8457. char comfirmstr[20]={0};
  8458. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  8459. int c = 0;
  8460. char *loc;
  8461. //char *ptr;
  8462. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  8463. strcpy(sstrtemp, stringtrimspace(payload));
  8464. //***(1)connectorId ****/
  8465. c=0;
  8466. loc = strstr(sstrtemp, "connectorId");
  8467. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8468. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  8469. {
  8470. sstr[c] = loc[strlen("connectorId")+2+c];
  8471. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8472. c++;
  8473. }
  8474. sstr[c] = '\0';
  8475. connectorIdInt = atoi(sstr);
  8476. //***(2)expiryDate ****/
  8477. loc = strstr(sstrtemp, "expiryDate");
  8478. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8479. c = 0;
  8480. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  8481. {
  8482. sstr[c] = loc[3+strlen("expiryDate")+c];
  8483. c++;
  8484. }
  8485. sstr[c] = '\0';
  8486. strcpy(expiryDatestr, sstr);
  8487. //***(3)idTag ****/
  8488. loc = strstr(sstrtemp, "idTag");
  8489. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8490. c = 0;
  8491. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  8492. {
  8493. sstr[c] = loc[3+strlen("idTag")+c];
  8494. c++;
  8495. }
  8496. sstr[c] = '\0';
  8497. strcpy(idTagstr, sstr);
  8498. //***(4)parentIdTag ****/
  8499. loc = strstr(sstrtemp, "parentIdTag");
  8500. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8501. c = 0;
  8502. if(loc == NULL)
  8503. {
  8504. strcpy(parentIdTagstr, "");
  8505. }
  8506. else
  8507. {
  8508. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8509. {
  8510. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8511. c++;
  8512. }
  8513. sstr[c] = '\0';
  8514. strcpy(parentIdTagstr, sstr);
  8515. }
  8516. //***(5)reservationId ****/
  8517. c=0;
  8518. loc = strstr(sstrtemp, "reservationId");
  8519. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8520. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  8521. {
  8522. sstr[c] = loc[strlen("reservationId")+2+c];
  8523. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8524. c++;
  8525. }
  8526. sstr[c] = '\0';
  8527. reservationIdInt = atoi(sstr);
  8528. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8529. /*
  8530. enum SYSTEM_STATUS
  8531. {
  8532. SYS_MODE_BOOTING = 0,
  8533. SYS_MODE_IDLE = 1,
  8534. SYS_MODE_AUTHORIZING = 2,
  8535. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  8536. SYS_MODE_REASSIGN = 4,
  8537. SYS_MODE_PREPARING = 5,
  8538. SYS_MODE_PREPARE_FOR_EV = 6,
  8539. SYS_MODE_PREPARE_FOR_EVSE = 7,
  8540. SYS_MODE_CHARGING = 8,
  8541. SYS_MODE_TERMINATING = 9,
  8542. SYS_MODE_COMPLETE = 10,
  8543. SYS_MODE_ALARM = 11,
  8544. SYS_MODE_FAULT = 12,
  8545. SYS_MODE_RESERVATION = 13,
  8546. SYS_MODE_BOOKING = 14,
  8547. SYS_MODE_MAINTAIN = 15,
  8548. SYS_MODE_DEBUG = 16,
  8549. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  8550. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  8551. SYS_MODE_UPDATE = 19
  8552. };
  8553. */
  8554. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  8555. {
  8556. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8557. goto end;
  8558. }
  8559. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  8560. {
  8561. //check Transaction active
  8562. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8563. {
  8564. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8565. {
  8566. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8567. }
  8568. else
  8569. {
  8570. tempIndex = connectorIdInt -1;
  8571. }
  8572. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8573. {
  8574. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8575. {
  8576. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  8577. {
  8578. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8579. {
  8580. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8581. {
  8582. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8583. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8584. }
  8585. 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'))
  8586. {
  8587. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8588. }
  8589. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8590. {
  8591. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8592. }
  8593. else
  8594. {
  8595. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8596. }
  8597. }
  8598. 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
  8599. {
  8600. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8601. }
  8602. }
  8603. else
  8604. {
  8605. //replace reservation
  8606. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8607. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8608. }
  8609. }
  8610. } // END FOR CHAdeMO_QUANTITY
  8611. }
  8612. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8613. {
  8614. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8615. {
  8616. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8617. }
  8618. else
  8619. {
  8620. tempIndex = connectorIdInt -1;
  8621. }
  8622. for (int index = 0; index < CCS_QUANTITY; index++)
  8623. {
  8624. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8625. {
  8626. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8627. {
  8628. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8629. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8630. {
  8631. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8632. {
  8633. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8634. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8635. }
  8636. 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'))
  8637. {
  8638. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8639. }
  8640. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  8641. {
  8642. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8643. }
  8644. else
  8645. {
  8646. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8647. }
  8648. }
  8649. 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
  8650. {
  8651. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8652. }
  8653. }
  8654. else
  8655. {
  8656. //replace reservation
  8657. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8658. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8659. }
  8660. }
  8661. } // END FOR CCS_QUANTITY
  8662. }
  8663. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8664. {
  8665. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8666. {
  8667. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8668. }
  8669. else
  8670. {
  8671. tempIndex = connectorIdInt -1;
  8672. }
  8673. for (int index = 0; index < GB_QUANTITY; index++)
  8674. {
  8675. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8676. {
  8677. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8678. {
  8679. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8680. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  8681. {
  8682. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8683. {
  8684. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8685. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8686. }
  8687. 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'))
  8688. {
  8689. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8690. }
  8691. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8692. {
  8693. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8694. }
  8695. else
  8696. {
  8697. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8698. }
  8699. }
  8700. 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
  8701. {
  8702. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8703. }
  8704. }
  8705. else
  8706. {
  8707. //replace reservation
  8708. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8709. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8710. }
  8711. }
  8712. }// END FOR GB_QUANTITY
  8713. }
  8714. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8715. {
  8716. tempIndex = connectorIdInt -1;
  8717. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8718. {
  8719. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8720. {
  8721. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  8722. {
  8723. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8724. 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
  8725. {
  8726. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8727. {
  8728. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8729. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8730. }
  8731. 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'))
  8732. {
  8733. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8734. }
  8735. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8736. {
  8737. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8738. }
  8739. else
  8740. {
  8741. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8742. }
  8743. }
  8744. 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
  8745. {
  8746. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8747. }
  8748. }
  8749. else
  8750. {
  8751. //replace reservation
  8752. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8753. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8754. }
  8755. }
  8756. }// END FOR GB_QUANTITY
  8757. }
  8758. else
  8759. {
  8760. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8761. {
  8762. tempIndex = 2;
  8763. }
  8764. else
  8765. {
  8766. tempIndex = (connectorIdInt -1);
  8767. }
  8768. for (int index = 0; index < AC_QUANTITY; index++)
  8769. {
  8770. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8771. {
  8772. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  8773. {
  8774. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  8775. {
  8776. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8777. {
  8778. 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))
  8779. {
  8780. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8781. }
  8782. else
  8783. {
  8784. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8785. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8786. }
  8787. }
  8788. 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'))
  8789. {
  8790. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8791. }
  8792. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8793. {
  8794. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8795. }
  8796. else
  8797. {
  8798. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8799. }
  8800. }
  8801. 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
  8802. {
  8803. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8804. }
  8805. }
  8806. else
  8807. {
  8808. //replace reservation
  8809. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8810. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8811. }
  8812. }
  8813. } // END FOR AC_QUANTITY
  8814. }
  8815. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8816. }
  8817. else if(connectorIdInt == 0)
  8818. {
  8819. //check Transaction active
  8820. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8821. {
  8822. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  8823. {
  8824. 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'))
  8825. {
  8826. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8827. goto end;
  8828. }
  8829. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8830. {
  8831. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8832. goto end;
  8833. }
  8834. 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
  8835. {
  8836. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8837. goto end;
  8838. }
  8839. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8840. {
  8841. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8842. goto end;
  8843. }
  8844. }
  8845. }// END FOR CHAdeMO_QUANTITY
  8846. for (int index = 0; index < CCS_QUANTITY; index++)
  8847. {
  8848. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8849. {
  8850. 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'))
  8851. {
  8852. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8853. goto end;
  8854. }
  8855. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  8856. {
  8857. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8858. goto end;
  8859. }
  8860. 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
  8861. {
  8862. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8863. goto end;
  8864. }
  8865. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8866. {
  8867. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8868. goto end;
  8869. }
  8870. }
  8871. } // END FOR CCS_QUANTITY
  8872. for (int index = 0; index < GB_QUANTITY; index++)
  8873. {
  8874. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8875. {
  8876. 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'))
  8877. {
  8878. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8879. goto end;
  8880. }
  8881. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8882. {
  8883. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8884. goto end;
  8885. }
  8886. 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
  8887. {
  8888. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8889. goto end;
  8890. }
  8891. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8892. {
  8893. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8894. goto end;
  8895. }
  8896. }
  8897. } // END FOR GB_QUANTITY
  8898. for (int index = 0; index < AC_QUANTITY; index++)
  8899. {
  8900. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  8901. {
  8902. 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'))
  8903. {
  8904. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8905. goto end;
  8906. }
  8907. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8908. {
  8909. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8910. goto end;
  8911. }
  8912. 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
  8913. {
  8914. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8915. goto end;
  8916. }
  8917. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8918. {
  8919. 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))
  8920. {
  8921. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8922. goto end;
  8923. }
  8924. }
  8925. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8926. {
  8927. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8928. goto end;
  8929. }
  8930. }
  8931. }// END FOR AC_QUANTITY
  8932. //The connectorId is 0
  8933. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  8934. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8935. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  8936. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  8937. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  8938. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  8939. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  8940. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  8941. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  8942. result = TRUE;
  8943. return result;
  8944. }
  8945. else
  8946. {
  8947. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8948. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8949. }
  8950. if(strcmp(comfirmstr,"Accepted") == 0)
  8951. {
  8952. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  8953. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  8954. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  8955. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  8956. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  8957. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  8958. result = TRUE;
  8959. return result;
  8960. }
  8961. end:
  8962. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  8963. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  8964. return result;
  8965. }
  8966. int handleResetRequest(char *uuid, char *payload)
  8967. {
  8968. mtrace();
  8969. int result = FAIL;
  8970. char sstr[10]={0},sstrtemp[30]={ 0 };
  8971. char typestr[10]={0};
  8972. char comfirmstr[20]={0};
  8973. int c = 0;
  8974. char *loc;
  8975. DEBUG_INFO("handleResetRequest...\n");
  8976. strcpy(sstrtemp, stringtrimspace(payload));
  8977. loc = strstr(sstrtemp, "type");
  8978. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8979. c = 0;
  8980. while (loc[3+strlen("type")+c] != '\"')
  8981. {
  8982. sstr[c] = loc[3+strlen("type")+c];
  8983. c++;
  8984. }
  8985. sstr[c] = '\0';
  8986. strcpy(typestr,sstr);
  8987. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  8988. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  8989. {
  8990. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  8991. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  8992. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  8993. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  8994. }
  8995. else
  8996. {
  8997. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  8998. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  8999. result = PASS;
  9000. }
  9001. sendResetConfirmation(uuid, comfirmstr);
  9002. return result;
  9003. }
  9004. int handleSendLocalListRequest(char *uuid, char *payload)
  9005. {
  9006. mtrace();
  9007. int result = FAIL;
  9008. int listVersionInt;
  9009. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  9010. char listsearch[]="listVersion";
  9011. char updateTypesearch[]="updateType";
  9012. char localAuthorizationListsearch[]="localAuthorizationList";
  9013. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  9014. char CardList[500][160]={0};
  9015. char updateTypestr[15]={0};
  9016. char idTagstr[20]={0};
  9017. char parentIdTag[20]={0};
  9018. char expiryDate[30]={0};
  9019. char idTagstatus[16]={0};
  9020. int c = 0;
  9021. int i = 0;
  9022. char *delim1 = "}";
  9023. char * pch;
  9024. char *loc;
  9025. //char *ptr;
  9026. char comfirmstr[20];
  9027. //int n_localAuthorizations = 0;
  9028. int checkState_Faulted = FALSE;
  9029. DEBUG_INFO("handleSendLocalListRequest...\n");
  9030. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  9031. {
  9032. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9033. goto end;
  9034. }
  9035. //check Charge Point state
  9036. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9037. {
  9038. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9039. {
  9040. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9041. }
  9042. }
  9043. for (int index = 0; index < CCS_QUANTITY; index++)
  9044. {
  9045. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9046. {
  9047. checkState_Faulted = TRUE; //OCPP Status
  9048. }
  9049. }
  9050. for (int index = 0; index < GB_QUANTITY; index++)
  9051. {
  9052. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9053. {
  9054. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9055. }
  9056. }
  9057. //check Charge Point state
  9058. for (int index = 0; index < AC_QUANTITY; index++)
  9059. {
  9060. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9061. {
  9062. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9063. }
  9064. }
  9065. if(checkState_Faulted == TRUE)
  9066. {
  9067. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9068. goto end;
  9069. }
  9070. //Filter payload space
  9071. strcpy(sstrtemp, stringtrimspace(payload));
  9072. //listVersion
  9073. c = 0;
  9074. loc = strstr(sstrtemp, listsearch);
  9075. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  9076. {
  9077. sstr[c] = loc[strlen("listVersion")+2+c];
  9078. c++;
  9079. }
  9080. sstr[c] = '\0';
  9081. listVersionInt = atoi(sstr);
  9082. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  9083. //updateType
  9084. loc = strstr(sstrtemp, updateTypesearch);
  9085. c = 0;
  9086. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  9087. {
  9088. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  9089. c++;
  9090. }
  9091. sstr[c] = '\0';
  9092. strcpy(updateTypestr, sstr);
  9093. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  9094. //localAuthorizationList
  9095. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9096. loc = strstr(sstrtemp, localAuthorizationListsearch);
  9097. if(loc != NULL) // localAuthorizationList is not NULL
  9098. {
  9099. //Check UpdateType
  9100. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  9101. {
  9102. //Local list full update
  9103. printf("Local list full update.\n");
  9104. OCPP_getListVerion();
  9105. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  9106. {
  9107. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9108. goto end;
  9109. }
  9110. OCPP_cleanLocalList();
  9111. }
  9112. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  9113. {
  9114. //Local list different update
  9115. printf("Local list different update.\n");
  9116. OCPP_getListVerion();
  9117. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  9118. {
  9119. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  9120. goto end;
  9121. }
  9122. }
  9123. else
  9124. {
  9125. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9126. goto end;
  9127. }
  9128. c = 0;
  9129. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  9130. {
  9131. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  9132. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9133. c++;
  9134. }
  9135. sstr[c] = '\0';
  9136. //DEBUG_INFO("sstr=%s\n", sstr);
  9137. //parsing strings to words
  9138. i = 0;
  9139. pch = strtok(sstr,delim1);
  9140. while (pch != NULL)
  9141. {
  9142. strcpy(CardList[i], pch);
  9143. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  9144. pch = strtok (NULL, delim1);
  9145. i = i + 1;
  9146. }
  9147. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  9148. //local Authorizations List Numbers
  9149. //n_localAuthorizations = i;
  9150. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  9151. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  9152. c= 0;
  9153. while(c < i) // i is CardList Number
  9154. {
  9155. //Search "IdToken"
  9156. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9157. loc = strstr(CardList[c], "idTag");
  9158. int j = 0;
  9159. while (loc[3+strlen("idTag")+j] != '\"')
  9160. {
  9161. sstr[j] = loc[3+strlen("idTag")+j];
  9162. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9163. j++;
  9164. }
  9165. sstr[j] = '\0';
  9166. strcpy(idTagstr, sstr);
  9167. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  9168. //Search "expiryDate"
  9169. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9170. loc = strstr(CardList[c], "expiryDate");
  9171. j = 0;
  9172. if(loc != NULL)
  9173. {
  9174. while (loc[3+strlen("expiryDate")+j] != '\"')
  9175. {
  9176. sstr[j] = loc[3+strlen("expiryDate")+j];
  9177. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9178. j++;
  9179. }
  9180. sstr[j] = '\0';
  9181. strcpy(expiryDate, sstr);
  9182. }
  9183. else
  9184. {
  9185. strcpy(expiryDate, "");
  9186. }
  9187. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  9188. //Search "parentIdTag"
  9189. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9190. loc = strstr(CardList[c], "parentIdTag");
  9191. j = 0;
  9192. if(loc != NULL)
  9193. {
  9194. while (loc[3+strlen("parentIdTag")+j] != '\"')
  9195. {
  9196. sstr[j] = loc[3+strlen("parentIdTag")+j];
  9197. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9198. j++;
  9199. }
  9200. sstr[j] = '\0';
  9201. strcpy(parentIdTag, sstr);
  9202. }
  9203. else
  9204. {
  9205. strcpy(parentIdTag, "");
  9206. }
  9207. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  9208. //Search "status"
  9209. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9210. loc = strstr(CardList[c], "status");
  9211. j = 0;
  9212. while (loc[3+strlen("status")+j] != '\"')
  9213. {
  9214. sstr[j] = loc[3+strlen("status")+j];
  9215. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9216. j++;
  9217. }
  9218. sstr[j] = '\0';
  9219. strcpy(idTagstatus, sstr);
  9220. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  9221. OCPP_getIdTagFromLocalList(idTagstr);
  9222. //OCPP_getIdTagFromLocalList("test"); For Test
  9223. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  9224. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  9225. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  9226. {
  9227. //Local list full update
  9228. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  9229. // update list
  9230. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  9231. //DEBUG_INFO("Local list full update. 1\n");
  9232. //OCPP_get_TableAuthlocalAllData();
  9233. //DEBUG_INFO("Local list full update. 2\n");
  9234. }
  9235. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  9236. {
  9237. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  9238. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  9239. }
  9240. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  9241. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  9242. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  9243. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  9244. c++;
  9245. }
  9246. }
  9247. else
  9248. {
  9249. //Check UpdateType
  9250. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  9251. {
  9252. //Local list full update
  9253. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  9254. OCPP_cleanLocalList();
  9255. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9256. goto end;
  9257. }
  9258. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  9259. {
  9260. //Local list different update
  9261. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  9262. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9263. goto end;
  9264. }
  9265. }
  9266. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9267. end:
  9268. sendSendLocalListConfirmation(uuid, comfirmstr);
  9269. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  9270. return result;
  9271. }
  9272. #define MAX 200
  9273. int handleSetChargingProfileRequest(char *uuid, char *payload)
  9274. {
  9275. mtrace();
  9276. int result = FAIL;
  9277. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  9278. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  9279. char chargingProfilePurposeStr[30]={0};
  9280. char chargingProfileKindStr[16]={0};
  9281. char recurrencyKindStr[10]={0};
  9282. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  9283. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  9284. int chargingSchedulePeriodCount = 0;
  9285. char comfirmstr[20]={0};
  9286. int meet= FALSE;
  9287. FILE *fptr1;
  9288. char filename[MAX]={0};
  9289. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  9290. char rmFileCmd[50]={0};
  9291. char tempchargingProfilePurposeStr[30]={0};
  9292. char word[1600]={0};
  9293. int n_chargingProfile = 0;
  9294. json_object *SetChargingProfile;
  9295. DEBUG_INFO("handleSetChargingProfileRequest\n");
  9296. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  9297. SetChargingProfile = json_tokener_parse(payload);
  9298. if(!is_error(SetChargingProfile))
  9299. {
  9300. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  9301. {
  9302. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  9303. if(connectorIdInt == 0)
  9304. {
  9305. memset(&ShmOCPP16Data->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  9306. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  9307. }
  9308. else
  9309. {
  9310. memset(&ShmOCPP16Data->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  9311. ShmOCPP16Data->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  9312. }
  9313. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  9314. }
  9315. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  9316. {
  9317. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  9318. {
  9319. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  9320. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9321. {
  9322. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  9323. }
  9324. else
  9325. {
  9326. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  9327. }
  9328. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  9329. }
  9330. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  9331. {
  9332. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  9333. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9334. {
  9335. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  9336. }
  9337. else
  9338. {
  9339. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  9340. }
  9341. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  9342. }
  9343. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9344. {
  9345. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  9346. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9347. {
  9348. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  9349. }
  9350. else
  9351. {
  9352. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  9353. }
  9354. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  9355. }
  9356. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  9357. {
  9358. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  9359. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9360. {
  9361. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  9362. }
  9363. else
  9364. {
  9365. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  9366. }
  9367. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  9368. }
  9369. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  9370. {
  9371. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  9372. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9373. {
  9374. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  9375. }
  9376. else
  9377. {
  9378. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  9379. }
  9380. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  9381. }
  9382. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  9383. {
  9384. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  9385. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9386. {
  9387. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9388. }
  9389. else
  9390. {
  9391. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9392. }
  9393. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  9394. }
  9395. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  9396. {
  9397. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  9398. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9399. {
  9400. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  9401. }
  9402. else
  9403. {
  9404. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  9405. }
  9406. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  9407. }
  9408. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  9409. {
  9410. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  9411. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9412. {
  9413. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  9414. }
  9415. else
  9416. {
  9417. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  9418. }
  9419. //DEBUG_INFO("validToStr: %s\n", validToStr);
  9420. }
  9421. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  9422. {
  9423. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  9424. {
  9425. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  9426. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9427. {
  9428. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9429. }
  9430. else
  9431. {
  9432. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9433. }
  9434. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  9435. }
  9436. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  9437. {
  9438. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  9439. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9440. {
  9441. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9442. }
  9443. else
  9444. {
  9445. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9446. }
  9447. //DEBUG_INFO("durationInt: %d\n", durationInt);
  9448. }
  9449. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  9450. {
  9451. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  9452. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9453. {
  9454. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9455. }
  9456. else
  9457. {
  9458. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9459. }
  9460. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  9461. }
  9462. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  9463. {
  9464. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  9465. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9466. {
  9467. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9468. }
  9469. else
  9470. {
  9471. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9472. }
  9473. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  9474. }
  9475. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9476. {
  9477. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  9478. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  9479. if(chargingSchedulePeriodCount <= 10)
  9480. {
  9481. 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++)
  9482. {
  9483. 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)
  9484. {
  9485. 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"));
  9486. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9487. {
  9488. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9489. }
  9490. else
  9491. {
  9492. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9493. }
  9494. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  9495. }
  9496. 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)
  9497. {
  9498. 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"));
  9499. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9500. {
  9501. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9502. }
  9503. else
  9504. {
  9505. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9506. }
  9507. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  9508. }
  9509. 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)
  9510. {
  9511. 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"));
  9512. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9513. {
  9514. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9515. }
  9516. else
  9517. {
  9518. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9519. }
  9520. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  9521. }
  9522. }
  9523. }
  9524. }
  9525. }
  9526. }
  9527. }
  9528. json_object_put(SetChargingProfile);
  9529. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  9530. {
  9531. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9532. goto end;
  9533. }
  9534. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  9535. {
  9536. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  9537. if(connectorIdInt != 0)
  9538. {
  9539. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9540. goto end;
  9541. }
  9542. strcpy(filename, ChargePointMaxProfile_JSON );
  9543. fptr1 = fopen(filename, "r");
  9544. if (!fptr1)
  9545. {
  9546. //file not exist
  9547. DEBUG_INFO("Unable to open the input file!!\n");
  9548. fptr1 = fopen(filename, "w+");
  9549. }
  9550. else
  9551. {
  9552. //Check Charging Profile Count
  9553. while(fscanf(fptr1, "%s", word) != EOF)
  9554. {
  9555. //DEBUG_INFO("word=%s\n",word);
  9556. if(strstr(word, "chargingProfileId")!= NULL)
  9557. {
  9558. //DEBUG_INFO("test chargingProfileId \n");
  9559. n_chargingProfile = n_chargingProfile + 1;
  9560. //DEBUG_INFO("chargingProfileId Found\n");
  9561. }
  9562. }
  9563. }
  9564. fclose(fptr1);
  9565. }
  9566. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  9567. {
  9568. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  9569. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9570. {
  9571. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9572. goto end;
  9573. }
  9574. memset(filename, 0, ARRAY_SIZE(filename));
  9575. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9576. fptr1 = fopen(filename, "r");
  9577. if (!fptr1)
  9578. {
  9579. //file not exist
  9580. //DEBUG_INFO("Unable to open the input file!!\n");
  9581. fptr1 = fopen(filename, "w+");
  9582. }
  9583. else
  9584. {
  9585. //Check Charging Profile Count
  9586. while(fscanf(fptr1, "%s", word) != EOF)
  9587. {
  9588. //DEBUG_INFO("word=%s\n",word);
  9589. if(strstr(word, "chargingProfileId")!= NULL)
  9590. {
  9591. //DEBUG_INFO("test chargingProfileId \n");
  9592. n_chargingProfile = n_chargingProfile + 1;
  9593. //DEBUG_INFO("chargingProfileId Found\n");
  9594. }
  9595. }
  9596. }
  9597. fclose(fptr1);
  9598. }
  9599. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9600. {
  9601. //printf("set chargingProfile 1-4\n");
  9602. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  9603. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  9604. if(connectorIdInt == 0)
  9605. {
  9606. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9607. goto end;
  9608. }
  9609. int tempIndex = 0;
  9610. //check Transaction active
  9611. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9612. {
  9613. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9614. {
  9615. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9616. }
  9617. else
  9618. {
  9619. tempIndex = connectorIdInt -1;
  9620. }
  9621. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9622. {
  9623. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9624. {
  9625. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9626. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9627. {
  9628. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9629. {
  9630. meet = TRUE;
  9631. break;
  9632. }
  9633. }
  9634. }
  9635. }
  9636. }
  9637. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9638. {
  9639. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9640. {
  9641. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9642. }
  9643. else
  9644. {
  9645. tempIndex = connectorIdInt -1;
  9646. }
  9647. for (int index = 0; index < CCS_QUANTITY; index++)
  9648. {
  9649. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9650. {
  9651. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9652. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9653. {
  9654. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9655. {
  9656. meet = TRUE;
  9657. break;
  9658. }
  9659. }
  9660. }
  9661. }
  9662. }
  9663. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9664. {
  9665. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9666. {
  9667. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9668. }
  9669. else
  9670. {
  9671. tempIndex = connectorIdInt -1;
  9672. }
  9673. for (int index = 0; index < GB_QUANTITY; index++)
  9674. {
  9675. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9676. {
  9677. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9678. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9679. {
  9680. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9681. {
  9682. meet = TRUE;
  9683. break;
  9684. }
  9685. }
  9686. }
  9687. }
  9688. }
  9689. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9690. {
  9691. tempIndex = connectorIdInt -1;
  9692. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9693. {
  9694. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9695. {
  9696. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  9697. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9698. {
  9699. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9700. {
  9701. meet = TRUE;
  9702. break;
  9703. }
  9704. }
  9705. }
  9706. }
  9707. }
  9708. else
  9709. {
  9710. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9711. {
  9712. tempIndex = 2;
  9713. }
  9714. else
  9715. {
  9716. tempIndex = (connectorIdInt -1);
  9717. }
  9718. for (int index = 0; index < AC_QUANTITY; index++)
  9719. {
  9720. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9721. {
  9722. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9723. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9724. {
  9725. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9726. {
  9727. meet = TRUE;
  9728. break;
  9729. }
  9730. }
  9731. }
  9732. }
  9733. }
  9734. //check Transaction active
  9735. if(meet == FALSE)
  9736. {
  9737. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9738. goto end;
  9739. }
  9740. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9741. {
  9742. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9743. goto end;
  9744. }
  9745. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9746. fptr1 = fopen(filename, "r");
  9747. if (!fptr1)
  9748. {
  9749. //file not exist
  9750. DEBUG_INFO("Unable to open the input file!!\n");
  9751. fptr1 = fopen(filename, "w+");
  9752. }
  9753. else
  9754. {
  9755. //Check Charging Profile Count
  9756. while(fscanf(fptr1, "%s", word) != EOF)
  9757. {
  9758. //DEBUG_INFO("word=%s\n",word);
  9759. if(strstr(word, "chargingProfileId")!= NULL)
  9760. {
  9761. //DEBUG_INFO("test chargingProfileId \n");
  9762. n_chargingProfile = n_chargingProfile + 1;
  9763. //DEBUG_INFO("chargingProfileId Found\n");
  9764. }
  9765. }
  9766. }
  9767. fclose(fptr1);
  9768. }
  9769. // Check ChargeProfileMaxStackLevel
  9770. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  9771. {
  9772. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9773. goto end;
  9774. }
  9775. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9776. {
  9777. int i = 0;
  9778. char fnametemp[200]={0};
  9779. n_chargingProfile = 0;
  9780. //Check ChargePointMaxProfile.json exit
  9781. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9782. {
  9783. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  9784. //Check Charging Profile Count
  9785. while(fscanf(fptr1, "%s", word) != EOF)
  9786. {
  9787. //DEBUG_INFO("word=%s\n",word);
  9788. if(strstr(word, "chargingProfileId")!= NULL)
  9789. {
  9790. //DEBUG_INFO("test chargingProfileId \n");
  9791. n_chargingProfile = n_chargingProfile + 1;
  9792. i = i + 1;
  9793. //DEBUG_INFO("chargingProfileId Found\n");
  9794. }
  9795. memset(word, 0, ARRAY_SIZE(word));
  9796. }
  9797. fclose(fptr1);
  9798. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  9799. }
  9800. //Check TxDefaultProfile_0.json exit
  9801. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9802. {
  9803. i = 0;
  9804. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  9805. //Check Charging Profile Count
  9806. while(fscanf(fptr1, "%s", word) != EOF)
  9807. {
  9808. //DEBUG_INFO("word=%s\n",word);
  9809. if(strstr(word, "chargingProfileId")!= NULL)
  9810. {
  9811. //DEBUG_INFO("test chargingProfileId \n");
  9812. n_chargingProfile = n_chargingProfile + 1;
  9813. i = i + 1;
  9814. //DEBUG_INFO("chargingProfileId Found\n");
  9815. }
  9816. memset(word, 0, ARRAY_SIZE(word));
  9817. }
  9818. fclose(fptr1);
  9819. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  9820. }
  9821. //Check TxDefaultProfile_%d.json
  9822. for(int j=1; j <= gunTotalNumber; j++)
  9823. {
  9824. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9825. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9826. if((access(fnametemp,F_OK))!=-1)
  9827. {
  9828. i = 0;
  9829. fptr1 = fopen(fnametemp, "r");
  9830. //Check Charging Profile Count
  9831. while(fscanf(fptr1, "%s", word) != EOF)
  9832. {
  9833. //DEBUG_INFO("word=%s\n",word);
  9834. if(strstr(word, "chargingProfileId")!= NULL)
  9835. {
  9836. //DEBUG_INFO("test chargingProfileId \n");
  9837. n_chargingProfile = n_chargingProfile + 1;
  9838. i = i + 1;
  9839. //DEBUG_INFO("chargingProfileId Found\n");
  9840. }
  9841. memset(word, 0, ARRAY_SIZE(word));
  9842. }
  9843. fclose(fptr1);
  9844. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9845. }
  9846. }
  9847. //Check TxProfile_%d.json
  9848. for(int j=1; j <= gunTotalNumber; j++)
  9849. {
  9850. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9851. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9852. if((access(fnametemp,F_OK))!=-1)
  9853. {
  9854. i = 0;
  9855. fptr1 = fopen(fnametemp, "r");
  9856. //Check Charging Profile Count
  9857. while(fscanf(fptr1, "%s", word) != EOF)
  9858. {
  9859. //DEBUG_INFO("word=%s\n",word);
  9860. if(strstr(word, "chargingProfileId")!= NULL)
  9861. {
  9862. //DEBUG_INFO("test chargingProfileId \n");
  9863. n_chargingProfile = n_chargingProfile + 1;
  9864. i = i + 1;
  9865. //DEBUG_INFO("chargingProfileId Found\n");
  9866. }
  9867. memset(word, 0, ARRAY_SIZE(word));
  9868. }
  9869. fclose(fptr1);
  9870. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9871. }
  9872. }
  9873. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  9874. {
  9875. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9876. goto end;
  9877. }
  9878. }
  9879. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9880. //**********************************Write to File********************************************************/
  9881. FILE *infile;
  9882. FILE *outfile;
  9883. infile = fopen (filename, "r");
  9884. outfile = fopen (tempfile, "w");
  9885. int d =0;
  9886. d = fgetc(infile);
  9887. rewind(infile);
  9888. if(d == EOF)
  9889. {
  9890. // Profile is empty
  9891. fprintf(outfile,"%s\n",payload);
  9892. fclose(infile);
  9893. fclose(outfile);
  9894. sprintf(rmFileCmd,"rm -f %s",filename);
  9895. system(rmFileCmd);
  9896. rename(tempfile, filename);
  9897. }
  9898. else
  9899. {
  9900. // Profile is not empty
  9901. char buf[2048]={0};
  9902. int ChargingProfileAdded = FALSE;
  9903. while (fgets(buf, sizeof(buf), infile) != NULL)
  9904. {
  9905. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9906. json_object *tmpChargingProfile;
  9907. tmpChargingProfile = json_tokener_parse(buf);
  9908. if(!is_error(SetChargingProfile))
  9909. {
  9910. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  9911. {
  9912. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  9913. }
  9914. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  9915. {
  9916. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  9917. {
  9918. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  9919. }
  9920. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  9921. {
  9922. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  9923. }
  9924. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9925. {
  9926. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  9927. }
  9928. }
  9929. }
  9930. json_object_put(tmpChargingProfile);
  9931. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  9932. {
  9933. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9934. {
  9935. //DEBUG_INFO("update set chargingProfile to file -0\n");
  9936. if(ChargingProfileAdded == FALSE)
  9937. {
  9938. fprintf(outfile,"%s\n",payload);
  9939. ChargingProfileAdded = TRUE;
  9940. }
  9941. }
  9942. else
  9943. {
  9944. if(tempstackLevelInt < stackLevelInt)
  9945. {
  9946. if(ChargingProfileAdded == FALSE)
  9947. {
  9948. fprintf(outfile,"%s\n",buf);
  9949. fprintf(outfile,"%s\n",payload);
  9950. ChargingProfileAdded = TRUE;
  9951. }
  9952. else
  9953. {
  9954. fprintf(outfile,"%s\n",buf);
  9955. }
  9956. }
  9957. else
  9958. {
  9959. if(ChargingProfileAdded == FALSE)
  9960. {
  9961. fprintf(outfile,"%s\n",buf);
  9962. fprintf(outfile,"%s\n",payload);
  9963. ChargingProfileAdded = TRUE;
  9964. }
  9965. else
  9966. {
  9967. fprintf(outfile,"%s\n",buf);
  9968. }
  9969. }
  9970. }
  9971. }
  9972. else
  9973. {
  9974. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9975. {
  9976. if(ChargingProfileAdded == FALSE)
  9977. {
  9978. fprintf(outfile,"%s\n",buf);
  9979. fprintf(outfile,"%s\n",payload);
  9980. ChargingProfileAdded = TRUE;
  9981. }
  9982. else
  9983. {
  9984. fprintf(outfile,"%s\n",buf);
  9985. }
  9986. }
  9987. else if(tempstackLevelInt < stackLevelInt)
  9988. {
  9989. if(ChargingProfileAdded == FALSE)
  9990. {
  9991. fprintf(outfile,"%s\n",buf);
  9992. fprintf(outfile,"%s\n",payload);
  9993. ChargingProfileAdded = TRUE;
  9994. }
  9995. else
  9996. {
  9997. fprintf(outfile,"%s\n",buf);
  9998. }
  9999. }
  10000. else
  10001. {
  10002. if(ChargingProfileAdded == FALSE)
  10003. {
  10004. fprintf(outfile,"%s\n",buf);
  10005. fprintf(outfile,"%s\n",payload);
  10006. ChargingProfileAdded = TRUE;
  10007. }
  10008. else
  10009. {
  10010. fprintf(outfile,"%s\n",buf);
  10011. }
  10012. }
  10013. }
  10014. } // end of while loop
  10015. fclose(infile);
  10016. fclose(outfile);
  10017. sprintf(rmFileCmd,"rm -f %s",filename);
  10018. system(rmFileCmd);
  10019. rename(tempfile, filename);
  10020. }
  10021. sleep(1);
  10022. result = TRUE;
  10023. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  10024. end:
  10025. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  10026. {
  10027. if(connectorIdInt == 0)
  10028. {
  10029. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  10030. {
  10031. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  10032. }
  10033. }
  10034. else
  10035. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  10036. }
  10037. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  10038. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10039. return result;
  10040. }
  10041. int handleTriggerMessageRequest(char *uuid, char *payload)
  10042. {
  10043. mtrace();
  10044. int result = FAIL;
  10045. int connectorIdIsNULL = FALSE;
  10046. int connectorIdInt =0;
  10047. char sstr[40]={0},sstrtemp[100]={ 0 };
  10048. char requestedMessagestr[40]={0};
  10049. char comfirmstr[20]={0};
  10050. int c = 0;
  10051. char *loc;
  10052. DEBUG_INFO("handleTriggerMessageRequest\n");
  10053. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  10054. strcpy(sstrtemp, stringtrimspace(payload));
  10055. c = 0;
  10056. loc = strstr(sstrtemp, "requestedMessage");
  10057. while (loc[3+strlen("requestedMessage")+c] != '\"')
  10058. {
  10059. sstr[c] = loc[3+strlen("requestedMessage")+c];
  10060. c++;
  10061. }
  10062. sstr[c] = '\0';
  10063. strcpy(requestedMessagestr, sstr);
  10064. c = 0;
  10065. loc = strstr(sstrtemp, "connectorId");
  10066. if(loc == NULL)
  10067. {
  10068. connectorIdIsNULL = TRUE;
  10069. }
  10070. else
  10071. {
  10072. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10073. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  10074. {
  10075. sstr[c] = loc[strlen("connectorId")+2+c];
  10076. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10077. c++;
  10078. }
  10079. sstr[c] = '\0';
  10080. connectorIdInt = atoi(sstr);
  10081. }
  10082. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  10083. {
  10084. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  10085. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  10086. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  10087. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  10088. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  10089. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  10090. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  10091. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  10092. {
  10093. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  10094. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10095. return TRUE;
  10096. }
  10097. else
  10098. {
  10099. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  10100. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10101. }
  10102. }
  10103. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  10104. {
  10105. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  10106. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10107. return TRUE;
  10108. }
  10109. //==========================
  10110. // Trigger message
  10111. //==========================
  10112. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  10113. {
  10114. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  10115. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  10116. {
  10117. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  10118. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  10119. }
  10120. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10121. }
  10122. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  10123. {
  10124. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  10125. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10126. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10127. }
  10128. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  10129. {
  10130. //sendBootNotificationRequest();
  10131. server_sign = FALSE;
  10132. }
  10133. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  10134. {
  10135. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  10136. }
  10137. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  10138. {
  10139. if(connectorIdIsNULL == FALSE)
  10140. {
  10141. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  10142. {
  10143. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  10144. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  10145. }
  10146. }
  10147. else
  10148. {
  10149. for(int idx=0;idx< gunTotalNumber;idx++)
  10150. {
  10151. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  10152. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  10153. }
  10154. }
  10155. }
  10156. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  10157. {
  10158. if(connectorIdIsNULL == FALSE)
  10159. {
  10160. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  10161. {
  10162. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  10163. cpinitateMsg.bits[connectorIdInt -1].StatusNotificationReq = 1;
  10164. }
  10165. }
  10166. else
  10167. {
  10168. for(int idx=0;idx< gunTotalNumber;idx++)
  10169. {
  10170. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  10171. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  10172. }
  10173. }
  10174. }
  10175. return result;
  10176. }
  10177. int handleUnlockConnectorRequest(char *uuid, char *payload)
  10178. {
  10179. mtrace();
  10180. int result = FAIL;
  10181. int connectorIdInt =0;
  10182. char comfirmstr[20]={0};
  10183. int tempIndex = 0;
  10184. json_object *UnlockConnector;
  10185. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  10186. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  10187. UnlockConnector = json_tokener_parse(payload);
  10188. if(!is_error(UnlockConnector))
  10189. {
  10190. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  10191. {
  10192. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  10193. }
  10194. }
  10195. json_object_put(UnlockConnector);
  10196. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  10197. if(gunTotalNumber == 0)
  10198. {
  10199. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10200. goto end;
  10201. }
  10202. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  10203. {
  10204. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10205. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10206. goto end;
  10207. }
  10208. else
  10209. {
  10210. //check Transaction active
  10211. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  10212. {
  10213. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10214. {
  10215. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10216. }
  10217. else
  10218. {
  10219. tempIndex = connectorIdInt -1;
  10220. }
  10221. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10222. {
  10223. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10224. {
  10225. //stop Transaction
  10226. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10227. }
  10228. }
  10229. }
  10230. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  10231. {
  10232. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10233. {
  10234. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10235. }
  10236. else
  10237. {
  10238. tempIndex = connectorIdInt -1;
  10239. }
  10240. for (int index = 0; index < CCS_QUANTITY; index++)
  10241. {
  10242. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10243. {
  10244. //stop Transaction
  10245. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10246. }
  10247. }
  10248. }
  10249. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  10250. {
  10251. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10252. {
  10253. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10254. }
  10255. else
  10256. {
  10257. tempIndex = connectorIdInt -1;
  10258. }
  10259. for (int index = 0; index < GB_QUANTITY; index++)
  10260. {
  10261. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  10262. {
  10263. //stop Transaction
  10264. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10265. }
  10266. }
  10267. }
  10268. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  10269. {
  10270. tempIndex = connectorIdInt -1;
  10271. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10272. {
  10273. 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)))
  10274. {
  10275. //stop Transaction
  10276. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10277. }
  10278. }
  10279. }
  10280. else
  10281. {
  10282. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10283. {
  10284. tempIndex = 2;
  10285. }
  10286. else
  10287. {
  10288. tempIndex = connectorIdInt-1;
  10289. }
  10290. for (int index = 0; index < AC_QUANTITY; index++)
  10291. {
  10292. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10293. {
  10294. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10295. }
  10296. }
  10297. }
  10298. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  10299. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  10300. result = TRUE;
  10301. return result;
  10302. }
  10303. end:
  10304. //json_object_put(obj); --- remove temporally
  10305. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  10306. return result;
  10307. }
  10308. static char UpdateFirmwarepayloadData[300]={0};
  10309. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  10310. {
  10311. mtrace();
  10312. int result = FAIL;
  10313. pthread_t t;
  10314. sendUpdateFirmwareConfirmation(uuid);
  10315. memset(UpdateFirmwarepayloadData, 0, 300);
  10316. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  10317. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  10318. ////pthread_join(t, NULL); //
  10319. //pthread_detach(t);
  10320. //sendUpdateFirmwareConfirmation(uuid);
  10321. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  10322. return result;
  10323. }
  10324. void *UpdateFirmwareProcess(void *data)
  10325. {
  10326. pthread_detach(pthread_self());
  10327. mtrace();
  10328. int retriesInt =0, retryIntervalInt=0;
  10329. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  10330. int port=0;
  10331. char locationstr[512]={0}, retrieveDatestr[36]={0};
  10332. int isSuccess = 0;
  10333. char ftpbuf[512];
  10334. char temp[100];
  10335. char * pch;
  10336. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  10337. json_object *UpdateFirmware;
  10338. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  10339. if(!is_error(UpdateFirmware))
  10340. {
  10341. // Required data
  10342. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  10343. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  10344. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  10345. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  10346. // Optional data
  10347. if(json_object_object_get(UpdateFirmware, "retries"))
  10348. {
  10349. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  10350. }
  10351. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  10352. {
  10353. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  10354. }
  10355. }
  10356. json_object_put(UpdateFirmware);
  10357. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10358. memset(path, 0, ARRAY_SIZE(path));
  10359. // Wait retrieveData
  10360. if(strlen(retrieveDatestr) > 10)
  10361. {
  10362. do
  10363. {
  10364. sleep(1);
  10365. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  10366. }
  10367. // Ready to download
  10368. system("rm -f /mnt/*");
  10369. if(strncmp(locationstr,"http", 4) == 0)
  10370. {
  10371. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10372. sprintf(ftppath,"/%s", path);
  10373. DEBUG_INFO("locationstr: %s\n", locationstr);
  10374. DEBUG_INFO("protocol: %s\n",protocol);
  10375. DEBUG_INFO("host: %s\n",host);
  10376. DEBUG_INFO("path: %s\n",path);
  10377. DEBUG_INFO("ftppath: %s\n",ftppath);
  10378. int ftppathlen=strlen(ftppath);
  10379. int i=1;
  10380. char filenametemp[50];
  10381. while(i < ftppathlen)
  10382. {
  10383. int len=ftppathlen-i;
  10384. if(ftppath[len]== 47) // '/' ascll code: 47
  10385. {
  10386. DEBUG_INFO("compare '/' all right\n");
  10387. break;
  10388. }
  10389. i=i+1;
  10390. }
  10391. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10392. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10393. filenametemp[i+1] = 0;
  10394. do
  10395. {
  10396. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  10397. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10398. sleep(1);
  10399. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  10400. if(!isSuccess)
  10401. {
  10402. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10403. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10404. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  10405. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10406. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10407. }
  10408. else
  10409. {
  10410. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10411. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10412. }
  10413. retriesInt--;
  10414. }while((isSuccess == 0)&&(retriesInt >= 0));
  10415. }
  10416. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  10417. {
  10418. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  10419. memset(temp, 0, ARRAY_SIZE(temp));
  10420. //DEBUG_INFO("locationstr=%s\n",locationstr);
  10421. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  10422. int ftppathlen=strlen(ftpbuf);
  10423. int i=1;
  10424. char filenametemp[50];
  10425. while(i < ftppathlen)
  10426. {
  10427. int len=ftppathlen-i;
  10428. if(ftpbuf[len]== 47) // '/' ascll code: 47
  10429. {
  10430. DEBUG_INFO(" compare '/' all right\n");
  10431. break;
  10432. }
  10433. i=i+1;
  10434. }
  10435. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10436. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  10437. filenametemp[i+1] = 0;
  10438. strncpy(temp, ftpbuf, ftppathlen-i+1);
  10439. pch=strchr(temp,'@');
  10440. if(pch==NULL)
  10441. {
  10442. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10443. protocol, host, &port, path);
  10444. strcpy(user,"anonymous");
  10445. strcpy(password,"");
  10446. }
  10447. else
  10448. {
  10449. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10450. protocol, user, password, host, &port, path);
  10451. }
  10452. sscanf(host,"%[^/]%s",host1, path1);
  10453. sprintf(ftppath,"%s", path1);
  10454. //DEBUG_INFO("protocol =%s\n",protocol);
  10455. //DEBUG_INFO("user =%s\n",user);
  10456. //DEBUG_INFO("password =%s\n",password);
  10457. //DEBUG_INFO("host1 =%s\n",host1);
  10458. //DEBUG_INFO("port =%d\n",port);
  10459. //DEBUG_INFO("path1 =%s\n",path1);
  10460. //DEBUG_INFO("ftppath=%s\n",ftppath);
  10461. //ftpFile(host, user, password, port, ftppath, fname);
  10462. //download firmware pthred
  10463. if(port == 0)
  10464. {
  10465. port = 21;
  10466. }
  10467. do
  10468. {
  10469. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  10470. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10471. sleep(1);
  10472. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  10473. if(!isSuccess)
  10474. {
  10475. //BulldogUtil.sleepMs(interval*1000);
  10476. DEBUG_INFO("Update firmware request and download file fail.\n");
  10477. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10478. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10479. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  10480. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10481. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10482. }
  10483. else
  10484. {
  10485. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10486. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10487. }
  10488. retriesInt--;
  10489. }while((!isSuccess)&&(retriesInt >= 0));
  10490. }
  10491. else
  10492. {
  10493. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10494. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10495. sleep(1);
  10496. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10497. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10498. }
  10499. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  10500. pthread_exit(NULL);
  10501. }
  10502. int handleCertificateSignedRequest(char *uuid, char *payload)
  10503. {
  10504. mtrace();
  10505. int result = PASS;
  10506. json_object *CertificateSigned;
  10507. DEBUG_INFO("handleCertificateSignedRequest...\n");
  10508. CertificateSigned = json_tokener_parse(payload);
  10509. if(!is_error(CertificateSigned))
  10510. {
  10511. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  10512. }
  10513. json_object_put(CertificateSigned);
  10514. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  10515. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  10516. fclose(fp);
  10517. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10518. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  10519. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  10520. sendCertificateSignedConfirmation(uuid);
  10521. return result;
  10522. }
  10523. int handleDeleteCertificateRequest(char *uuid, char *payload)
  10524. {
  10525. mtrace();
  10526. int result = PASS;
  10527. json_object *DeleteCertificate;
  10528. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  10529. DeleteCertificate = json_tokener_parse(payload);
  10530. if(!is_error(DeleteCertificate))
  10531. {
  10532. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  10533. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  10534. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  10535. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  10536. }
  10537. json_object_put(DeleteCertificate);
  10538. /*
  10539. * TODO: Delete certificateSigned process
  10540. */
  10541. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  10542. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  10543. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  10544. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  10545. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  10546. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  10547. sendDeleteCertificateConfirmation(uuid);
  10548. return result;
  10549. }
  10550. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  10551. {
  10552. mtrace();
  10553. int result = PASS;
  10554. json_object *ExtendedTriggerMessage;
  10555. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  10556. ExtendedTriggerMessage = json_tokener_parse(payload);
  10557. if(!is_error(ExtendedTriggerMessage))
  10558. {
  10559. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  10560. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  10561. {
  10562. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  10563. }
  10564. else
  10565. {
  10566. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  10567. }
  10568. }
  10569. json_object_put(ExtendedTriggerMessage);
  10570. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  10571. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  10572. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  10573. {
  10574. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  10575. }
  10576. else
  10577. {
  10578. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  10579. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  10580. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  10581. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  10582. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  10583. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  10584. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  10585. {
  10586. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  10587. }
  10588. else
  10589. {
  10590. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  10591. }
  10592. }
  10593. sendExtendedTriggerMessageConfirmation(uuid);
  10594. //==========================
  10595. // Trigger message
  10596. //==========================
  10597. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  10598. {
  10599. //sendBootNotificationRequest();
  10600. server_sign = FALSE;
  10601. }
  10602. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  10603. {
  10604. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  10605. }
  10606. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  10607. {
  10608. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  10609. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  10610. {
  10611. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  10612. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  10613. }
  10614. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10615. }
  10616. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  10617. {
  10618. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  10619. }
  10620. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  10621. {
  10622. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  10623. {
  10624. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  10625. }
  10626. else
  10627. {
  10628. for(int idx=0;idx< gunTotalNumber;idx++)
  10629. {
  10630. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  10631. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  10632. }
  10633. }
  10634. }
  10635. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  10636. {
  10637. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  10638. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  10639. {
  10640. system("openssl req -newkey rsa:2048 -out /Storage/OCPP/certCP.csr -nodes -keyout /Storage/OCPP/certCP.key -subj \"/C=TW/ST=Taiwan/L=Taoyuan/O=Phihong Technology/OU=IT/CN=phihong.com\" &");
  10641. }
  10642. }
  10643. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  10644. {
  10645. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  10646. {
  10647. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  10648. }
  10649. else
  10650. {
  10651. for(int idx=0;idx< gunTotalNumber;idx++)
  10652. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  10653. }
  10654. }
  10655. return result;
  10656. }
  10657. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  10658. {
  10659. mtrace();
  10660. int result = PASS;
  10661. json_object *GetInstalledCertificateIds;
  10662. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  10663. GetInstalledCertificateIds = json_tokener_parse(payload);
  10664. if(!is_error(GetInstalledCertificateIds))
  10665. {
  10666. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  10667. }
  10668. json_object_put(GetInstalledCertificateIds);
  10669. /*
  10670. * TODO: Return installed certificate process
  10671. */
  10672. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  10673. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  10674. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  10675. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  10676. sendGetInstalledCertificateIdsConfirmation(uuid);
  10677. return result;
  10678. }
  10679. int handleGetLogRequest(char *uuid, char *payload)
  10680. {
  10681. mtrace();
  10682. int result = PASS;
  10683. json_object *GetLog;
  10684. DEBUG_INFO("handleGetLogRequest...\n");
  10685. GetLog = json_tokener_parse(payload);
  10686. if(!is_error(GetLog))
  10687. {
  10688. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  10689. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  10690. if(json_object_object_get(GetLog, "retries") != NULL)
  10691. {
  10692. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  10693. }
  10694. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  10695. {
  10696. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  10697. }
  10698. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  10699. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  10700. {
  10701. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  10702. }
  10703. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  10704. {
  10705. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  10706. }
  10707. }
  10708. json_object_put(GetLog);
  10709. /*
  10710. * TODO: Upload log process
  10711. */
  10712. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  10713. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  10714. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  10715. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  10716. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  10717. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  10718. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  10719. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  10720. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  10721. sendGetLogConfirmation(uuid);
  10722. return result;
  10723. }
  10724. int handleInstallCertificateRequest(char *uuid, char *payload)
  10725. {
  10726. mtrace();
  10727. int result = PASS;
  10728. json_object *InstallCertificate;
  10729. DEBUG_INFO("handleInstallCertificateRequest...\n");
  10730. InstallCertificate = json_tokener_parse(payload);
  10731. if(!is_error(InstallCertificate))
  10732. {
  10733. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  10734. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  10735. /*
  10736. * TODO: Install certificate process
  10737. */
  10738. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  10739. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  10740. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  10741. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  10742. sendInstallCertificateConfirmation(uuid);
  10743. }
  10744. json_object_put(InstallCertificate);
  10745. return result;
  10746. }
  10747. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  10748. {
  10749. mtrace();
  10750. int result = PASS;
  10751. json_object *SignedUpdateFirmware;
  10752. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  10753. SignedUpdateFirmware = json_tokener_parse(payload);
  10754. if(!is_error(SignedUpdateFirmware))
  10755. {
  10756. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  10757. {
  10758. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  10759. }
  10760. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  10761. {
  10762. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  10763. }
  10764. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  10765. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  10766. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  10767. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  10768. {
  10769. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  10770. }
  10771. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  10772. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  10773. }
  10774. json_object_put(SignedUpdateFirmware);
  10775. /*
  10776. * TODO: Upgrade firmware process
  10777. */
  10778. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  10779. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  10780. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  10781. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  10782. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  10783. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  10784. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  10785. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  10786. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  10787. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  10788. sendInstallCertificateConfirmation(uuid);
  10789. return result;
  10790. }
  10791. int handleUnknownRequest(char *uuid, char *payload)
  10792. {
  10793. mtrace();
  10794. int result = PASS;
  10795. DEBUG_INFO("handleUnknownRequest...\n");
  10796. sendUnknownConfirmation(uuid);
  10797. result = PASS;
  10798. return result;
  10799. }
  10800. //==========================================
  10801. // Handle server response routine
  10802. //==========================================
  10803. void handleAuthorizeResponse(char *payload, int gun_index)
  10804. {
  10805. mtrace();
  10806. char expiryDatestr[30]={0};
  10807. char parentIdTagstr[20]={0};
  10808. char statusstr[20]={0};
  10809. int expiryDateISNULL=FALSE;
  10810. int parentIdTagISNULL=FALSE;
  10811. DEBUG_INFO("handleAuthorizeResponse...\n");
  10812. json_object *Authorize;
  10813. Authorize = json_tokener_parse(payload);
  10814. if(!is_error(Authorize))
  10815. {
  10816. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  10817. {
  10818. // Required data
  10819. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  10820. // Optional data
  10821. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  10822. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  10823. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  10824. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  10825. }
  10826. }
  10827. json_object_put(Authorize);
  10828. if(expiryDateISNULL == FALSE)
  10829. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  10830. if(parentIdTagISNULL == FALSE)
  10831. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  10832. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  10833. //Update idTag information to authorization cache if supproted
  10834. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  10835. {
  10836. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  10837. }
  10838. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  10839. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  10840. authorizeRetryTimes = 0;
  10841. }
  10842. void handleBootNotificationResponse(char *payload, int gun_index)
  10843. {
  10844. mtrace();
  10845. char statusStr[12]={0};
  10846. char currentTimeStr[30]={0};
  10847. int intervalInt = 0;
  10848. DEBUG_INFO("handleBootNotificationResponse...\n");
  10849. json_object *BootNotification;
  10850. BootNotification = json_tokener_parse(payload);
  10851. if(!is_error(BootNotification))
  10852. {
  10853. // Required data
  10854. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  10855. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  10856. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  10857. }
  10858. json_object_put(BootNotification);
  10859. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10860. BootNotificationInterval = intervalInt;
  10861. HeartBeatWaitTime = intervalInt;
  10862. //write back to ShmOCPP16Data->BootNotification
  10863. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  10864. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10865. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  10866. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  10867. {
  10868. server_sign = TRUE;
  10869. server_pending =FALSE;
  10870. }
  10871. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  10872. {
  10873. server_pending = TRUE;
  10874. }
  10875. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  10876. srand(time(NULL));
  10877. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  10878. SetOcppConnStatus(TRUE);
  10879. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  10880. }
  10881. void handleDataTransferResponse(char *payload, int gun_index)
  10882. {
  10883. char sstr[160]={0};//sstr[200]={ 0 };
  10884. int c = 0;
  10885. char *loc;
  10886. DEBUG_INFO("handleDataTransferResponse ...\n");
  10887. loc = strstr(payload, "status");
  10888. printf("loc=%s\n",loc);
  10889. c = 0;
  10890. while (loc[3+strlen("status")+c] != '\"')
  10891. {
  10892. sstr[c] = loc[3+strlen("status")+c];
  10893. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10894. c++;
  10895. }
  10896. sstr[c] = '\0';
  10897. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  10898. }
  10899. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  10900. {
  10901. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  10902. //struct json_object *obj;
  10903. // obj = json_tokener_parse(payload);
  10904. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  10905. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  10906. //No fields are defined.
  10907. }
  10908. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  10909. {
  10910. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  10911. //struct json_object *obj;
  10912. // obj = json_tokener_parse(payload);
  10913. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  10914. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  10915. //No fields are defined.
  10916. }
  10917. void handleHeartbeatResponse(char *payload, int gun_index)
  10918. {
  10919. mtrace();
  10920. DEBUG_INFO("handleHeartbeatResponse...\n");
  10921. json_object *Heartbeat;
  10922. Heartbeat = json_tokener_parse(payload);
  10923. if(!is_error(Heartbeat))
  10924. {
  10925. // Required data
  10926. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  10927. }
  10928. json_object_put(Heartbeat);
  10929. if(FirstHeartBeat == 0)
  10930. {
  10931. FirstHeartBeat = 1;
  10932. DEBUG_INFO("FirstHeartBeat \n");
  10933. }
  10934. HeartBeatWithNOResponse = 0;
  10935. clientTime.Heartbeat=time((time_t*)NULL);
  10936. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  10937. }
  10938. void handleMeterValuesResponse(char *payload, int gun_index)
  10939. {
  10940. mtrace();
  10941. DEBUG_INFO("handleMeterValuesResponse...\n");
  10942. }
  10943. void handleStartTransactionResponse(char *payload, int gun_index)
  10944. {
  10945. mtrace();
  10946. //int transactionIdInt = 0;
  10947. FILE *outfile;
  10948. char data[100]={0};
  10949. DEBUG_INFO("handleStartTransactionResponse...\n");
  10950. json_object *StartTransaction;
  10951. StartTransaction = json_tokener_parse(payload);
  10952. if(!is_error(StartTransaction))
  10953. {
  10954. // Required data
  10955. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  10956. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  10957. // Optional data
  10958. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  10959. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  10960. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  10961. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  10962. }
  10963. json_object_put(StartTransaction);
  10964. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  10965. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  10966. //-----------Start : write to the Queue TransactionId file -----------------//
  10967. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  10968. {}
  10969. else
  10970. {
  10971. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  10972. if(log == NULL)
  10973. {
  10974. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  10975. return ;
  10976. }
  10977. else
  10978. {
  10979. fclose(log);
  10980. }
  10981. }
  10982. // open file for writing
  10983. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  10984. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  10985. {
  10986. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  10987. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  10988. fputs(data, outfile);
  10989. fclose (outfile);
  10990. }
  10991. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10992. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10993. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  10994. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  10995. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10996. }
  10997. void handleStatusNotificationResponse(char *payload, int gun_index)
  10998. {
  10999. mtrace();
  11000. DEBUG_INFO("handleStatusNotificationResponse...\n");
  11001. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  11002. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  11003. }
  11004. void handleStopTransactionnResponse(char *payload, int gun_index)
  11005. {
  11006. mtrace();
  11007. DEBUG_INFO("handleStopTransactionnResponse...\n");
  11008. json_object *StopTransaction;
  11009. StopTransaction = json_tokener_parse(payload);
  11010. if(!is_error(StopTransaction))
  11011. {
  11012. // Optional data
  11013. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  11014. {
  11015. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  11016. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  11017. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  11018. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11019. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  11020. }
  11021. }
  11022. json_object_put(StopTransaction);
  11023. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  11024. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  11025. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11026. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11027. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  11028. }
  11029. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  11030. {
  11031. mtrace();
  11032. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  11033. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  11034. }
  11035. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  11036. {
  11037. mtrace();
  11038. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  11039. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  11040. }
  11041. void handleSignCertificateResponse(char *payload, int gun_index)
  11042. {
  11043. mtrace();
  11044. DEBUG_INFO("handleSignCertificateResponse...\n");
  11045. json_object *SignCertificate;
  11046. SignCertificate = json_tokener_parse(payload);
  11047. if(!is_error(SignCertificate))
  11048. {
  11049. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  11050. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  11051. }
  11052. json_object_put(SignCertificate);
  11053. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  11054. }
  11055. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11056. {
  11057. mtrace();
  11058. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  11059. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  11060. }
  11061. //==========================================
  11062. // Handle Error routine
  11063. //==========================================
  11064. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  11065. {
  11066. mtrace();
  11067. #ifdef SystemLogMessage
  11068. DEBUG_INFO("errorCode: %s\n", errorCode);
  11069. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  11070. DEBUG_INFO("errorDetails: %s\n", payload);
  11071. #endif
  11072. }
  11073. //===============================================
  11074. // Common routine
  11075. //===============================================
  11076. int initialConfigurationTable(void)
  11077. {
  11078. //clock_t start_t, end_t, total_t;
  11079. FILE *fp;
  11080. FILE *outfile;
  11081. char str[512]={0};
  11082. char sstr[256]={0};
  11083. int c = 0;
  11084. char *loc;
  11085. int confVersion = 2;
  11086. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  11087. //start_t = clock();
  11088. //printf("Starting of the program, start_t = %ld\n", start_t);
  11089. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  11090. // Check configuration file size is correct
  11091. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  11092. {
  11093. struct stat st;
  11094. stat("/Storage/OCPP/OCPPConfiguration", &st);
  11095. if(st.st_size < 3100)
  11096. {
  11097. system("rm -f /Storage/OCPP/OCPPConfiguration");
  11098. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  11099. }
  11100. }
  11101. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  11102. {
  11103. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  11104. if(outfile == NULL)
  11105. {
  11106. DEBUG_INFO("Error opening file\n");
  11107. return FALSE;
  11108. }
  11109. /*Core Profile*/
  11110. //AllowOfflineTxForUnknownId
  11111. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11113. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  11114. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11115. //AuthorizationCacheEnabled
  11116. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11117. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11118. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11119. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11120. //AuthorizeRemoteTxRequests
  11121. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11122. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11123. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  11124. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11125. //BlinkRepeat
  11126. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11127. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11128. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11129. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11130. //ClockAlignedDataInterval
  11131. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11132. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11134. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11135. //ConnectionTimeOut
  11136. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11137. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11138. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11139. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11140. //GetConfigurationMaxKeys
  11141. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11142. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11143. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  11144. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11145. // HeartbeatInterval
  11146. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11148. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  11149. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11150. // LightIntensity
  11151. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11152. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11153. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11154. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11155. // LocalAuthorizeOffline
  11156. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  11157. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  11158. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  11159. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11160. // LocalPreAuthorize
  11161. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  11162. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  11163. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  11164. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  11165. // MaxEnergyOnInvalidId
  11166. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  11167. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  11168. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  11169. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  11170. // MeterValuesAlignedData
  11171. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  11172. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  11173. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11174. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11175. else
  11176. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11177. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  11178. // MeterValuesAlignedDataMaxLength
  11179. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  11180. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  11181. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11182. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  11183. else
  11184. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "9" );
  11185. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  11186. // MeterValuesSampledData
  11187. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  11188. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  11189. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11190. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11191. else
  11192. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11193. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  11194. // MeterValuesSampledDataMaxLength
  11195. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  11196. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  11197. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11198. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  11199. else
  11200. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "9" );
  11201. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  11202. // MeterValueSampleInterval
  11203. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  11204. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  11205. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  11206. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  11207. // MinimumStatusDuration
  11208. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  11209. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  11210. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  11211. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  11212. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  11213. // NumberOfConnectors
  11214. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  11215. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  11216. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11217. {
  11218. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  11219. }
  11220. else
  11221. {
  11222. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  11223. }
  11224. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  11225. // ResetRetries
  11226. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  11227. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  11228. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  11229. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  11230. // ConnectorPhaseRotation
  11231. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  11232. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  11233. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  11234. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  11235. // ConnectorPhaseRotationMaxLength
  11236. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  11237. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  11238. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  11239. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  11240. // StopTransactionOnEVSideDisconnect
  11241. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  11242. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  11243. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  11244. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  11245. // StopTransactionOnInvalidId
  11246. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  11247. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  11248. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  11249. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  11250. // StopTxnAlignedData
  11251. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  11252. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  11253. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  11254. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  11255. // StopTxnAlignedDataMaxLength
  11256. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  11257. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  11258. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  11259. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  11260. // StopTxnSampledData
  11261. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  11262. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  11263. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11264. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11265. else
  11266. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11267. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  11268. // StopTxnSampledDataMaxLength
  11269. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  11270. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  11271. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11272. {
  11273. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  11274. }
  11275. else
  11276. {
  11277. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  11278. }
  11279. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  11280. // SupportedFeatureProfiles
  11281. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  11282. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  11283. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  11284. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  11285. // SupportedFeatureProfilesMaxLength
  11286. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  11287. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  11288. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  11289. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  11290. // TransactionMessageAttempts
  11291. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  11292. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  11293. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  11294. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11295. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11296. // TransactionMessageRetryInterval
  11297. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  11298. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  11299. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  11300. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11301. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11302. // UnlockConnectorOnEVSideDisconnect
  11303. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  11304. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  11305. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  11306. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  11307. // WebSocketPingInterval
  11308. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  11309. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  11310. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  11311. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  11312. // QueueOffLineStartTransactionMessage
  11313. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  11314. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  11315. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  11316. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  11317. // AuthorizationKey
  11318. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  11319. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  11320. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "" );
  11321. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  11322. // SecurityProfile
  11323. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  11324. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  11325. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "0" );
  11326. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  11327. // DefaultPrice
  11328. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  11329. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  11330. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  11331. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  11332. // CustomDisplayCostAndPrice
  11333. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  11334. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  11335. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  11336. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  11337. // CustomIdleFeeAfterStop
  11338. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  11339. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  11340. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  11341. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  11342. // Configuration Version
  11343. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  11344. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  11345. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  11346. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  11347. //* Local Auth List Management Profile*/
  11348. #if 0
  11349. //For OCTT Test Case
  11350. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11351. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  11352. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11353. #endif
  11354. #if 1
  11355. //LocalAuthListEnabled
  11356. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11357. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  11358. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11359. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11360. #endif
  11361. //LocalAuthListMaxLength
  11362. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  11363. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  11364. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  11365. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  11366. //SendLocalListMaxLength
  11367. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  11368. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  11369. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  11370. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  11371. //ReserveConnectorZeroSupported
  11372. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  11373. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  11374. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  11375. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11376. //* Smart Charging Profile */
  11377. //ChargeProfileMaxStackLevel
  11378. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  11379. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  11380. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  11381. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11382. // ChargingScheduleAllowedChargingRateUnit
  11383. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  11384. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  11385. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  11386. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11387. // ChargingScheduleMaxPeriods
  11388. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  11389. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  11390. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  11391. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11392. // ConnectorSwitch3to1PhaseSupported
  11393. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11394. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11395. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  11396. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11397. // MaxChargingProfilesInstalled
  11398. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11399. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11400. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  11401. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11402. fclose(outfile);
  11403. }
  11404. else
  11405. {
  11406. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  11407. char keystr[60]={0};
  11408. char readonlystr[10]={0};
  11409. char valuestr[256]={0};
  11410. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  11411. if(fp == NULL) {
  11412. DEBUG_INFO("Error opening file");
  11413. return FALSE;
  11414. }
  11415. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  11416. {
  11417. //DEBUG_INFO("Get Configuration \n");
  11418. if(strlen(str) > 0)
  11419. {
  11420. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  11421. //*************************key*********************************/
  11422. if(strstr(str, "key") != NULL)
  11423. {
  11424. loc = strstr(str, "key");
  11425. c = 0;
  11426. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11427. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  11428. {
  11429. sstr[c] = loc[strlen("key")+3+c];
  11430. c++;
  11431. }
  11432. sstr[c] = '\0';
  11433. strcpy(keystr,sstr);
  11434. }
  11435. //*************************readonly*********************************/
  11436. if(strstr(str, "readonly") != NULL)
  11437. {
  11438. loc = strstr(str, "readonly");
  11439. c = 0;
  11440. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11441. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  11442. {
  11443. sstr[c] = loc[strlen("readonly")+2+c];
  11444. c++;
  11445. }
  11446. sstr[c] = '\0';
  11447. strcpy(readonlystr,sstr);
  11448. }
  11449. //*************************value*********************************/
  11450. if(strstr(str, "value") != NULL)
  11451. {
  11452. loc = strstr(str, "value");
  11453. c = 0;
  11454. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11455. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  11456. {
  11457. sstr[c] = loc[strlen("value")+3+c];
  11458. c++;
  11459. }
  11460. sstr[c] = '\0';
  11461. strcpy(valuestr,sstr);
  11462. }
  11463. // DEBUG_INFO("keystr=%s\n",keystr);
  11464. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  11465. // DEBUG_INFO("valuestr=%s\n",valuestr);
  11466. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  11467. {
  11468. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11469. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11470. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  11471. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  11472. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  11473. }
  11474. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  11475. {
  11476. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11477. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11478. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  11479. }
  11480. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  11481. {
  11482. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11483. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  11484. }
  11485. if(strcmp(keystr, "BlinkRepeat") == 0)
  11486. {
  11487. //Charger.BlinkRepeat = Integer.parseInt(value);
  11488. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11489. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  11490. }
  11491. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  11492. {
  11493. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11494. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  11495. }
  11496. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  11497. {
  11498. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11499. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  11500. }
  11501. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  11502. {
  11503. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11504. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  11505. }
  11506. if(strcmp(keystr, "HeartbeatInterval") == 0)
  11507. {
  11508. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11509. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  11510. HeartBeatWaitTime = atoi(valuestr);
  11511. }
  11512. if(strcmp(keystr, "LightIntensity") == 0)
  11513. {
  11514. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11515. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  11516. }
  11517. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  11518. {
  11519. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11520. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  11521. }
  11522. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  11523. {
  11524. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11525. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  11526. }
  11527. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  11528. {
  11529. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11530. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  11531. }
  11532. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  11533. {
  11534. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11535. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  11536. }
  11537. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  11538. {
  11539. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11540. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  11541. }
  11542. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  11543. {
  11544. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11545. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  11546. }
  11547. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  11548. {
  11549. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11550. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  11551. }
  11552. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  11553. {
  11554. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11555. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  11556. }
  11557. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  11558. {
  11559. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11560. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  11561. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  11562. }
  11563. if(strcmp(keystr, "NumberOfConnectors") == 0)
  11564. {
  11565. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11566. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  11567. }
  11568. if(strcmp(keystr, "ResetRetries") == 0)
  11569. {
  11570. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11571. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  11572. }
  11573. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  11574. {
  11575. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11576. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  11577. }
  11578. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  11579. {
  11580. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11581. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  11582. }
  11583. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  11584. {
  11585. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11586. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  11587. }
  11588. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  11589. {
  11590. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11591. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  11592. }
  11593. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  11594. {
  11595. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11596. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  11597. }
  11598. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  11599. {
  11600. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11601. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  11602. }
  11603. if(strcmp(keystr, "StopTxnSampledData") == 0)
  11604. {
  11605. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11606. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  11607. }
  11608. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  11609. {
  11610. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11611. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  11612. }
  11613. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  11614. {
  11615. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11616. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  11617. }
  11618. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  11619. {
  11620. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11621. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  11622. }
  11623. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  11624. {
  11625. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11626. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  11627. TransactionMessageAttemptsValue = atoi(valuestr);
  11628. }
  11629. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  11630. {
  11631. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11632. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  11633. TransactionMessageRetryIntervalValue = atoi(valuestr);
  11634. }
  11635. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  11636. {
  11637. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11638. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  11639. }
  11640. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  11641. {
  11642. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11643. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  11644. }
  11645. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  11646. {
  11647. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11648. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  11649. }
  11650. if(strcmp(keystr, "AuthorizationKey") == 0)
  11651. {
  11652. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11653. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  11654. }
  11655. if(strcmp(keystr, "SecurityProfile") == 0)
  11656. {
  11657. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11658. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  11659. }
  11660. if(strcmp(keystr, "DefaultPrice") == 0)
  11661. {
  11662. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11663. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  11664. }
  11665. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  11666. {
  11667. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11668. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  11669. }
  11670. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  11671. {
  11672. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11673. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  11674. }
  11675. if(strcmp(keystr, "ConfigurationVersion") == 0)
  11676. {
  11677. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11678. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  11679. }
  11680. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  11681. {
  11682. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11683. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  11684. }
  11685. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  11686. {
  11687. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11688. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  11689. }
  11690. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  11691. {
  11692. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11693. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  11694. }
  11695. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  11696. {
  11697. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11698. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  11699. }
  11700. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  11701. {
  11702. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11703. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  11704. }
  11705. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  11706. {
  11707. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11708. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  11709. }
  11710. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  11711. {
  11712. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11713. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  11714. }
  11715. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  11716. {
  11717. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11718. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  11719. }
  11720. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  11721. {
  11722. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11723. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  11724. }
  11725. }
  11726. }
  11727. fclose(fp);
  11728. }
  11729. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  11730. {
  11731. return PASS;
  11732. }
  11733. else
  11734. {
  11735. return FAIL;
  11736. }
  11737. }
  11738. void StoreConfigurationTable(void)
  11739. {
  11740. FILE *outfile;
  11741. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  11742. if(outfile == NULL)
  11743. {
  11744. DEBUG_INFO("Error opening file");
  11745. return ;
  11746. }
  11747. /*Core Profile*/
  11748. //AllowOfflineTxForUnknownId
  11749. /*
  11750. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11751. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  11752. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11753. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  11754. */
  11755. //DEBUG_INFO("data=%s\n",data);
  11756. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11757. //AuthorizationCacheEnabled
  11758. /*
  11759. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11760. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11761. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11762. */
  11763. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11764. //AuthorizeRemoteTxRequests
  11765. /*
  11766. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11767. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11768. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  11769. */
  11770. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11771. //BlinkRepeat
  11772. /*
  11773. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11775. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11776. */
  11777. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11778. //ClockAlignedDataInterval
  11779. /*
  11780. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11781. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11782. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11783. */
  11784. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11785. //ConnectionTimeOut
  11786. /*
  11787. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11788. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11789. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11790. */
  11791. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11792. //GetConfigurationMaxKeys
  11793. /*
  11794. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11795. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11796. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  11797. */
  11798. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11799. // HeartbeatInterval
  11800. /*
  11801. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11803. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  11804. */
  11805. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11806. // LightIntensity
  11807. /*
  11808. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11809. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11810. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11811. */
  11812. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11813. // LocalAuthorizeOffline
  11814. /*
  11815. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  11816. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  11817. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  11818. */
  11819. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11820. // LocalPreAuthorize
  11821. /*
  11822. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  11823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  11824. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  11825. */
  11826. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  11827. // MaxEnergyOnInvalidId
  11828. /*
  11829. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  11830. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  11831. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  11832. */
  11833. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  11834. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  11835. // MeterValuesAlignedData
  11836. /*
  11837. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  11838. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  11839. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  11840. */
  11841. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  11842. // MeterValuesAlignedDataMaxLength
  11843. /*
  11844. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  11845. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  11846. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  11847. */
  11848. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  11849. // MeterValuesSampledData
  11850. /*
  11851. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  11852. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  11853. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  11854. */
  11855. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  11856. // MeterValuesSampledDataMaxLength
  11857. /*
  11858. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  11859. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  11860. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  11861. */
  11862. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  11863. // MeterValueSampleInterval
  11864. /*
  11865. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  11866. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  11867. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  11868. */
  11869. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  11870. // MinimumStatusDuration
  11871. /*
  11872. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  11873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  11874. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  11875. */
  11876. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  11877. // NumberOfConnectors
  11878. /*
  11879. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  11880. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  11881. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11882. {
  11883. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  11884. }
  11885. else
  11886. {
  11887. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  11888. }
  11889. */
  11890. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  11891. // ResetRetries
  11892. /*
  11893. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  11894. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  11895. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  11896. */
  11897. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  11898. // ConnectorPhaseRotation
  11899. /*
  11900. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  11901. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  11902. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  11903. */
  11904. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  11905. // ConnectorPhaseRotationMaxLength
  11906. /*
  11907. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  11908. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  11909. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  11910. */
  11911. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  11912. // StopTransactionOnEVSideDisconnect
  11913. /*
  11914. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  11915. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  11916. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  11917. */
  11918. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  11919. // StopTransactionOnInvalidId
  11920. /*
  11921. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  11922. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  11923. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  11924. */
  11925. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  11926. // StopTxnAlignedData
  11927. /*
  11928. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  11929. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  11930. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  11931. */
  11932. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  11933. // StopTxnAlignedDataMaxLength
  11934. /*
  11935. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  11936. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  11937. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  11938. */
  11939. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  11940. // StopTxnSampledData
  11941. /*
  11942. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  11943. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  11944. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  11945. */
  11946. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  11947. // StopTxnSampledDataMaxLength
  11948. /*
  11949. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  11950. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  11951. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  11952. */
  11953. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  11954. // SupportedFeatureProfiles
  11955. /*
  11956. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  11957. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  11958. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  11959. */
  11960. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  11961. // SupportedFeatureProfilesMaxLength
  11962. /*
  11963. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  11964. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  11965. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  11966. */
  11967. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  11968. // TransactionMessageAttempts
  11969. /*
  11970. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  11971. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  11972. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  11973. */
  11974. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11975. // TransactionMessageRetryInterval
  11976. /*
  11977. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  11978. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  11979. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  11980. */
  11981. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11982. // UnlockConnectorOnEVSideDisconnect
  11983. /*
  11984. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  11985. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  11986. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  11987. */
  11988. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  11989. // WebSocketPingInterval
  11990. /*
  11991. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  11992. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  11993. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  11994. */
  11995. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  11996. // QueueOffLineStartTransactionMessage
  11997. /*
  11998. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  11999. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  12000. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  12001. */
  12002. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  12003. // AuthorizationKey
  12004. /*
  12005. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12006. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12007. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  12008. */
  12009. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12010. // SecurityProfile
  12011. /*
  12012. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12013. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12014. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  12015. */
  12016. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12017. // DefaultPrice
  12018. /*
  12019. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12020. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12021. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12022. */
  12023. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12024. // CustomDisplayCostAndPrice
  12025. /*
  12026. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12027. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12028. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12029. */
  12030. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12031. // CustomIdleFeeAfterStop
  12032. /*
  12033. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12034. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12035. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12036. */
  12037. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12038. // ConfigurationVersion
  12039. /*
  12040. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  12041. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12042. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  12043. */
  12044. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12045. //* Local Auth List Management Profile*/
  12046. //LocalAuthListEnabled
  12047. /*
  12048. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12049. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12050. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12051. */
  12052. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12053. //LocalAuthListMaxLength
  12054. /*
  12055. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12056. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12057. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  12058. */
  12059. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12060. //SendLocalListMaxLength
  12061. /*
  12062. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12063. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12064. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  12065. */
  12066. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12067. //ReserveConnectorZeroSupported
  12068. /*
  12069. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12070. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12071. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12072. */
  12073. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12074. //* Smart Charging Profile */
  12075. //ChargeProfileMaxStackLevel
  12076. /*
  12077. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12078. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12079. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12080. */
  12081. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12082. // ChargingScheduleAllowedChargingRateUnit
  12083. /*
  12084. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12085. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12086. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  12087. */
  12088. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12089. // ChargingScheduleMaxPeriods
  12090. /*
  12091. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12092. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12093. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12094. */
  12095. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12096. // ConnectorSwitch3to1PhaseSupported
  12097. /*
  12098. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  12099. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  12100. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  12101. */
  12102. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12103. // MaxChargingProfilesInstalled
  12104. /*
  12105. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  12106. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  12107. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  12108. */
  12109. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12110. fclose(outfile);
  12111. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12112. }
  12113. void getKeyValue(char *keyReq)
  12114. {
  12115. int isEmpty = FALSE;
  12116. int isKnowKey = FALSE;
  12117. DEBUG_INFO("keyReq = %s\n", keyReq);
  12118. if((keyReq == NULL) || (strlen(keyReq) == 0))
  12119. isEmpty = TRUE;
  12120. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  12121. {
  12122. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  12123. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  12124. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  12125. {
  12126. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  12127. }
  12128. else
  12129. {
  12130. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  12131. }
  12132. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  12133. isKnowKey = TRUE;
  12134. }
  12135. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  12136. {
  12137. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  12138. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  12139. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  12140. {
  12141. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  12142. }
  12143. else
  12144. {
  12145. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  12146. }
  12147. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  12148. isKnowKey = TRUE;
  12149. }
  12150. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  12151. {
  12152. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  12153. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  12154. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  12155. {
  12156. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  12157. }
  12158. else
  12159. {
  12160. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  12161. }
  12162. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  12163. isKnowKey = TRUE;
  12164. }
  12165. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  12166. {
  12167. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  12168. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  12169. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  12170. {
  12171. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  12172. }
  12173. else
  12174. {
  12175. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  12176. }
  12177. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  12178. isKnowKey = TRUE;
  12179. }
  12180. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  12181. {
  12182. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  12183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  12184. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  12185. {
  12186. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  12187. }
  12188. else
  12189. {
  12190. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  12191. }
  12192. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  12193. isKnowKey = TRUE;
  12194. }
  12195. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  12196. {
  12197. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  12198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  12199. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  12200. {
  12201. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  12202. }
  12203. else
  12204. {
  12205. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  12206. }
  12207. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  12208. isKnowKey = TRUE;
  12209. }
  12210. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  12211. {
  12212. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  12213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  12214. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  12215. {
  12216. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  12217. }
  12218. else
  12219. {
  12220. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  12221. }
  12222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  12223. isKnowKey = TRUE;
  12224. }
  12225. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  12226. {
  12227. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  12228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  12229. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  12230. {
  12231. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  12232. }
  12233. else
  12234. {
  12235. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  12236. }
  12237. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  12238. isKnowKey = TRUE;
  12239. }
  12240. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  12241. {
  12242. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  12243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  12244. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  12245. {
  12246. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  12247. }
  12248. else
  12249. {
  12250. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  12251. }
  12252. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  12253. isKnowKey = TRUE;
  12254. }
  12255. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  12256. {
  12257. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  12258. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  12259. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  12260. {
  12261. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  12262. }
  12263. else
  12264. {
  12265. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  12266. }
  12267. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  12268. isKnowKey = TRUE;
  12269. }
  12270. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  12271. {
  12272. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  12273. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  12274. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  12275. {
  12276. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  12277. }
  12278. else
  12279. {
  12280. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  12281. }
  12282. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  12283. isKnowKey = TRUE;
  12284. }
  12285. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  12286. {
  12287. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  12288. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  12289. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  12290. {
  12291. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  12292. }
  12293. else
  12294. {
  12295. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  12296. }
  12297. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  12298. isKnowKey = TRUE;
  12299. }
  12300. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  12301. {
  12302. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  12303. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  12304. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  12305. {
  12306. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  12307. }
  12308. else
  12309. {
  12310. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  12311. }
  12312. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  12313. isKnowKey = TRUE;
  12314. }
  12315. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  12316. {
  12317. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  12318. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  12319. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  12320. {
  12321. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12322. }
  12323. else
  12324. {
  12325. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12326. }
  12327. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  12328. isKnowKey = TRUE;
  12329. }
  12330. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  12331. {
  12332. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  12333. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  12334. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  12335. {
  12336. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  12337. }
  12338. else
  12339. {
  12340. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  12341. }
  12342. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  12343. isKnowKey = TRUE;
  12344. }
  12345. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  12346. {
  12347. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  12348. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  12349. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  12350. {
  12351. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12352. }
  12353. else
  12354. {
  12355. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12356. }
  12357. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  12358. isKnowKey = TRUE;
  12359. }
  12360. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  12361. {
  12362. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  12363. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  12364. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12365. {
  12366. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  12367. }
  12368. else
  12369. {
  12370. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  12371. }
  12372. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  12373. isKnowKey = TRUE;
  12374. }
  12375. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  12376. {
  12377. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  12378. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  12379. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12380. {
  12381. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  12382. }
  12383. else
  12384. {
  12385. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  12386. }
  12387. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  12388. isKnowKey = TRUE;
  12389. }
  12390. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  12391. {
  12392. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  12393. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  12394. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12395. {
  12396. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  12397. }
  12398. else
  12399. {
  12400. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  12401. }
  12402. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  12403. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  12404. isKnowKey = TRUE;
  12405. }
  12406. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  12407. {
  12408. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  12409. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  12410. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12411. {
  12412. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  12413. }
  12414. else
  12415. {
  12416. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  12417. }
  12418. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  12419. isKnowKey = TRUE;
  12420. }
  12421. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  12422. {
  12423. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  12424. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  12425. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12426. {
  12427. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  12428. }
  12429. else
  12430. {
  12431. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  12432. }
  12433. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  12434. isKnowKey = TRUE;
  12435. }
  12436. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  12437. {
  12438. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  12439. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  12440. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12441. {
  12442. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12443. }
  12444. else
  12445. {
  12446. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12447. }
  12448. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  12449. isKnowKey = TRUE;
  12450. }
  12451. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  12452. {
  12453. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  12454. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  12455. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12456. {
  12457. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  12458. }
  12459. else
  12460. {
  12461. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  12462. }
  12463. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  12464. isKnowKey = TRUE;
  12465. }
  12466. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  12467. {
  12468. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  12469. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  12470. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12471. {
  12472. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  12473. }
  12474. else
  12475. {
  12476. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  12477. }
  12478. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  12479. isKnowKey = TRUE;
  12480. }
  12481. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  12482. {
  12483. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  12484. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  12485. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12486. {
  12487. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  12488. }
  12489. else
  12490. {
  12491. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  12492. }
  12493. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  12494. isKnowKey = TRUE;
  12495. }
  12496. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  12497. {
  12498. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  12499. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  12500. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12501. {
  12502. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12503. }
  12504. else
  12505. {
  12506. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12507. }
  12508. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  12509. isKnowKey = TRUE;
  12510. }
  12511. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  12512. {
  12513. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  12514. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  12515. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12516. {
  12517. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  12518. }
  12519. else
  12520. {
  12521. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  12522. }
  12523. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  12524. isKnowKey = TRUE;
  12525. }
  12526. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  12527. {
  12528. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  12529. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  12530. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12531. {
  12532. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12533. }
  12534. else
  12535. {
  12536. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12537. }
  12538. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  12539. isKnowKey = TRUE;
  12540. }
  12541. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  12542. {
  12543. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  12544. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  12545. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12546. {
  12547. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  12548. }
  12549. else
  12550. {
  12551. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  12552. }
  12553. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  12554. isKnowKey = TRUE;
  12555. }
  12556. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  12557. {
  12558. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  12559. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  12560. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12561. {
  12562. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12563. }
  12564. else
  12565. {
  12566. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12567. }
  12568. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  12569. isKnowKey = TRUE;
  12570. }
  12571. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  12572. {
  12573. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  12574. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  12575. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12576. {
  12577. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  12578. }
  12579. else
  12580. {
  12581. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  12582. }
  12583. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  12584. isKnowKey = TRUE;
  12585. }
  12586. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  12587. {
  12588. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  12589. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  12590. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12591. {
  12592. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  12593. }
  12594. else
  12595. {
  12596. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  12597. }
  12598. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  12599. isKnowKey = TRUE;
  12600. }
  12601. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  12602. {
  12603. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  12604. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  12605. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12606. {
  12607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  12608. }
  12609. else
  12610. {
  12611. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  12612. }
  12613. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  12614. isKnowKey = TRUE;
  12615. }
  12616. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  12617. {
  12618. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  12619. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  12620. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12621. {
  12622. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  12623. }
  12624. else
  12625. {
  12626. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  12627. }
  12628. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  12629. isKnowKey = TRUE;
  12630. }
  12631. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  12632. {
  12633. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  12634. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  12635. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12636. {
  12637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  12638. }
  12639. else
  12640. {
  12641. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  12642. }
  12643. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  12644. isKnowKey = TRUE;
  12645. }
  12646. /*
  12647. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  12648. {
  12649. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  12650. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  12651. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  12652. {
  12653. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  12654. }
  12655. else
  12656. {
  12657. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  12658. }
  12659. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  12660. isKnowKey = TRUE;
  12661. }*/
  12662. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  12663. {
  12664. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  12665. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  12666. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  12667. {
  12668. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  12669. }
  12670. else
  12671. {
  12672. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  12673. }
  12674. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  12675. isKnowKey = TRUE;
  12676. }
  12677. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  12678. {
  12679. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  12680. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  12681. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  12682. {
  12683. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  12684. }
  12685. else
  12686. {
  12687. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  12688. }
  12689. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  12690. isKnowKey = TRUE;
  12691. }
  12692. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  12693. {
  12694. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  12695. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  12696. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  12697. {
  12698. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  12699. }
  12700. else
  12701. {
  12702. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  12703. }
  12704. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  12705. isKnowKey = TRUE;
  12706. }
  12707. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  12708. {
  12709. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  12710. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  12711. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  12712. {
  12713. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  12714. }
  12715. else
  12716. {
  12717. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  12718. }
  12719. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  12720. isKnowKey = TRUE;
  12721. }
  12722. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  12723. {
  12724. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  12725. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  12726. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  12727. {
  12728. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  12729. }
  12730. else
  12731. {
  12732. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  12733. }
  12734. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  12735. isKnowKey = TRUE;
  12736. }
  12737. #if 1
  12738. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  12739. {
  12740. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  12741. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  12742. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12743. {
  12744. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  12745. }
  12746. else
  12747. {
  12748. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  12749. }
  12750. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  12751. isKnowKey = TRUE;
  12752. }
  12753. #endif
  12754. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  12755. {
  12756. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  12757. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  12758. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12759. {
  12760. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12761. }
  12762. else
  12763. {
  12764. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12765. }
  12766. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  12767. isKnowKey = TRUE;
  12768. }
  12769. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  12770. {
  12771. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  12772. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  12773. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12774. {
  12775. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12776. }
  12777. else
  12778. {
  12779. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12780. }
  12781. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  12782. isKnowKey = TRUE;
  12783. }
  12784. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  12785. {
  12786. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  12787. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  12788. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12789. {
  12790. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  12791. }
  12792. else
  12793. {
  12794. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  12795. }
  12796. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12797. isKnowKey = TRUE;
  12798. }
  12799. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  12800. {
  12801. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  12802. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  12803. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12804. {
  12805. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  12806. }
  12807. else
  12808. {
  12809. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  12810. }
  12811. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12812. isKnowKey = TRUE;
  12813. }
  12814. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  12815. {
  12816. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  12817. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  12818. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12819. {
  12820. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  12821. }
  12822. else
  12823. {
  12824. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  12825. }
  12826. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12827. isKnowKey = TRUE;
  12828. }
  12829. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  12830. {
  12831. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  12832. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  12833. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12834. {
  12835. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  12836. }
  12837. else
  12838. {
  12839. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  12840. }
  12841. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12842. isKnowKey = TRUE;
  12843. }
  12844. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  12845. {
  12846. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  12847. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  12848. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12849. {
  12850. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  12851. }
  12852. else
  12853. {
  12854. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  12855. }
  12856. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12857. isKnowKey = TRUE;
  12858. }
  12859. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  12860. {
  12861. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  12862. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  12863. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12864. {
  12865. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  12866. }
  12867. else
  12868. {
  12869. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  12870. }
  12871. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12872. isKnowKey = TRUE;
  12873. }
  12874. //=========================================================
  12875. if(!isEmpty && !isKnowKey)
  12876. {
  12877. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  12878. strcpy(unknownkey[UnknownKeynum], keyReq);
  12879. UnknownKeynum = UnknownKeynum + 1;
  12880. }
  12881. }
  12882. void processUnkownKey(void)
  12883. {
  12884. DEBUG_INFO("processUnkownKey...\n");
  12885. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  12886. for(int index=0; index < UnknownKeynum; index++)
  12887. {
  12888. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  12889. {
  12890. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  12891. }
  12892. }
  12893. }
  12894. int setKeyValue(char *key, char *value)
  12895. {
  12896. int isSuccess = NotSupported;
  12897. int check_ascii=0;
  12898. char str[256]={0};
  12899. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  12900. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  12901. {
  12902. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  12903. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  12904. {
  12905. strcpy(str, (const char*)value);
  12906. for(int i = 0; str[i]; i++){
  12907. str[i] = tolower(str[i]);
  12908. }
  12909. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12910. isSuccess = ConfigurationStatus_Accepted;
  12911. }
  12912. else
  12913. {
  12914. isSuccess = ConfigurationStatus_Rejected;
  12915. }
  12916. }
  12917. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  12918. {
  12919. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  12920. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  12921. {
  12922. strcpy(str, (const char*)value);
  12923. for(int i = 0; str[i]; i++){
  12924. str[i] = tolower(str[i]);
  12925. }
  12926. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12927. isSuccess = ConfigurationStatus_Accepted;
  12928. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  12929. }
  12930. else
  12931. {
  12932. isSuccess = ConfigurationStatus_Rejected;
  12933. }
  12934. }
  12935. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  12936. {
  12937. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  12938. {
  12939. strcpy(str, (const char*)value);
  12940. for(int i = 0; str[i]; i++)
  12941. {
  12942. str[i] = tolower(str[i]);
  12943. }
  12944. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  12945. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12946. isSuccess = ConfigurationStatus_Accepted;
  12947. }
  12948. else
  12949. {
  12950. isSuccess = ConfigurationStatus_Rejected;
  12951. }
  12952. }
  12953. if(strcmp(key, "BlinkRepeat") == 0)
  12954. {
  12955. //Charger.BlinkRepeat = Integer.parseInt(value);
  12956. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  12957. {
  12958. check_ascii = value[0];
  12959. if( (check_ascii < 48) || (check_ascii > 57) )
  12960. {
  12961. isSuccess = ConfigurationStatus_Rejected;
  12962. }
  12963. else
  12964. {
  12965. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  12966. isSuccess = ConfigurationStatus_Accepted;
  12967. }
  12968. }
  12969. else
  12970. {
  12971. isSuccess = ConfigurationStatus_Rejected;
  12972. }
  12973. }
  12974. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  12975. {
  12976. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  12977. {
  12978. check_ascii = value[0];
  12979. if( (check_ascii < 48) || (check_ascii > 57) )
  12980. {
  12981. isSuccess = ConfigurationStatus_Rejected;
  12982. }
  12983. else
  12984. {
  12985. if((atoi(value) == 0) || (atoi(value) >= 10))
  12986. {
  12987. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  12988. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  12989. isSuccess = ConfigurationStatus_Accepted;
  12990. }
  12991. else
  12992. isSuccess = ConfigurationStatus_Rejected;
  12993. }
  12994. }
  12995. else
  12996. {
  12997. isSuccess = ConfigurationStatus_Rejected;
  12998. }
  12999. }
  13000. if(strcmp(key, "ConnectionTimeOut") == 0 )
  13001. {
  13002. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  13003. {
  13004. check_ascii = value[0];
  13005. if( (check_ascii < 48) || (check_ascii > 57) )
  13006. {
  13007. isSuccess = ConfigurationStatus_Rejected;
  13008. }
  13009. else
  13010. {
  13011. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  13012. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  13013. isSuccess = ConfigurationStatus_Accepted;
  13014. }
  13015. }
  13016. else
  13017. {
  13018. isSuccess = ConfigurationStatus_Rejected;
  13019. }
  13020. }
  13021. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  13022. {
  13023. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  13024. {
  13025. check_ascii = value[0];
  13026. if( (check_ascii < 48) || (check_ascii > 57) )
  13027. {
  13028. isSuccess = ConfigurationStatus_Rejected;
  13029. }
  13030. else
  13031. {
  13032. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13033. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  13034. isSuccess = ConfigurationStatus_Accepted;
  13035. }
  13036. }
  13037. else
  13038. {
  13039. isSuccess = ConfigurationStatus_Rejected;
  13040. }
  13041. }
  13042. if(strcmp(key, "HeartbeatInterval") == 0)
  13043. {
  13044. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13045. {
  13046. check_ascii = value[0];
  13047. if( (check_ascii < 48) || (check_ascii > 57) )
  13048. {
  13049. isSuccess = ConfigurationStatus_Rejected;
  13050. }
  13051. else
  13052. {
  13053. if((atoi(value) == 0) || (atoi(value) >= 10))
  13054. {
  13055. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13056. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  13057. HeartBeatWaitTime = atoi(value);
  13058. isSuccess = ConfigurationStatus_Accepted;
  13059. }
  13060. else
  13061. {
  13062. isSuccess = ConfigurationStatus_Rejected;
  13063. }
  13064. }
  13065. }
  13066. else
  13067. {
  13068. isSuccess = ConfigurationStatus_Rejected;
  13069. }
  13070. }
  13071. if(strcmp(key, "LightIntensity") == 0)
  13072. {
  13073. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13074. {
  13075. check_ascii = value[0];
  13076. if( (check_ascii < 48) || (check_ascii > 57) )
  13077. {
  13078. isSuccess = ConfigurationStatus_Rejected;
  13079. }
  13080. else
  13081. {
  13082. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  13083. isSuccess = ConfigurationStatus_Accepted;
  13084. }
  13085. }
  13086. else
  13087. {
  13088. isSuccess = ConfigurationStatus_Rejected;
  13089. }
  13090. }
  13091. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  13092. {
  13093. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  13094. {
  13095. strcpy(str, (const char*)value);
  13096. for(int i = 0; str[i]; i++)
  13097. {
  13098. str[i] = tolower(str[i]);
  13099. }
  13100. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13101. isSuccess = ConfigurationStatus_Accepted;
  13102. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13103. }
  13104. else
  13105. {
  13106. isSuccess = ConfigurationStatus_Rejected;
  13107. }
  13108. }
  13109. if(strcmp(key, "LocalPreAuthorize") == 0)
  13110. {
  13111. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  13112. {
  13113. strcpy(str, (const char*)value);
  13114. for(int i = 0; str[i]; i++)
  13115. {
  13116. str[i] = tolower(str[i]);
  13117. }
  13118. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13119. isSuccess = ConfigurationStatus_Accepted;
  13120. }
  13121. else
  13122. {
  13123. isSuccess = ConfigurationStatus_Rejected;
  13124. }
  13125. }
  13126. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  13127. {
  13128. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  13129. {
  13130. check_ascii = value[0];
  13131. if( (check_ascii < 48) || (check_ascii > 57) )
  13132. {
  13133. isSuccess = ConfigurationStatus_Rejected;
  13134. }
  13135. else
  13136. {
  13137. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  13138. isSuccess = ConfigurationStatus_Accepted;
  13139. }
  13140. }
  13141. else
  13142. {
  13143. isSuccess = ConfigurationStatus_Rejected;
  13144. }
  13145. }
  13146. if(strcmp(key, "MeterValuesAlignedData") == 0)
  13147. {
  13148. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13149. {
  13150. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  13151. isSuccess = ConfigurationStatus_Accepted;
  13152. }
  13153. else
  13154. {
  13155. isSuccess = ConfigurationStatus_Rejected;
  13156. }
  13157. }
  13158. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  13159. {
  13160. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13161. {
  13162. check_ascii = value[0];
  13163. if( (check_ascii < 48) || (check_ascii > 57) )
  13164. {
  13165. isSuccess = ConfigurationStatus_Rejected;
  13166. }
  13167. else
  13168. {
  13169. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13170. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  13171. isSuccess = ConfigurationStatus_Accepted;
  13172. }
  13173. }
  13174. else
  13175. {
  13176. isSuccess = ConfigurationStatus_Rejected;
  13177. }
  13178. }
  13179. if(strcmp(key, "MeterValuesSampledData") == 0 )
  13180. {
  13181. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  13182. {
  13183. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  13184. isSuccess = ConfigurationStatus_Accepted;
  13185. }
  13186. else
  13187. {
  13188. isSuccess = ConfigurationStatus_Rejected;
  13189. }
  13190. }
  13191. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  13192. {
  13193. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  13194. {
  13195. check_ascii = value[0];
  13196. if( (check_ascii < 48) || (check_ascii > 57) )
  13197. {
  13198. isSuccess = ConfigurationStatus_Rejected;
  13199. }
  13200. else
  13201. {
  13202. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13203. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  13204. isSuccess = ConfigurationStatus_Accepted;
  13205. }
  13206. }
  13207. else
  13208. {
  13209. isSuccess = ConfigurationStatus_Rejected;
  13210. }
  13211. }
  13212. if(strcmp(key, "MeterValueSampleInterval") == 0)
  13213. {
  13214. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  13215. {
  13216. check_ascii = value[0];
  13217. if( (check_ascii < 48) || (check_ascii > 57) )
  13218. {
  13219. isSuccess = ConfigurationStatus_Rejected;
  13220. }
  13221. else
  13222. {
  13223. if((atoi(value) == 0) || (atoi(value) >= 10))
  13224. {
  13225. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13226. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  13227. isSuccess = ConfigurationStatus_Accepted;
  13228. }
  13229. else
  13230. {
  13231. isSuccess = ConfigurationStatus_Rejected;
  13232. }
  13233. }
  13234. }
  13235. else
  13236. {
  13237. isSuccess = ConfigurationStatus_Rejected;
  13238. }
  13239. }
  13240. if(strcmp(key, "MinimumStatusDuration") == 0)
  13241. {
  13242. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  13243. {
  13244. check_ascii = value[0];
  13245. if( (check_ascii < 48) || (check_ascii > 57) )
  13246. {
  13247. isSuccess = ConfigurationStatus_Rejected;
  13248. }
  13249. else
  13250. {
  13251. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  13252. {
  13253. isSuccess = ConfigurationStatus_Rejected;
  13254. }
  13255. else
  13256. {
  13257. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  13258. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  13259. server_cycle_Status = atoi(value); //StatusNotification Cycle
  13260. isSuccess = ConfigurationStatus_Accepted;
  13261. }
  13262. }
  13263. }
  13264. else
  13265. {
  13266. isSuccess = ConfigurationStatus_Rejected;
  13267. }
  13268. }
  13269. if(strcmp(key, "NumberOfConnectors") == 0)
  13270. {
  13271. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  13272. {
  13273. check_ascii = value[0];
  13274. if( (check_ascii < 48) || (check_ascii > 57) )
  13275. {
  13276. isSuccess = ConfigurationStatus_Rejected;
  13277. }
  13278. else
  13279. {
  13280. //Charger.ResetRetries = Integer.parseInt(value);
  13281. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  13282. isSuccess = ConfigurationStatus_Accepted;
  13283. }
  13284. }
  13285. else
  13286. {
  13287. isSuccess = ConfigurationStatus_Rejected;
  13288. }
  13289. }
  13290. if(strcmp(key, "ResetRetries") == 0)
  13291. {
  13292. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  13293. {
  13294. check_ascii = value[0];
  13295. if( (check_ascii < 48) || (check_ascii > 57) )
  13296. {
  13297. isSuccess = ConfigurationStatus_Rejected;
  13298. }
  13299. else
  13300. {
  13301. //Charger.ResetRetries = Integer.parseInt(value);
  13302. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  13303. isSuccess = ConfigurationStatus_Accepted;
  13304. }
  13305. }
  13306. else
  13307. {
  13308. isSuccess = ConfigurationStatus_Rejected;
  13309. }
  13310. }
  13311. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  13312. {
  13313. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  13314. {
  13315. strcpy(str, (const char*)value);
  13316. for(int i = 0; str[i]; i++)
  13317. {
  13318. str[i] = tolower(str[i]);
  13319. }
  13320. if(strcmp(str, "notapplicable")== 0)
  13321. {
  13322. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  13323. isSuccess = ConfigurationStatus_Accepted;
  13324. }
  13325. else if(strcmp(str, "unknown")== 0)
  13326. {
  13327. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  13328. isSuccess = ConfigurationStatus_Accepted;
  13329. }
  13330. else if(strcmp(str, "rst")== 0)
  13331. {
  13332. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  13333. isSuccess = ConfigurationStatus_Accepted;
  13334. }
  13335. else if(strcmp(str, "rts")== 0)
  13336. {
  13337. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  13338. isSuccess = ConfigurationStatus_Accepted;
  13339. }
  13340. else if(strcmp(str, "srt")== 0)
  13341. {
  13342. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  13343. isSuccess = ConfigurationStatus_Accepted;
  13344. }
  13345. else if(strcmp(str, "str")== 0)
  13346. {
  13347. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  13348. isSuccess = ConfigurationStatus_Accepted;
  13349. }
  13350. else if(strcmp(str, "trs")== 0)
  13351. {
  13352. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  13353. isSuccess = ConfigurationStatus_Accepted;
  13354. }
  13355. else if(strcmp(str, "tsr")== 0)
  13356. {
  13357. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  13358. isSuccess = ConfigurationStatus_Accepted;
  13359. }
  13360. else
  13361. {
  13362. isSuccess = ConfigurationStatus_Rejected;
  13363. }
  13364. }
  13365. else
  13366. {
  13367. isSuccess = ConfigurationStatus_Rejected;
  13368. }
  13369. }
  13370. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  13371. {
  13372. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  13373. {
  13374. check_ascii = value[0];
  13375. if( (check_ascii < 48) || (check_ascii > 57) )
  13376. {
  13377. isSuccess = ConfigurationStatus_Rejected;
  13378. }
  13379. else
  13380. {
  13381. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  13382. isSuccess = ConfigurationStatus_Accepted;
  13383. }
  13384. }
  13385. else
  13386. {
  13387. isSuccess = ConfigurationStatus_Rejected;
  13388. }
  13389. }
  13390. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  13391. {
  13392. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  13393. {
  13394. strcpy(str, (const char*)value);
  13395. for(int i = 0; str[i]; i++)
  13396. {
  13397. str[i] = tolower(str[i]);
  13398. }
  13399. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  13400. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13401. isSuccess = ConfigurationStatus_Accepted;
  13402. }
  13403. else
  13404. {
  13405. isSuccess = ConfigurationStatus_Rejected;
  13406. }
  13407. }
  13408. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  13409. {
  13410. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  13411. {
  13412. strcpy(str, (const char*)value);
  13413. for(int i = 0; str[i]; i++)
  13414. {
  13415. str[i] = tolower(str[i]);
  13416. }
  13417. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  13418. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13419. isSuccess = ConfigurationStatus_Accepted;
  13420. }
  13421. else
  13422. {
  13423. isSuccess = ConfigurationStatus_Rejected;
  13424. }
  13425. }
  13426. if(strcmp(key, "StopTxnAlignedData") == 0)
  13427. {
  13428. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  13429. {
  13430. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  13431. isSuccess = ConfigurationStatus_Accepted;
  13432. }
  13433. else
  13434. {
  13435. isSuccess = ConfigurationStatus_Rejected;
  13436. }
  13437. }
  13438. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  13439. {
  13440. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  13441. {
  13442. check_ascii = value[0];
  13443. if( (check_ascii < 48) || (check_ascii > 57) )
  13444. {
  13445. isSuccess = ConfigurationStatus_Rejected;
  13446. }
  13447. else
  13448. {
  13449. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  13450. isSuccess = ConfigurationStatus_Accepted;
  13451. }
  13452. }
  13453. else
  13454. {
  13455. isSuccess = ConfigurationStatus_Rejected;
  13456. }
  13457. }
  13458. if(strcmp(key, "StopTxnSampledData") == 0)
  13459. {
  13460. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  13461. {
  13462. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  13463. isSuccess = ConfigurationStatus_Accepted;
  13464. }
  13465. else
  13466. {
  13467. isSuccess = ConfigurationStatus_Rejected;
  13468. }
  13469. }
  13470. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  13471. {
  13472. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  13473. {
  13474. check_ascii = value[0];
  13475. if( (check_ascii < 48) || (check_ascii > 57) )
  13476. {
  13477. isSuccess = ConfigurationStatus_Rejected;
  13478. }
  13479. else
  13480. {
  13481. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  13482. isSuccess = ConfigurationStatus_Accepted;
  13483. }
  13484. }
  13485. else
  13486. {
  13487. isSuccess = ConfigurationStatus_Rejected;
  13488. }
  13489. }
  13490. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  13491. {
  13492. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  13493. {
  13494. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  13495. isSuccess = ConfigurationStatus_Accepted;
  13496. }
  13497. else
  13498. {
  13499. isSuccess = ConfigurationStatus_Rejected;
  13500. }
  13501. }
  13502. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  13503. {
  13504. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  13505. {
  13506. check_ascii = value[0];
  13507. if( (check_ascii < 48) || (check_ascii > 57) )
  13508. {
  13509. isSuccess = ConfigurationStatus_Rejected;
  13510. }
  13511. else
  13512. {
  13513. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  13514. isSuccess = ConfigurationStatus_Accepted;
  13515. }
  13516. }
  13517. else
  13518. {
  13519. isSuccess = ConfigurationStatus_Rejected;
  13520. }
  13521. }
  13522. if(strcmp(key, "TransactionMessageAttempts") == 0)
  13523. {
  13524. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  13525. {
  13526. check_ascii = value[0];
  13527. if( (check_ascii < 48) || (check_ascii > 57) )
  13528. {
  13529. isSuccess = ConfigurationStatus_Rejected;
  13530. }
  13531. else
  13532. {
  13533. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  13534. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  13535. TransactionMessageAttemptsValue = atoi(value);
  13536. isSuccess = ConfigurationStatus_Accepted;
  13537. }
  13538. }
  13539. else
  13540. {
  13541. isSuccess = ConfigurationStatus_Rejected;
  13542. }
  13543. }
  13544. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  13545. {
  13546. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  13547. {
  13548. check_ascii = value[0];
  13549. if( (check_ascii < 48) || (check_ascii > 57) )
  13550. {
  13551. isSuccess = ConfigurationStatus_Rejected;
  13552. }
  13553. else
  13554. {
  13555. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  13556. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  13557. TransactionMessageRetryIntervalValue = atoi(value);
  13558. isSuccess = ConfigurationStatus_Accepted;
  13559. }
  13560. }
  13561. else
  13562. {
  13563. isSuccess = ConfigurationStatus_Rejected;
  13564. }
  13565. }
  13566. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  13567. {
  13568. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  13569. {
  13570. strcpy(str, (const char*)value);
  13571. for(int i = 0; str[i]; i++)
  13572. {
  13573. str[i] = tolower(str[i]);
  13574. }
  13575. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  13576. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13577. isSuccess = ConfigurationStatus_Accepted;
  13578. }
  13579. else
  13580. {
  13581. isSuccess = ConfigurationStatus_Rejected;
  13582. }
  13583. }
  13584. if(strcmp(key, "WebSocketPingInterval") == 0)
  13585. {
  13586. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  13587. {
  13588. check_ascii = value[0];
  13589. if( (check_ascii < 48) || (check_ascii > 57) )
  13590. {
  13591. isSuccess = ConfigurationStatus_Rejected;
  13592. }
  13593. else
  13594. {
  13595. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  13596. isSuccess = ConfigurationStatus_Accepted;
  13597. }
  13598. }
  13599. else
  13600. {
  13601. isSuccess = ConfigurationStatus_Rejected;
  13602. }
  13603. }
  13604. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  13605. {
  13606. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  13607. {
  13608. strcpy(str, (const char*)value);
  13609. for(int i = 0; str[i]; i++)
  13610. {
  13611. str[i] = tolower(str[i]);
  13612. }
  13613. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13614. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13615. isSuccess = ConfigurationStatus_Accepted;
  13616. }
  13617. else
  13618. {
  13619. isSuccess = ConfigurationStatus_Rejected;
  13620. }
  13621. }
  13622. if(strcmp(key, "AuthorizationKey") == 0)
  13623. {
  13624. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  13625. {
  13626. strcpy(str, (const char*)value);
  13627. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  13628. isSuccess = ConfigurationStatus_Accepted;
  13629. }
  13630. else
  13631. {
  13632. isSuccess = ConfigurationStatus_Rejected;
  13633. }
  13634. }
  13635. if(strcmp(key, "SecurityProfile") == 0)
  13636. {
  13637. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  13638. {
  13639. check_ascii = value[0];
  13640. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  13641. {
  13642. isSuccess = ConfigurationStatus_Rejected;
  13643. }
  13644. else if(check_ascii == 0x33)
  13645. {
  13646. isSuccess = NotSupported;
  13647. }
  13648. else
  13649. {
  13650. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  13651. {
  13652. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  13653. isSuccess = ConfigurationStatus_Accepted;
  13654. }
  13655. else
  13656. isSuccess = ConfigurationStatus_Rejected;
  13657. }
  13658. }
  13659. else
  13660. {
  13661. isSuccess = ConfigurationStatus_Rejected;
  13662. }
  13663. }
  13664. if(strcmp(key, "DefaultPrice") == 0)
  13665. {
  13666. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  13667. {
  13668. strcpy(str, (const char*)value);
  13669. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  13670. isSuccess = ConfigurationStatus_Accepted;
  13671. }
  13672. else
  13673. {
  13674. isSuccess = ConfigurationStatus_Rejected;
  13675. }
  13676. }
  13677. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  13678. {
  13679. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  13680. {
  13681. strcpy(str, (const char*)value);
  13682. for(int i = 0; str[i]; i++)
  13683. {
  13684. str[i] = tolower(str[i]);
  13685. }
  13686. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13687. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13688. isSuccess = ConfigurationStatus_Accepted;
  13689. }
  13690. else
  13691. {
  13692. isSuccess = ConfigurationStatus_Rejected;
  13693. }
  13694. }
  13695. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  13696. {
  13697. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  13698. {
  13699. strcpy(str, (const char*)value);
  13700. for(int i = 0; str[i]; i++)
  13701. {
  13702. str[i] = tolower(str[i]);
  13703. }
  13704. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13705. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13706. isSuccess = ConfigurationStatus_Accepted;
  13707. }
  13708. else
  13709. {
  13710. isSuccess = ConfigurationStatus_Rejected;
  13711. }
  13712. }
  13713. #if 0
  13714. //For OCPP Test Case
  13715. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  13716. {
  13717. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13718. {
  13719. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  13720. isSuccess = ConfigurationStatus_Accepted;
  13721. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13722. }
  13723. else
  13724. {
  13725. isSuccess = ConfigurationStatus_Rejected;
  13726. }
  13727. }
  13728. #endif
  13729. #if 1
  13730. if(strcmp(key, "LocalAuthListEnabled") == 0)
  13731. {
  13732. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13733. {
  13734. strcpy(str, (const char*)value);
  13735. for(int i = 0; str[i]; i++)
  13736. {
  13737. str[i] = tolower(str[i]);
  13738. }
  13739. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13740. isSuccess = ConfigurationStatus_Accepted;
  13741. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13742. }
  13743. else
  13744. {
  13745. isSuccess = ConfigurationStatus_Rejected;
  13746. }
  13747. }
  13748. #endif
  13749. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  13750. {
  13751. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  13752. {
  13753. check_ascii = value[0];
  13754. if( (check_ascii < 48) || (check_ascii > 57) )
  13755. {
  13756. isSuccess = ConfigurationStatus_Rejected;
  13757. }
  13758. else
  13759. {
  13760. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  13761. isSuccess = ConfigurationStatus_Accepted;
  13762. }
  13763. }
  13764. else
  13765. {
  13766. isSuccess = ConfigurationStatus_Rejected;
  13767. }
  13768. }
  13769. if(strcmp(key, "SendLocalListMaxLength") == 0)
  13770. {
  13771. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  13772. {
  13773. check_ascii = value[0];
  13774. if( (check_ascii < 48) || (check_ascii > 57) )
  13775. {
  13776. isSuccess = ConfigurationStatus_Rejected;
  13777. }
  13778. else
  13779. {
  13780. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  13781. isSuccess = ConfigurationStatus_Accepted;
  13782. }
  13783. }
  13784. else
  13785. {
  13786. isSuccess = ConfigurationStatus_Rejected;
  13787. }
  13788. }
  13789. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  13790. {
  13791. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  13792. {
  13793. strcpy(str, (const char*)value);
  13794. for(int i = 0; str[i]; i++)
  13795. {
  13796. str[i] = tolower(str[i]);
  13797. }
  13798. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13799. isSuccess = ConfigurationStatus_Accepted;
  13800. }
  13801. else
  13802. {
  13803. isSuccess = ConfigurationStatus_Rejected;
  13804. }
  13805. }
  13806. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  13807. {
  13808. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  13809. {
  13810. check_ascii = value[0];
  13811. if( (check_ascii < 48) || (check_ascii > 57) )
  13812. {
  13813. isSuccess = ConfigurationStatus_Rejected;
  13814. }
  13815. else
  13816. {
  13817. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  13818. isSuccess = ConfigurationStatus_Accepted;
  13819. }
  13820. }
  13821. else
  13822. {
  13823. isSuccess = ConfigurationStatus_Rejected;
  13824. }
  13825. }
  13826. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  13827. {
  13828. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  13829. {
  13830. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  13831. isSuccess = ConfigurationStatus_Accepted;
  13832. }
  13833. else
  13834. {
  13835. isSuccess = ConfigurationStatus_Rejected;
  13836. }
  13837. }
  13838. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  13839. {
  13840. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  13841. {
  13842. check_ascii = value[0];
  13843. if( (check_ascii < 48) || (check_ascii > 57) )
  13844. {
  13845. isSuccess = ConfigurationStatus_Rejected;
  13846. }
  13847. else
  13848. {
  13849. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  13850. isSuccess = ConfigurationStatus_Accepted;
  13851. }
  13852. }
  13853. else
  13854. {
  13855. isSuccess = ConfigurationStatus_Rejected;
  13856. }
  13857. }
  13858. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  13859. {
  13860. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  13861. {
  13862. strcpy(str, (const char*)value);
  13863. for(int i = 0; str[i]; i++)
  13864. {
  13865. str[i] = tolower(str[i]);
  13866. }
  13867. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13868. isSuccess = ConfigurationStatus_Accepted;
  13869. }
  13870. else
  13871. {
  13872. isSuccess = ConfigurationStatus_Rejected;
  13873. }
  13874. }
  13875. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  13876. {
  13877. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  13878. {
  13879. check_ascii = value[0];
  13880. if( (check_ascii < 48) || (check_ascii > 57) )
  13881. {
  13882. isSuccess = ConfigurationStatus_Rejected;
  13883. }
  13884. else
  13885. {
  13886. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  13887. isSuccess = ConfigurationStatus_Accepted;
  13888. }
  13889. }
  13890. else
  13891. {
  13892. isSuccess = ConfigurationStatus_Rejected;
  13893. }
  13894. }
  13895. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13896. return isSuccess;
  13897. }
  13898. int TransactionMessageAttemptsGet(void)
  13899. {
  13900. return TransactionMessageAttemptsValue;
  13901. }
  13902. int FirstHeartBeatResponse(void)
  13903. {
  13904. return FirstHeartBeat;
  13905. }
  13906. int TransactionMessageRetryIntervalGet(void)
  13907. {
  13908. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13909. }
  13910. int ReadHttpStatus(int sock)
  13911. {
  13912. //char c;
  13913. char buff[1024]="",*ptr=buff+1;
  13914. int bytes_received, status;
  13915. DEBUG_INFO("Begin Response ..\n");
  13916. while((bytes_received = recv(sock, ptr, 1, 0))){
  13917. if(bytes_received==-1){
  13918. perror("ReadHttpStatus");
  13919. exit(1);
  13920. }
  13921. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  13922. ptr++;
  13923. }
  13924. *ptr=0;
  13925. ptr=buff+1;
  13926. sscanf(ptr,"%*s %d ", &status);
  13927. DEBUG_INFO("%s\n",ptr);
  13928. DEBUG_INFO("status=%d\n",status);
  13929. DEBUG_INFO("End Response ..\n");
  13930. return (bytes_received>0)?status:0;
  13931. }
  13932. //the only filed that it parsed is 'Content-Length'
  13933. int ParseHeader(int sock)
  13934. {
  13935. //char c;
  13936. char buff[1024]="",*ptr=buff+4;
  13937. int bytes_received;
  13938. DEBUG_INFO("Begin HEADER ..\n");
  13939. while((bytes_received = recv(sock, ptr, 1, 0))){
  13940. if(bytes_received==-1){
  13941. perror("Parse Header");
  13942. exit(1);
  13943. }
  13944. if(
  13945. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  13946. (ptr[-1]=='\r') && (*ptr=='\n' )
  13947. ) break;
  13948. ptr++;
  13949. }
  13950. *ptr=0;
  13951. ptr=buff+4;
  13952. //printf("%s",ptr);
  13953. if(bytes_received){
  13954. ptr=strstr(ptr,"Content-Length:");
  13955. if(ptr){
  13956. sscanf(ptr,"%*s %d",&bytes_received);
  13957. }else
  13958. bytes_received=-1; //unknown size
  13959. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  13960. }
  13961. DEBUG_INFO("End HEADER ..\n");
  13962. return bytes_received ;
  13963. }
  13964. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  13965. {
  13966. int result = TRUE;
  13967. char rmFileCmd[100]={0};
  13968. char FilePath[100]={0};
  13969. char ftpbuf[200];
  13970. int systemresult;
  13971. //DEBUG_INFO("filename=%s\n",filename);
  13972. //DEBUG_INFO("url=%s\n",url);
  13973. sprintf(FilePath,"/mnt/%s",filename);
  13974. system("ping 8.8.8.8 &");
  13975. if((access(FilePath,F_OK))!=-1)
  13976. {
  13977. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13978. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13979. system(rmFileCmd);
  13980. }
  13981. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13982. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  13983. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13984. systemresult = system(ftpbuf);
  13985. //DEBUG_INFO("systemresult=%d\n",systemresult);
  13986. if(systemresult != 0)
  13987. {
  13988. DEBUG_INFO("http DownLoad error!\n");
  13989. result = FALSE;
  13990. }
  13991. system("pkill ping");
  13992. return result;
  13993. }
  13994. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  13995. {
  13996. int result = TRUE;
  13997. char rmFileCmd[100]={0};
  13998. char FilePath[100]={0};
  13999. char ftpbuf[200];
  14000. int systemresult;
  14001. //char temp[100];
  14002. sprintf(FilePath,"/mnt/%s",filename);
  14003. system("ping 8.8.8.8 &");
  14004. if((access(FilePath,F_OK))!=-1)
  14005. {
  14006. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14007. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14008. system(rmFileCmd);
  14009. }
  14010. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14011. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14012. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  14013. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14014. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14015. systemresult = system(ftpbuf);
  14016. //DEBUG_INFO("systemresult=%d\n",systemresult);
  14017. if(systemresult != 0)
  14018. {
  14019. printf("wget error!\n");
  14020. result = FALSE;
  14021. }
  14022. system("pkill ping");
  14023. return result;
  14024. }
  14025. int httpUploadFile(char *location, char *path, char *filename,char *url)
  14026. {
  14027. char rmFileCmd[100]={0};
  14028. char FilePath[100]={0};
  14029. char buf[512];
  14030. int systemresult = 0;
  14031. //DEBUG_INFO("filename=%s\n",filename);
  14032. //DEBUG_INFO("url=%s\n",url);
  14033. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  14034. if((access(FilePath,F_OK))!=-1)
  14035. {
  14036. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14037. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14038. system(rmFileCmd);
  14039. }
  14040. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  14041. if(fp == NULL)
  14042. {
  14043. DEBUG_INFO("log is NULL\n");
  14044. return FALSE;
  14045. }
  14046. else
  14047. {
  14048. fprintf(fp, "%s\n", url);
  14049. fprintf(fp, "%s\n", filename);
  14050. fclose(fp);
  14051. }
  14052. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  14053. if(phpFP == NULL)
  14054. {
  14055. DEBUG_INFO("PHP upload fail.\n");
  14056. return FALSE;
  14057. }
  14058. else
  14059. {
  14060. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  14061. {
  14062. if(strstr(buf, "result") != NULL)
  14063. {
  14064. sscanf(buf, "result: %d", &systemresult);
  14065. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  14066. }
  14067. }
  14068. pclose(phpFP);
  14069. }
  14070. if(systemresult != 1)
  14071. {
  14072. DEBUG_INFO("HTTP upload error!\n");
  14073. return FALSE;
  14074. }
  14075. return TRUE;
  14076. }
  14077. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  14078. {
  14079. struct hostent* server;
  14080. char *IPbuffer;
  14081. char ftpbuf[200];
  14082. int systemresult;
  14083. // To retrieve host information
  14084. server = gethostbyname(location);
  14085. // To convert an Internet network
  14086. // address into ASCII string
  14087. IPbuffer = inet_ntoa(*((struct in_addr*)
  14088. server->h_addr_list[0]));
  14089. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14090. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  14091. /* format : ftpput -u username -p passwd IP target source*/
  14092. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  14093. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14094. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14095. systemresult = system(ftpbuf);
  14096. DEBUG_INFO("systemresult=%d\n",systemresult);
  14097. if(systemresult != 0)
  14098. {
  14099. DEBUG_INFO("ftpput error!\n");
  14100. return FALSE;
  14101. }
  14102. return TRUE;
  14103. }
  14104. int GetOcppServerURL()
  14105. {
  14106. int result = FALSE;
  14107. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  14108. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  14109. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  14110. struct yuarel url;
  14111. char urlStr[512];
  14112. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  14113. {
  14114. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  14115. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14116. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  14117. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  14118. if(yuarel_parse(&url, urlStr) != -1)
  14119. {
  14120. sprintf(OcppProtocol, "%s", url.scheme);
  14121. sprintf(OcppHost, "%s", url.host);
  14122. if(url.path == NULL)
  14123. OcppTempPath[0] = '\0';
  14124. else
  14125. {
  14126. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  14127. {
  14128. sprintf(OcppTempPath, "%s/", url.path);
  14129. }
  14130. else
  14131. {
  14132. sprintf(OcppTempPath, "%s", url.path);
  14133. }
  14134. }
  14135. if(url.port == 0)
  14136. {
  14137. if(strcmp(OcppProtocol, "wss") == 0)
  14138. OcppPort = 443;
  14139. else
  14140. OcppPort = 80;
  14141. }
  14142. else
  14143. OcppPort = url.port;
  14144. result = TRUE;
  14145. }
  14146. }
  14147. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  14148. {
  14149. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  14150. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14151. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  14152. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  14153. if(yuarel_parse(&url, urlStr) != -1)
  14154. {
  14155. sprintf(OcppProtocol, "%s", url.scheme);
  14156. sprintf(OcppHost, "%s", url.host);
  14157. if(url.path == NULL)
  14158. OcppTempPath[0] = '\0';
  14159. else
  14160. sprintf(OcppTempPath, "%s", url.path);
  14161. if(url.port == 0)
  14162. {
  14163. if(strcmp(OcppProtocol, "wss") == 0)
  14164. OcppPort = 443;
  14165. else
  14166. OcppPort = 80;
  14167. }
  14168. else
  14169. OcppPort = url.port;
  14170. result = TRUE;
  14171. }
  14172. }
  14173. else
  14174. {
  14175. strcpy(OcppHost,"");
  14176. }
  14177. return result;
  14178. }
  14179. int GetOcppPath()
  14180. {
  14181. int result = FALSE;
  14182. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  14183. {
  14184. if(OcppTempPath == NULL)
  14185. {
  14186. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  14187. }
  14188. else
  14189. {
  14190. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  14191. }
  14192. result = TRUE;
  14193. goto End;
  14194. }
  14195. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  14196. {
  14197. if(OcppTempPath == NULL)
  14198. {
  14199. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  14200. }
  14201. else
  14202. {
  14203. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  14204. }
  14205. result = TRUE;
  14206. goto End;
  14207. }
  14208. else
  14209. {
  14210. strcpy(OcppPath,"");
  14211. }
  14212. End:
  14213. return result;
  14214. }
  14215. int GetOcppPort()
  14216. {
  14217. return OcppPort;
  14218. }
  14219. int GetOcppConnStatus(void)
  14220. {
  14221. return ShmOCPP16Data->OcppConnStatus;
  14222. }
  14223. void SetOcppConnStatus(uint8_t status)
  14224. {
  14225. ShmOCPP16Data->OcppConnStatus = status;
  14226. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  14227. }
  14228. int GetHeartBeatWithNOResponse(void)
  14229. {
  14230. return HeartBeatWithNOResponse;
  14231. }
  14232. void SetHeartBeatWithNOResponse(void)
  14233. {
  14234. HeartBeatWithNOResponse = 0;
  14235. }
  14236. void GetStartTransactionIdTag(int gun_index)
  14237. {
  14238. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  14239. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  14240. }
  14241. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  14242. {
  14243. char ch;
  14244. FILE *fptr1;
  14245. int temptransactionId;
  14246. char str[100]={0};
  14247. temptransactionId = 0;
  14248. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  14249. {
  14250. DEBUG_INFO("IdTag is empty.\n");
  14251. return temptransactionId;
  14252. }
  14253. /*------ Read the file ----------------*/
  14254. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  14255. if (!fptr1)
  14256. {
  14257. DEBUG_INFO("QueueTransactionId file open error.\n");
  14258. //printf(" File not found or unable to open the input file!!\n");
  14259. return temptransactionId;
  14260. }
  14261. ch=fgetc(fptr1);
  14262. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  14263. rewind(fptr1);
  14264. if(ch!=EOF)
  14265. {
  14266. // printf("%c",ch);
  14267. while (fgets(str, 100, fptr1) != NULL)
  14268. {
  14269. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14270. if(str[0]=='\0')
  14271. {
  14272. break;
  14273. }
  14274. char *revbuf[8] = {0}; // Variable store string split
  14275. int num = 0;// Quantity after string split
  14276. DEBUG_INFO("Transaction queue data= %s\n", str);
  14277. splitstring(str,",",revbuf,&num); // String split
  14278. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  14279. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  14280. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  14281. DEBUG_INFO("------------------------------\n");
  14282. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  14283. {
  14284. if(isStopTransaction)
  14285. {
  14286. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  14287. {
  14288. temptransactionId = atoi(revbuf[2]);
  14289. //break;
  14290. }
  14291. }
  14292. else
  14293. {
  14294. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  14295. {
  14296. temptransactionId = atoi(revbuf[2]);
  14297. //break;
  14298. }
  14299. }
  14300. }
  14301. }
  14302. }
  14303. else
  14304. DEBUG_INFO("EOF\n");
  14305. fclose(fptr1);
  14306. /*------- End of reading ---------------*/
  14307. return temptransactionId;
  14308. }
  14309. void SetTransactionIdZero(int transactionId)
  14310. {
  14311. char ch;
  14312. FILE *fptr1, *fptr2;
  14313. int temptransactionId = 0;
  14314. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  14315. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  14316. if (!fptr1)
  14317. {
  14318. //printf(" File not found or unable to open the input file!!\n");
  14319. return ;
  14320. }
  14321. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  14322. if (!fptr2)
  14323. {
  14324. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  14325. fclose(fptr1);
  14326. return ;
  14327. }
  14328. ch=fgetc(fptr1);
  14329. rewind(fptr1);
  14330. if(ch!=EOF)
  14331. {
  14332. // copy all contents to the temporary file except the specific line
  14333. while (fgets(str, 100, fptr1) != NULL)
  14334. {
  14335. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14336. if(str[0]=='\0')
  14337. {
  14338. break;
  14339. }
  14340. char *revbuf[8] = {0};
  14341. int num = 0;
  14342. strcpy(strtemp, str);
  14343. splitstring(str,",",revbuf,&num);
  14344. if(revbuf[2][0] != '\0')
  14345. {
  14346. temptransactionId = atoi(revbuf[2]);
  14347. if(transactionId != temptransactionId)
  14348. {
  14349. fprintf(fptr2, "%s\n", strtemp);
  14350. }
  14351. }
  14352. }
  14353. }
  14354. fclose(fptr1);
  14355. fclose(fptr2);
  14356. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  14357. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  14358. /*------ Read the file ----------------*/
  14359. }
  14360. int InternetDisconnect(void)
  14361. {
  14362. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  14363. }
  14364. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  14365. void storeTempStopTransaction(int gun_index)
  14366. {
  14367. char guid[37]={0};
  14368. int tempIndex = 0;
  14369. char TempStopTransaction[256];
  14370. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  14371. DEBUG_INFO("storeTempStopTransaction...\n");
  14372. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  14373. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  14374. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  14375. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14376. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14377. {
  14378. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14379. {
  14380. tempIndex = ((gun_index==2) ? 1: 0);
  14381. }
  14382. else
  14383. {
  14384. tempIndex = gun_index;
  14385. }
  14386. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14387. {
  14388. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14389. {
  14390. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  14391. }
  14392. }// END OF CHAdeMO_QUANTITY
  14393. }
  14394. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14395. {
  14396. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14397. {
  14398. tempIndex = ((gun_index==2) ? 1: 0);
  14399. }
  14400. else
  14401. {
  14402. tempIndex = gun_index;
  14403. }
  14404. for (int index = 0; index < CCS_QUANTITY; index++)
  14405. {
  14406. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14407. {
  14408. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  14409. }
  14410. }// END OF CCS_QUANTITY
  14411. }
  14412. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14413. {
  14414. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14415. {
  14416. tempIndex = ((gun_index==2) ? 1: 0);
  14417. }
  14418. else
  14419. {
  14420. tempIndex = gun_index;
  14421. }
  14422. for (int index = 0; index < GB_QUANTITY; index++)
  14423. {
  14424. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14425. {
  14426. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  14427. }
  14428. }// END OF GB_QUANTITY
  14429. }
  14430. else if(gunType[gun_index] == GUN_TYPE_DO)
  14431. {
  14432. tempIndex = gun_index;
  14433. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14434. {
  14435. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14436. {
  14437. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  14438. }
  14439. }
  14440. }
  14441. else
  14442. {
  14443. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14444. {
  14445. tempIndex = 2;
  14446. }
  14447. else
  14448. {
  14449. tempIndex = gun_index;
  14450. }
  14451. for (int index = 0; index < AC_QUANTITY; index++)
  14452. {
  14453. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14454. {
  14455. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  14456. }
  14457. }// END OF AC_QUANTITY
  14458. }
  14459. //Stop Transaction Time
  14460. struct timeval tmnow;
  14461. struct tm *tm;
  14462. char buf[28];//, usec_buf[6];
  14463. gettimeofday(&tmnow, NULL);
  14464. time_t t;
  14465. t = time(NULL);
  14466. /*UTC time and date*/
  14467. tm = gmtime(&t);
  14468. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  14469. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  14470. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  14471. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  14472. random_uuid(guid);
  14473. /***********************************transactionData******************************************************/
  14474. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  14475. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  14476. //=================================
  14477. //1. Transaction_Begin
  14478. //=================================
  14479. //============================== Energy.Active.Import.Interval ===========================================
  14480. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  14481. {
  14482. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  14483. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  14484. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  14485. 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*/]);
  14486. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14487. 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))
  14488. {
  14489. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  14490. }
  14491. else
  14492. {
  14493. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  14494. }
  14495. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  14496. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  14497. }
  14498. //=================================
  14499. //2. Transaction_End
  14500. //=================================
  14501. //2.1====================================== Current.Import L1 ==============================================
  14502. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  14503. {
  14504. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  14505. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14506. {
  14507. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14508. {
  14509. tempIndex = ((gun_index==2) ? 1: 0);
  14510. }
  14511. else
  14512. {
  14513. tempIndex = gun_index;
  14514. }
  14515. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14516. {
  14517. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14518. {
  14519. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14520. }
  14521. }// End of for CHAdeMO_QUANTITY
  14522. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14523. }
  14524. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14525. {
  14526. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14527. {
  14528. tempIndex = ((gun_index==2) ? 1: 0);
  14529. }
  14530. else
  14531. {
  14532. tempIndex = gun_index;
  14533. }
  14534. for (int index = 0; index < CCS_QUANTITY; index++)
  14535. {
  14536. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14537. {
  14538. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14539. }
  14540. }// End of for CCS_QUANTITY
  14541. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14542. }
  14543. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14544. {
  14545. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14546. {
  14547. tempIndex = ((gun_index==2) ? 1: 0);
  14548. }
  14549. else
  14550. {
  14551. tempIndex = gun_index;
  14552. }
  14553. for (int index = 0; index < GB_QUANTITY; index++)
  14554. {
  14555. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14556. {
  14557. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14558. }
  14559. }// End of for GB_QUANTITY
  14560. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14561. }
  14562. else if(gunType[gun_index] == GUN_TYPE_DO)
  14563. {
  14564. tempIndex = gun_index;
  14565. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14566. {
  14567. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14568. {
  14569. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14570. }
  14571. }
  14572. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14573. }
  14574. else
  14575. {
  14576. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14577. {
  14578. tempIndex = 2;
  14579. }
  14580. else
  14581. {
  14582. tempIndex = gun_index;
  14583. }
  14584. for (int index = 0; index < AC_QUANTITY; index++)
  14585. {
  14586. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14587. {
  14588. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  14589. }
  14590. }// End of for AC_QUANTITY
  14591. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  14592. }
  14593. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14594. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  14595. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  14596. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  14597. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  14598. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14599. }
  14600. //2.2===================================== Energy.Active.Import.Interval ==========================================
  14601. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  14602. {
  14603. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14604. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14605. {
  14606. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14607. {
  14608. tempIndex = ((gun_index==2) ? 1: 0);
  14609. }
  14610. else
  14611. {
  14612. tempIndex = gun_index;
  14613. }
  14614. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14615. {
  14616. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14617. {
  14618. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14619. }
  14620. }// END OF CHAdeMO_QUANTITY
  14621. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14622. }
  14623. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14624. {
  14625. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14626. {
  14627. tempIndex = ((gun_index==2) ? 1: 0);
  14628. }
  14629. else
  14630. {
  14631. tempIndex = gun_index;
  14632. }
  14633. for (int index = 0; index < CCS_QUANTITY; index++)
  14634. {
  14635. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14636. {
  14637. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14638. }
  14639. }// END OF CCS_QUANTITY
  14640. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14641. }
  14642. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14643. {
  14644. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14645. {
  14646. tempIndex = ((gun_index==2) ? 1: 0);
  14647. }
  14648. else
  14649. {
  14650. tempIndex = gun_index;
  14651. }
  14652. for (int index = 0; index < GB_QUANTITY; index++)
  14653. {
  14654. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14655. {
  14656. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14657. }
  14658. }// END OF GB_QUANTITY
  14659. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14660. }
  14661. else if(gunType[gun_index] == GUN_TYPE_DO)
  14662. {
  14663. tempIndex = gun_index;
  14664. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14665. {
  14666. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14667. {
  14668. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14669. }
  14670. }
  14671. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14672. }
  14673. else
  14674. {
  14675. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14676. {
  14677. tempIndex = 2;
  14678. }
  14679. else
  14680. {
  14681. tempIndex = gun_index;
  14682. }
  14683. for (int index = 0; index < AC_QUANTITY; index++)
  14684. {
  14685. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14686. {
  14687. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14688. }
  14689. }// END OF AC_QUANTITY
  14690. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  14691. }
  14692. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14693. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  14694. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  14695. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  14696. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  14697. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  14698. }
  14699. //2.3====================================== Power.Active.Import =========================================
  14700. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  14701. {
  14702. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14703. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14704. {
  14705. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14706. {
  14707. tempIndex = ((gun_index==2) ? 1: 0);
  14708. }
  14709. else
  14710. {
  14711. tempIndex = gun_index;
  14712. }
  14713. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14714. {
  14715. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14716. {
  14717. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14718. }
  14719. } // End for CHAdeMO_QUANTITY
  14720. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14721. }
  14722. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14723. {
  14724. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14725. {
  14726. tempIndex = ((gun_index==2) ? 1: 0);
  14727. }
  14728. else
  14729. {
  14730. tempIndex = gun_index;
  14731. }
  14732. for (int index = 0; index < CCS_QUANTITY; index++)
  14733. {
  14734. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14735. {
  14736. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14737. }
  14738. } // END for CCS_QUANTITY
  14739. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14740. }
  14741. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14742. {
  14743. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14744. {
  14745. tempIndex = ((gun_index==2) ? 1: 0);
  14746. }
  14747. else
  14748. {
  14749. tempIndex = gun_index;
  14750. }
  14751. for (int index = 0; index < GB_QUANTITY; index++)
  14752. {
  14753. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14754. {
  14755. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14756. }
  14757. }// END for GB_QUANTITY
  14758. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14759. }
  14760. else if(gunType[gun_index] == GUN_TYPE_DO)
  14761. {
  14762. tempIndex = gun_index;
  14763. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14764. {
  14765. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14766. {
  14767. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14768. }
  14769. }
  14770. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14771. }
  14772. else
  14773. {
  14774. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14775. {
  14776. tempIndex = 2;
  14777. }
  14778. else
  14779. {
  14780. tempIndex = gun_index;
  14781. }
  14782. for (int index = 0; index < AC_QUANTITY; index++)
  14783. {
  14784. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14785. {
  14786. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14787. }
  14788. } // END for AC_QUANTITY
  14789. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  14790. }
  14791. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14792. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  14793. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  14794. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  14795. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  14796. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  14797. }
  14798. //2.4====================================== Voltage L1 ====================================================
  14799. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  14800. {
  14801. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14802. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14803. {
  14804. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14805. {
  14806. tempIndex = ((gun_index==2) ? 1: 0);
  14807. }
  14808. else
  14809. {
  14810. tempIndex = gun_index;
  14811. }
  14812. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14813. {
  14814. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14815. {
  14816. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14817. }
  14818. } // END OF FOR CHAdeMO_QUANTITY
  14819. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14820. }
  14821. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14822. {
  14823. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14824. {
  14825. tempIndex = ((gun_index==2) ? 1: 0);
  14826. }
  14827. else
  14828. {
  14829. tempIndex = gun_index;
  14830. }
  14831. for (int index = 0; index < CCS_QUANTITY; index++)
  14832. {
  14833. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14834. {
  14835. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14836. }
  14837. } // END OF FOR CCS_QUANTITY
  14838. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14839. }
  14840. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14841. {
  14842. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14843. {
  14844. tempIndex = ((gun_index==2) ? 1: 0);
  14845. }
  14846. else
  14847. {
  14848. tempIndex = gun_index;
  14849. }
  14850. for (int index = 0; index < GB_QUANTITY; index++)
  14851. {
  14852. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14853. {
  14854. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14855. }
  14856. } // END OF FOR GB_QUANTITY
  14857. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14858. }
  14859. else if(gunType[gun_index] == GUN_TYPE_DO)
  14860. {
  14861. tempIndex = gun_index;
  14862. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14863. {
  14864. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14865. {
  14866. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14867. }
  14868. }
  14869. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14870. }
  14871. else
  14872. {
  14873. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14874. {
  14875. tempIndex = 2;
  14876. }
  14877. else
  14878. {
  14879. tempIndex = gun_index;
  14880. }
  14881. for (int index = 0; index < AC_QUANTITY; index++)
  14882. {
  14883. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14884. {
  14885. 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
  14886. }
  14887. } // END OF FOR AC_QUANTITY
  14888. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  14889. }
  14890. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14891. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  14892. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  14893. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  14894. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  14895. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  14896. }
  14897. //2.5============================================== End SoC =========================================================
  14898. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  14899. {
  14900. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14901. 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))
  14902. {
  14903. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  14904. {
  14905. tempIndex = ((gun_index==2) ? 1: 0);
  14906. }
  14907. else
  14908. {
  14909. tempIndex = gun_index;
  14910. }
  14911. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14912. {
  14913. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14914. {
  14915. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14916. {
  14917. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  14918. }
  14919. }
  14920. }
  14921. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14922. {
  14923. for (int index = 0; index < CCS_QUANTITY; index++)
  14924. {
  14925. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14926. {
  14927. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  14928. }
  14929. }
  14930. }
  14931. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14932. {
  14933. for (int index = 0; index < GB_QUANTITY; index++)
  14934. {
  14935. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14936. {
  14937. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  14938. }
  14939. }
  14940. }
  14941. else if(gunType[gun_index] == GUN_TYPE_DO)
  14942. {
  14943. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14944. {
  14945. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14946. {
  14947. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  14948. }
  14949. }
  14950. }
  14951. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14952. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  14953. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  14954. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  14955. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  14956. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  14957. } // END FOR DC CASE
  14958. }
  14959. //2.6====================================== Current.Import L2 ==============================================
  14960. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  14961. {
  14962. // AC 3 phase L2 current
  14963. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  14964. {
  14965. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14966. {
  14967. tempIndex = 2;
  14968. }
  14969. else
  14970. {
  14971. tempIndex = gun_index;
  14972. }
  14973. for (int index = 0; index < AC_QUANTITY; index++)
  14974. {
  14975. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14976. {
  14977. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  14978. }
  14979. }// End of for AC_QUANTITY
  14980. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  14981. }
  14982. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14983. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  14984. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  14985. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  14986. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14987. }
  14988. //2.7====================================== Current.Import L3 ==============================================
  14989. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  14990. {
  14991. // AC 3 phase L3 current
  14992. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  14993. {
  14994. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14995. {
  14996. tempIndex = 2;
  14997. }
  14998. else
  14999. {
  15000. tempIndex = gun_index;
  15001. }
  15002. for (int index = 0; index < AC_QUANTITY; index++)
  15003. {
  15004. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15005. {
  15006. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  15007. }
  15008. }// End of for AC_QUANTITY
  15009. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  15010. }
  15011. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15012. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  15013. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  15014. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  15015. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15016. }
  15017. //2.9====================================== Voltage L2 ====================================================
  15018. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15019. {
  15020. // AC 3 phase L2 volatge
  15021. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15022. {
  15023. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15024. {
  15025. tempIndex = 2;
  15026. }
  15027. else
  15028. {
  15029. tempIndex = gun_index;
  15030. }
  15031. for (int index = 0; index < AC_QUANTITY; index++)
  15032. {
  15033. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15034. {
  15035. 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
  15036. }
  15037. } // END OF FOR AC_QUANTITY
  15038. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  15039. }
  15040. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15041. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  15042. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  15043. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  15044. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15045. }
  15046. //2.10====================================== Voltage L3 ====================================================
  15047. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15048. {
  15049. // AC 3 phase L3 volatge
  15050. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15051. {
  15052. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15053. {
  15054. tempIndex = 2;
  15055. }
  15056. else
  15057. {
  15058. tempIndex = gun_index;
  15059. }
  15060. for (int index = 0; index < AC_QUANTITY; index++)
  15061. {
  15062. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15063. {
  15064. 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
  15065. }
  15066. } // END OF FOR AC_QUANTITY
  15067. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  15068. }
  15069. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15070. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  15071. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  15072. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  15073. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15074. }
  15075. //====================== Start SoC ================================
  15076. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  15077. {
  15078. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15079. 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))
  15080. {
  15081. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15082. {
  15083. tempIndex = ((gun_index==2) ? 1: 0);
  15084. }
  15085. else
  15086. {
  15087. tempIndex = gun_index;
  15088. }
  15089. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15090. {
  15091. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15092. {
  15093. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15094. {
  15095. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  15096. }
  15097. }
  15098. }
  15099. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15100. {
  15101. for (int index = 0; index < CCS_QUANTITY; index++)
  15102. {
  15103. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15104. {
  15105. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  15106. }
  15107. }
  15108. }
  15109. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15110. {
  15111. for (int index = 0; index < GB_QUANTITY; index++)
  15112. {
  15113. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15114. {
  15115. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  15116. }
  15117. }
  15118. }
  15119. else if(gunType[gun_index] == GUN_TYPE_DO)
  15120. {
  15121. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15122. {
  15123. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15124. {
  15125. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  15126. }
  15127. }
  15128. }
  15129. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15130. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  15131. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15132. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  15133. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  15134. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15135. } // END FOR DC CASE
  15136. }
  15137. //======================================== Message create ==============================================
  15138. json_object *StopTransaction = json_object_new_object();
  15139. json_object *transactionDatas = json_object_new_array();
  15140. json_object *sampledValues = json_object_new_array();
  15141. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  15142. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  15143. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  15144. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  15145. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  15146. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  15147. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  15148. {
  15149. json_object *transactionData = json_object_new_object();
  15150. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  15151. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  15152. {
  15153. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  15154. {
  15155. json_object *sampledValue = json_object_new_object();
  15156. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  15157. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  15158. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  15159. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  15160. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  15161. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  15162. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  15163. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  15164. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  15165. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  15166. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  15167. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  15168. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  15169. json_object_array_add(sampledValues, sampledValue);
  15170. }
  15171. }
  15172. json_object_object_add(transactionData, "sampledValue", sampledValues);
  15173. json_object_array_add(transactionDatas, transactionData);
  15174. }
  15175. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  15176. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  15177. ,MESSAGE_TYPE_CALL
  15178. ,guid
  15179. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  15180. json_object_put(StopTransaction);
  15181. // Check File "TempStopTransaction" Exist
  15182. if((access(TempStopTransaction,F_OK))!=-1)
  15183. {
  15184. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  15185. fclose(fopen(TempStopTransaction, "w"));
  15186. }
  15187. else
  15188. {
  15189. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  15190. FILE *log = fopen(TempStopTransaction, "w+");
  15191. if(log == NULL)
  15192. {
  15193. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  15194. return ;
  15195. }
  15196. else
  15197. {
  15198. fclose(log);
  15199. }
  15200. }
  15201. //Add TempStopTransaction | Update TempStopTransaction
  15202. // open file for writing
  15203. FILE *outfile;
  15204. outfile = fopen (TempStopTransaction, "a");
  15205. //DEBUG_INFO("data = %s\n", queuedata);
  15206. fputs(queuedata, outfile);
  15207. fputs("\n", outfile);
  15208. fclose (outfile);
  15209. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15210. }
  15211. void checkTempStopTransaction(int gun_index)
  15212. {
  15213. FILE *fptr1;
  15214. char ch;
  15215. char str[QUEUE_MESSAGE_LENGTH]={0};
  15216. char guid[37]={0};
  15217. char tempdata[65]={0};
  15218. char connectorStr[2]={0};
  15219. char TempStopTransaction[256];
  15220. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  15221. fptr1 = fopen(TempStopTransaction, "r");
  15222. //TempStopTransaction格式: 槍號,StopTransaction封包
  15223. if (!fptr1)
  15224. {
  15225. //printf(" File not found or unable to open the input file!!\n");
  15226. return ;
  15227. }
  15228. ch=fgetc(fptr1);
  15229. //printf(" Now the content of the file %s is : \n",fname);
  15230. rewind(fptr1);
  15231. if(ch!=EOF)
  15232. {
  15233. // copy all contents to the temporary file except the specific line
  15234. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  15235. {
  15236. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15237. if(str[0]=='\0')
  15238. {
  15239. break;
  15240. }
  15241. //TempStopTransaction格式: 槍號,StopTransaction封包
  15242. strncpy(connectorStr, str, 1);
  15243. if(atoi(connectorStr) != (gun_index+1))
  15244. {
  15245. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  15246. fclose(fptr1);
  15247. return ;
  15248. }
  15249. //random_uuid(guid);
  15250. strncpy(guid, str+6, 36); //copy guid
  15251. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  15252. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  15253. {
  15254. //DEBUG_INFO("StopTransaction mapitem pass\n");
  15255. }
  15256. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  15257. OCPP_insert_transaction_msg(NO, str);
  15258. memset(str,0,ARRAY_SIZE(str));
  15259. }
  15260. }
  15261. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  15262. fclose(fptr1);
  15263. remove(TempStopTransaction); // remove the original file
  15264. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15265. }
  15266. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  15267. {
  15268. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  15269. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  15270. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  15271. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  15272. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  15273. }
  15274. int GetWebSocketPingInterval(void)
  15275. {
  15276. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15277. }
  15278. int GetServerSign(void)
  15279. {
  15280. return server_sign;
  15281. }
  15282. uint8_t GetOcppSecurityProfile()
  15283. {
  15284. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15285. }
  15286. void GetOcppChargerBoxId(uint8_t *data)
  15287. {
  15288. sprintf((char*)data, "%s", ShmOCPP16Data->ChargeBoxId);
  15289. }
  15290. void GetOcppSecurityPassword(uint8_t *data)
  15291. {
  15292. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15293. }
  15294. void SetOcppVersion(uint8_t *version)
  15295. {
  15296. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  15297. DEBUG_INFO("ocpp version: %s\n", version);
  15298. if(strstr((char*)version, "ocpp1.6") != NULL)
  15299. {
  15300. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  15301. }
  15302. else if(strstr((char*)version, "ocpp2.0") != NULL)
  15303. {
  15304. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  15305. system("pkill OcppBackend");
  15306. }
  15307. }
  15308. void SetServerSign(int value)
  15309. {
  15310. server_sign = value;
  15311. }
  15312. int GetBootNotificationInterval(void)
  15313. {
  15314. return BootNotificationInterval;
  15315. }
  15316. int GetInternetConn(void)
  15317. {
  15318. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  15319. }
  15320. int isConnectorInitMode(int gun_index)
  15321. {
  15322. int tempIndex = 0;
  15323. int result = TRUE;
  15324. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15325. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15326. {
  15327. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15328. {
  15329. tempIndex = ((gun_index==2) ? 1: 0);
  15330. }
  15331. else
  15332. {
  15333. tempIndex = gun_index;
  15334. }
  15335. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15336. {
  15337. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  15338. {
  15339. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15340. } //end of the same index
  15341. }//end of for CHAdeMO_QUANTITY
  15342. }
  15343. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15344. {
  15345. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15346. {
  15347. tempIndex = ((gun_index==2) ? 1: 0);
  15348. }
  15349. else
  15350. {
  15351. tempIndex = gun_index;
  15352. }
  15353. for (int index = 0; index < CCS_QUANTITY; index++)
  15354. {
  15355. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15356. {
  15357. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15358. } //end of the same index
  15359. } // end of for CCS_QUANTITY
  15360. }
  15361. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15362. {
  15363. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15364. {
  15365. tempIndex = ((gun_index==2) ? 1: 0);
  15366. }
  15367. else
  15368. {
  15369. tempIndex = gun_index;
  15370. }
  15371. for (int index = 0; index < GB_QUANTITY; index++)
  15372. {
  15373. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15374. {
  15375. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15376. } //end of the same index
  15377. } // end of for GB_QUANTITY
  15378. }
  15379. else if(gunType[gun_index] == GUN_TYPE_DO)
  15380. {
  15381. tempIndex = gun_index;
  15382. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15383. {
  15384. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15385. {
  15386. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15387. } //end of the same index
  15388. }
  15389. }
  15390. else
  15391. {
  15392. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15393. {
  15394. tempIndex = 2;
  15395. }
  15396. else
  15397. {
  15398. tempIndex = gun_index;
  15399. }
  15400. for (int index = 0; index < AC_QUANTITY; index++)
  15401. {
  15402. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15403. {
  15404. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15405. }//end of the same index
  15406. }//end of for AC_QUANTITY
  15407. }
  15408. return result;
  15409. }
  15410. void refreshProcDogTimer()
  15411. {
  15412. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  15413. }
  15414. void InitialSystemValue(void)
  15415. {
  15416. int connectorIndex = 0;
  15417. //int valueASCII = 0;
  15418. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  15419. gunTotalNumber=0;
  15420. SystemInitial = 0;
  15421. localversion=0;
  15422. BootNotificationInterval = 0;
  15423. authorizeRetryTimes = 0;
  15424. GunStatusInterval = 10;
  15425. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15426. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15427. //Hear Beat
  15428. HeartBeatWithNOResponse = 0;
  15429. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  15430. FirstHeartBeat = 0;
  15431. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  15432. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  15433. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  15434. memset(statusModeChage, 0, ARRAY_SIZE(statusModeChage));
  15435. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  15436. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  15437. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  15438. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  15439. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  15440. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  15441. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  15442. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  15443. memset(gunType, 0, ARRAY_SIZE(gunType));
  15444. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  15445. {
  15446. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O')
  15447. {
  15448. // DO series
  15449. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  15450. {
  15451. SystemInitial = SystemInitial + 1;
  15452. gunTotalNumber = gunTotalNumber + 1;
  15453. gunType[connectorIndex] = GUN_TYPE_DO;
  15454. connectorIndex = connectorIndex + 1;
  15455. }
  15456. }
  15457. else
  15458. {
  15459. // DM, DW, DS series
  15460. //check connector / socket type (index: 8, 9, 10)
  15461. for(int index=7; index <10 ; index++)
  15462. {
  15463. if(index != 8)
  15464. {
  15465. // DC Connector
  15466. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  15467. {
  15468. SystemInitial = SystemInitial + 1;
  15469. gunTotalNumber = gunTotalNumber + 1;
  15470. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  15471. connectorIndex = connectorIndex + 1;
  15472. }
  15473. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  15474. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  15475. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  15476. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  15477. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  15478. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  15479. {
  15480. SystemInitial = SystemInitial + 1;
  15481. gunTotalNumber = gunTotalNumber + 1;
  15482. gunType[connectorIndex] = GUN_TYPE_CCS;
  15483. connectorIndex = connectorIndex + 1;
  15484. }
  15485. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  15486. {
  15487. SystemInitial = SystemInitial + 1;
  15488. gunTotalNumber = gunTotalNumber + 1;
  15489. gunType[connectorIndex] = GUN_TYPE_GBT;
  15490. connectorIndex = connectorIndex + 1;
  15491. }
  15492. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  15493. {
  15494. SystemInitial = SystemInitial + 1;
  15495. gunTotalNumber = gunTotalNumber + 1;
  15496. gunType[connectorIndex] = GUN_TYPE_DO;
  15497. connectorIndex = connectorIndex + 1;
  15498. }
  15499. }
  15500. else
  15501. {
  15502. // AC Connector
  15503. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  15504. {
  15505. SystemInitial = SystemInitial + 1;
  15506. gunTotalNumber = gunTotalNumber + 1;
  15507. gunType[connectorIndex] = GUN_TYPE_AC;
  15508. connectorIndex = connectorIndex + 1;
  15509. }
  15510. }
  15511. }
  15512. }
  15513. //DEBUG_INFO("DC ...\n");
  15514. }
  15515. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  15516. {
  15517. //check connector / socket type (index: 8, 9, 10)
  15518. for(int index=7; index <10 ; index++)
  15519. {
  15520. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  15521. {
  15522. SystemInitial = SystemInitial + 1;
  15523. gunTotalNumber = gunTotalNumber + 1;
  15524. gunType[connectorIndex] = GUN_TYPE_AC;
  15525. connectorIndex = connectorIndex + 1;
  15526. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  15527. }
  15528. }
  15529. }
  15530. //Status && ConnectorPlugIn Setting
  15531. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15532. {
  15533. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  15534. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  15535. }
  15536. for (int index = 0; index < CCS_QUANTITY; index++)
  15537. {
  15538. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  15539. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  15540. }
  15541. for (int index = 0; index < GB_QUANTITY; index++)
  15542. {
  15543. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  15544. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  15545. }
  15546. for (int index = 0; index < AC_QUANTITY; index++)
  15547. {
  15548. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  15549. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  15550. }
  15551. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15552. {
  15553. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  15554. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  15555. }
  15556. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  15557. {
  15558. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  15559. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  15560. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  15561. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  15562. }
  15563. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  15564. clientTime.Heartbeat=time((time_t*)NULL);
  15565. sleep(1);
  15566. }
  15567. void LWS_Send(char *str)
  15568. {
  15569. //=====================================================
  15570. // Check InternetConn 0: disconnected, 1: connected
  15571. //====================================================
  15572. if(GetOcppConnStatus() == 0)
  15573. {
  15574. DEBUG_INFO("offline now !!!\n");
  15575. return;
  15576. }
  15577. // Only disable isWebsocketSendable operation initiated by charger
  15578. if((strstr((char*)str, "\"Authorize\"") != NULL)
  15579. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  15580. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  15581. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  15582. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  15583. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  15584. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  15585. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  15586. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  15587. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  15588. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  15589. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  15590. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  15591. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  15592. {
  15593. isWebsocketSendable = 0;
  15594. }
  15595. pthread_mutex_lock(&lock_send);
  15596. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  15597. sprintf((char *)SendBuffer, "%s", str);
  15598. SendBufLen = strlen(str);
  15599. pthread_mutex_unlock(&lock_send);
  15600. lws_callback_on_writable(wsi_client);
  15601. //lws_service(context, 0);
  15602. //sleep(1);
  15603. }
  15604. void LWS_SendNow(char *str)
  15605. {
  15606. //=====================================================
  15607. // Check InternetConn 0: disconnected, 1: connected
  15608. //====================================================
  15609. if(GetOcppConnStatus() == 0)
  15610. {
  15611. DEBUG_INFO("offline now !!!\n");
  15612. return;
  15613. }
  15614. // Only disable isWebsocketSendable operation initiated by charger
  15615. if((strstr((char*)str, "\"Authorize\"") != NULL)
  15616. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  15617. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  15618. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  15619. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  15620. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  15621. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  15622. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  15623. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  15624. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  15625. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  15626. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  15627. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  15628. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  15629. {
  15630. isWebsocketSendable = 0;
  15631. }
  15632. pthread_mutex_lock(&lock_send);
  15633. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  15634. sprintf((char *)SendBuffer, "%s", str);
  15635. SendBufLen = strlen(str);
  15636. pthread_mutex_unlock(&lock_send);
  15637. lws_callback_on_writable(wsi_client);
  15638. lws_service(context, 0);
  15639. //sleep(1);
  15640. }