MessageHandler.c 754 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. //ConfigurationMaxKeys
  12. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  13. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  14. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  15. //=================================
  16. // StatusNotification cycle
  17. //=================================
  18. static int server_cycle_Status = 120;
  19. //===============================
  20. // Configuration: unknownkey
  21. //===============================
  22. static char unknownkey[10][20] = {0};
  23. static int UnknownKeynum = 0;
  24. //===============================
  25. // Gun Total Numbers
  26. //===============================
  27. static int gunTotalNumber = 0;
  28. static uint8_t gunType[4] = {0};
  29. //===============================
  30. // Local List Version
  31. //===============================
  32. static int localversion=0;
  33. static char idTagAuthorization[32] = {0};
  34. //===============================
  35. // OCPP sign variable
  36. //===============================
  37. static int server_sign = FALSE;
  38. int server_pending = FALSE;
  39. static int BootNotificationInterval = 0;
  40. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  41. //===============================
  42. // OCPP auth variable
  43. //===============================
  44. static int authorizeRetryTimes = 0; //number of Retry times
  45. //===============================
  46. // OCPP other variables
  47. //===============================
  48. static int HeartBeatWaitTime = 10;
  49. static int FirstHeartBeat = 0;
  50. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  51. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  52. static char CurrentChargingProfileScheduleStr[30] = {0};
  53. //========================================
  54. // OCPP status/previous related variables
  55. //========================================
  56. static int GunStatusInterval = 10;
  57. static uint8_t statusModeChage[CONNECTOR_QUANTITY] = {FALSE};
  58. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  59. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  60. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  61. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  62. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  63. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  64. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  65. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  66. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  67. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  68. static int TransactionMessageAttemptsValue = 0;
  69. static int TransactionMessageRetryIntervalValue = 0;
  70. static int TempMeterValueInterval = 0;
  71. static struct OCPPAuthLocalElemet
  72. {
  73. int listVersionInt;
  74. char idTagstr[20];
  75. char parentIdTag[20];
  76. char expiryDate[30];
  77. char idTagstatus[16];
  78. }idTagQuery;
  79. //=============================================
  80. // OCPP HeartBeat Response Not Receive Counts
  81. //============================================
  82. static int HeartBeatWithNOResponse = 0;
  83. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  84. extern sqlite3 *db;
  85. int TransactionMessageAttemptsGet(void);
  86. int TransactionMessageRetryIntervalGet(void);
  87. int GetOcppConnStatus(void);
  88. void SetOcppConnStatus(uint8_t status);
  89. int setKeyValue(char *key, char *value);
  90. void OCPP_get_TableAuthlocalAllData(void);
  91. void processUnkownKey(void);
  92. struct StructOCPPMeterValue
  93. {
  94. unsigned char TimeStamp[28];
  95. struct StructSampledValue SampledValue[10];
  96. };
  97. struct ClientTime
  98. {
  99. unsigned int Heartbeat;
  100. unsigned int StatusNotification[CONNECTOR_QUANTITY];
  101. unsigned int StartTransaction;
  102. unsigned int StopTransaction;
  103. unsigned int MeterValues[CONNECTOR_QUANTITY];
  104. }clientTime;
  105. typedef union
  106. {
  107. //Operations Initiated by Central System
  108. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  109. struct
  110. {
  111. //CsMsgValue[0]
  112. unsigned char StatusNotificationReq:1; //bit 0,
  113. unsigned char StatusNotificationConf:1; //bit 1,
  114. unsigned char TriggerMeterValue:1; //bit 2,
  115. unsigned char :5; //bit 5~7
  116. }bits[CONNECTOR_QUANTITY];
  117. }CpinitiateMsg;
  118. CpinitiateMsg cpinitateMsg;
  119. //GetConfiguration Array
  120. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  121. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  122. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  123. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  124. #if 0
  125. static char *ChargePointErrorCodeStr[] = {
  126. MACROSTR(ConnectorLockFailure),
  127. MACROSTR(EVCommunicationError),
  128. MACROSTR(GroundFailure),
  129. MACROSTR(HighTemperature),
  130. MACROSTR(InternalError),
  131. MACROSTR(LocalListConflict),
  132. MACROSTR(NoError),
  133. MACROSTR(OtherError),
  134. MACROSTR(OverCurrentFailure),
  135. MACROSTR(OverVoltage),
  136. MACROSTR(PowerMeterFailure),
  137. MACROSTR(PowerSwitchFailure),
  138. MACROSTR(ReaderFailure),
  139. MACROSTR(ResetFailure),
  140. MACROSTR(UnderVoltage),
  141. MACROSTR(WeakSignal)
  142. };
  143. #endif
  144. static char * ChargePointStatusStr[] = {
  145. MACROSTR(Available),
  146. MACROSTR(Preparing),
  147. MACROSTR(Charging),
  148. MACROSTR(SuspendedEVSE),
  149. MACROSTR(SuspendedEV),
  150. MACROSTR(Finishing),
  151. MACROSTR(Reserved),
  152. MACROSTR(Unavailable),
  153. MACROSTR(Faulted)
  154. };
  155. static char *RegistrationStatusStr[] = {
  156. MACROSTR(Accepted),
  157. MACROSTR(Pending),
  158. MACROSTR(Rejected)
  159. };
  160. static char *AvailabilityTypeStr[] = {
  161. MACROSTR(Inoperative),
  162. MACROSTR(Operative)
  163. };
  164. static char *AvailabilityStatusStr[] = {
  165. MACROSTR(Accepted),
  166. MACROSTR(Rejected),
  167. MACROSTR(Scheduled)
  168. };
  169. static char *ConfigurationStatusStr[] = {
  170. MACROSTR(Accepted),
  171. MACROSTR(Rejected),
  172. MACROSTR(RebootRequired),
  173. MACROSTR(NotSupported)
  174. };
  175. static char *ClearCacheStatusStr[] = {
  176. MACROSTR(Accepted),
  177. MACROSTR(Rejected)
  178. };
  179. static char *ChargingProfilePurposeTypeStr[] = {
  180. MACROSTR(ChargePointMaxProfile),
  181. MACROSTR(TxDefaultProfile),
  182. MACROSTR(TxProfile)
  183. };
  184. static char *ChargingProfileStatusStr[] = {
  185. MACROSTR(Accepted),
  186. MACROSTR(Rejected),
  187. MACROSTR(NotSupported)
  188. };
  189. static char *ClearChargingProfileStatusStr[] = {
  190. MACROSTR(Accepted),
  191. MACROSTR(Unknown)
  192. };
  193. static char *GetCompositeScheduleStatusStr[] = {
  194. MACROSTR(Accepted),
  195. MACROSTR(Rejected)
  196. };
  197. static char *UpdateTypeStr[] = {
  198. MACROSTR(Differential),
  199. MACROSTR(Full)
  200. };
  201. static char *UpdateStatusStr[] = {
  202. MACROSTR(Accepted),
  203. MACROSTR(Failed),
  204. MACROSTR(NotSupported),
  205. MACROSTR(VersionMismatch)
  206. };
  207. static char *RemoteStartStopStatusStr[] = {
  208. MACROSTR(Accepted),
  209. MACROSTR(Rejected)
  210. };
  211. static char *ReservationStatusStr[] = {
  212. MACROSTR(Accepted),
  213. MACROSTR(Faulted),
  214. MACROSTR(Occupied),
  215. MACROSTR(Rejected),
  216. MACROSTR(Unavailable)
  217. };
  218. static char *ResetTypeStr[] = {
  219. MACROSTR(Hard),
  220. MACROSTR(Soft)
  221. };
  222. static char *ResetStatusStr[] = {
  223. MACROSTR(Accepted),
  224. MACROSTR(Rejected)
  225. };
  226. static char * DiagnosticsStatusStr[] = {
  227. MACROSTR(Idle),
  228. MACROSTR(Uploaded),
  229. MACROSTR(UploadFailed),
  230. MACROSTR(Uploading)
  231. };
  232. static char * FirmwareStatusStr[] = {
  233. MACROSTR(Downloaded),
  234. MACROSTR(DownloadFailed),
  235. MACROSTR(Downloading),
  236. MACROSTR(Idle),
  237. MACROSTR(InstallationFailed),
  238. MACROSTR(Installing),
  239. MACROSTR(Installed)
  240. };
  241. static char * MessageTriggerStr[] = {
  242. MACROSTR(BootNotification),
  243. MACROSTR(DiagnosticsStatusNotification),
  244. MACROSTR(FirmwareStatusNotification),
  245. MACROSTR(Heartbeat),
  246. MACROSTR(MeterValues),
  247. MACROSTR(StatusNotification)
  248. };
  249. static char * TriggerMessageStatusStr[] = {
  250. MACROSTR(Accepted),
  251. MACROSTR(Rejected),
  252. MACROSTR(NotImplemented)
  253. };
  254. static char * UnlockStatusStr[] = {
  255. MACROSTR(Unlocked),
  256. MACROSTR(UnlockFailed),
  257. MACROSTR(NotSupported)
  258. };
  259. #if 0
  260. static char * StopTransactionReasonStr[] = {
  261. MACROSTR(EmergencyStop),
  262. MACROSTR(EVDisconnected),
  263. MACROSTR(HardReset),
  264. MACROSTR(Local),
  265. MACROSTR(Other),
  266. MACROSTR(PowerLoss),
  267. MACROSTR(Reboot),
  268. MACROSTR(Remote),
  269. MACROSTR(SoftReset),
  270. MACROSTR(UnlockCommand),
  271. MACROSTR(DeAuthorized)
  272. };
  273. #endif
  274. static char * CancelReservationStatusStr[] = {
  275. MACROSTR(Accepted),
  276. MACROSTR(Rejected)
  277. };
  278. static char * ReadingContextStr[] = {
  279. MACROSTR(Interruption.Begin),
  280. MACROSTR(Interruption.End),
  281. MACROSTR(Other),
  282. MACROSTR(Sample.Clock),
  283. MACROSTR(Sample.Periodic),
  284. MACROSTR(Transaction.Begin),
  285. MACROSTR(Transaction.End),
  286. MACROSTR(Trigger)
  287. };
  288. static char * ValueFormatStr[] = {
  289. MACROSTR(Raw),
  290. MACROSTR(SignedData)
  291. };
  292. static char * MeasurandStr[] = {
  293. MACROSTR(Current.Export),
  294. MACROSTR(Current.Import),
  295. MACROSTR(Current.Offered),
  296. MACROSTR(Energy.Active.Export.Register),
  297. MACROSTR(Energy.Active.Import.Register),
  298. MACROSTR(Energy.Reactive.Export.Register),
  299. MACROSTR(Energy.Reactive.Import.Register),
  300. MACROSTR(Energy.Active.Export.Interval),
  301. MACROSTR(Energy.Active.Import.Interval),
  302. MACROSTR(Energy.Reactive.Export.Interval),
  303. MACROSTR(Energy.Reactive.Import.Interval),
  304. MACROSTR(Frequency),
  305. MACROSTR(Power.Active.Export),
  306. MACROSTR(Power.Active.Import),
  307. MACROSTR(Power.Factor),
  308. MACROSTR(Power.Offered),
  309. MACROSTR(Power.Reactive.ExportMACROSTR),
  310. MACROSTR(Power.Reactive.Import),
  311. MACROSTR(RPM),
  312. MACROSTR(SoC),
  313. MACROSTR(Temperature),
  314. MACROSTR(Voltage)
  315. };
  316. static char * LocationStr[] = {
  317. MACROSTR(Body),
  318. MACROSTR(Cable),
  319. MACROSTR(EV),
  320. MACROSTR(Inlet),
  321. MACROSTR(Outlet)
  322. };
  323. static char * PhaseStr[] = {
  324. MACROSTR(L1),
  325. MACROSTR(L2),
  326. MACROSTR(L3),
  327. MACROSTR(N),
  328. MACROSTR(L1-N),
  329. MACROSTR(L2-N),
  330. MACROSTR(L3-N),
  331. MACROSTR(L1-L2),
  332. MACROSTR(L2-L3),
  333. MACROSTR(L3-L1)
  334. };
  335. static char * UnitOfMeasureStr[] = {
  336. MACROSTR(Wh),
  337. MACROSTR(kWh),
  338. MACROSTR(varh),
  339. MACROSTR(kvarh),
  340. MACROSTR(W),
  341. MACROSTR(kW),
  342. MACROSTR(VA),
  343. MACROSTR(kVA),
  344. MACROSTR(var),
  345. MACROSTR(kvar),
  346. MACROSTR(A),
  347. MACROSTR(V),
  348. MACROSTR(Celsius),
  349. MACROSTR(Fahrenheit),
  350. MACROSTR(K),
  351. MACROSTR(Percent)
  352. };
  353. //=========================================
  354. // Sqlite3 related function
  355. //=========================================
  356. static int selectSqlCount = 0;
  357. static int callback(void *data, int argc, char **argv, char **azColName){
  358. int i;
  359. //printf("%s: ", (const char*)data);
  360. selectSqlCount = argc;
  361. for(i = 0; i<argc; i++){
  362. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  363. }
  364. //printf("\n");
  365. return 0;
  366. }
  367. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  368. //int i;
  369. //printf("%s:\n", (const char*)data);
  370. localversion = argv[5] ? atoi(argv[5]) : 0;
  371. //printf("localversion=%d\n", localversion);
  372. return 0;
  373. }
  374. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  375. //printf("%s:\n", (const char*)data);
  376. //idTag
  377. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  378. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  379. //parentIdTag
  380. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  381. //expir_date
  382. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  383. //status
  384. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  385. //version
  386. if(columenCount > 5)
  387. idTagQuery.listVersionInt = atoi(columnValue[5]);
  388. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  389. return 0;
  390. }
  391. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  392. {
  393. // localversion = argv[5] ? atoi(argv[5]) : 0;
  394. // printf("localversion=%d\n", localversion);
  395. return 0;
  396. }
  397. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  398. {
  399. for (int i = 0; i < n_columns; i++)
  400. {
  401. DEBUG_INFO("%s\t", col_values[i]);
  402. }
  403. DEBUG_INFO("\n");
  404. return 0;
  405. }
  406. int OCPP_cleanLocalCache()
  407. {
  408. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  409. char *errMsg = 0;
  410. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  411. if (SQLITE_OK != rc)
  412. {
  413. DEBUG_INFO("SQL error: %s\n",errMsg);
  414. return FALSE;
  415. }
  416. return TRUE;
  417. }
  418. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  419. {
  420. int isSuccess = TRUE;
  421. int ret = 0;
  422. //const char* data = "Callback function called";
  423. char sql[300];
  424. char zErrMsg[200];
  425. memset(sql, 0, 300);
  426. memset(zErrMsg, 0, 200);
  427. sprintf(sql, "insert or replace into ocpp_auth_cache (idtag, parent_idtag, expir_date, status) " "VALUES ('%s', '%s', '%s', '%s'); ""SELECT * from ocpp_auth_cache", idTag, parentTage, expiryDate, status);
  428. //* Execute SQL statement */
  429. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  430. if( ret != SQLITE_OK )
  431. {
  432. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  433. isSuccess = FALSE;
  434. }
  435. return isSuccess;
  436. }
  437. void OCPP_getIdTagFromLocalCache(char idTag[])
  438. {
  439. int rc = 0;
  440. char sql[100];
  441. char zErrMsg[100];
  442. memset(sql, 0, 100);
  443. memset(zErrMsg, 0, 100);
  444. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  445. memset(&idTagQuery, 0, sizeof(idTagQuery));
  446. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  447. /* Execute SQL statement */
  448. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  449. if( rc != SQLITE_OK )
  450. {
  451. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  452. }
  453. }
  454. void OCPP_getListVerion()
  455. {
  456. int rc = 0;
  457. // const char* data = "Callback function called";
  458. char sql[100];
  459. char zErrMsg[100];
  460. memset(sql, 0, 100);
  461. memset(zErrMsg, 0, 100);
  462. strcpy(sql, "select * from ocpp_auth_local order by idx");
  463. /* Execute SQL statement */
  464. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  465. if( rc != SQLITE_OK )
  466. {
  467. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  468. }
  469. }
  470. void OCPP_get_TableAuthlocalAllData(void)
  471. {
  472. int rc = 0;
  473. char sql[100];
  474. char zErrMsg[100];
  475. memset(sql, 0, 100);
  476. memset(zErrMsg, 0, 100);
  477. sprintf(sql,"select * from ocpp_auth_local ");
  478. /* Execute SQL statement */
  479. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  480. if( rc != SQLITE_OK )
  481. {
  482. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  483. }
  484. //return ver;
  485. }
  486. int OCPP_cleanLocalList()
  487. {
  488. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  489. char *errMsg = 0;
  490. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  491. if (SQLITE_OK != rc)
  492. {
  493. DEBUG_INFO("%s\n",errMsg);
  494. return FALSE;
  495. }
  496. return TRUE;
  497. }
  498. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  499. {
  500. int isSuccess = FALSE;
  501. int ret = 0;
  502. //const char* data = "Callback function called";
  503. char sql[300];
  504. char zErrMsg[200];
  505. memset(sql, 0, 300);
  506. memset(zErrMsg, 0, 200);
  507. sprintf(sql,"insert or replace into ocpp_auth_local (idtag, parent_idtag, expir_date, status, version) " "VALUES ('%s', '%s', '%s', '%s', %d ); ""SELECT * from ocpp_auth_local", idTag, parentTage, expiryDate, status, version);
  508. //* Execute SQL statement */
  509. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  510. if( ret != SQLITE_OK )
  511. {
  512. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  513. return isSuccess;
  514. }
  515. memset(sql, 0, 300);
  516. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  517. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  518. if( ret != SQLITE_OK )
  519. {
  520. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  521. return isSuccess;
  522. }
  523. isSuccess = TRUE;
  524. return isSuccess;
  525. }
  526. void OCPP_getIdTagFromLocalList(char idTag[])
  527. {
  528. int rc = 0;
  529. // const char* data = "Callback function called";
  530. char sql[100];
  531. char zErrMsg[100];
  532. memset(sql, 0, 100);
  533. memset(zErrMsg, 0, 100);
  534. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  535. memset(&idTagQuery, 0, sizeof(idTagQuery));
  536. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  537. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  538. /* Execute SQL statement */
  539. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  540. if( rc != SQLITE_OK )
  541. {
  542. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  543. }
  544. //return ver;
  545. }
  546. void OCPP_deleteIdTagFromLocalList(char idTag[])
  547. {
  548. //int ver = 0;
  549. //int isSuccess = FALSE;
  550. int rc = 0;
  551. char sql[100];
  552. char zErrMsg[100];
  553. memset(sql, 0, 100);
  554. memset(zErrMsg, 0, 100);
  555. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  556. //* Execute SQL statement */
  557. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  558. if( rc != SQLITE_OK )
  559. {
  560. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  561. }
  562. }
  563. int getCurrentYear()
  564. {
  565. int result = 0;
  566. time_t CurrentTime;
  567. struct tm *tm;
  568. CurrentTime = time(NULL);
  569. tm=localtime(&CurrentTime);
  570. result = (tm->tm_year + 1900);
  571. return result;
  572. }
  573. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  574. {
  575. int result = PASS;
  576. char* errMsg = NULL;
  577. char sqlStr[8192];
  578. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  579. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  580. {
  581. result = FAIL;
  582. DEBUG_INFO( "Insert local transaction record error message: %s\n", errMsg);
  583. }
  584. sprintf(sqlStr, "delete from ocpp_transaction_record where (idx < (select idx from ocpp_transaction_record order by idx desc limit 1)-2000) and (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  585. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  586. {
  587. result = FAIL;
  588. DEBUG_INFO( "delete local transaction record error message: %s\n", errMsg);
  589. }
  590. return result;
  591. }
  592. //==========================================
  593. // Check time passed since today
  594. //==========================================
  595. long long DiffTimebWithNow(struct timeb ST)
  596. {
  597. //return milli-second
  598. struct timeb ET;
  599. long long StartTime,StopTime;
  600. ftime(&ET);
  601. StartTime=(long long)ST.time;
  602. StopTime=(long long)ET.time;
  603. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  604. }
  605. int getTimePassSinceToday()
  606. {
  607. int result = -1;
  608. static time_t lastTime;
  609. time_t t;
  610. struct tm *tmStartToday;
  611. struct timeb tbStartToday;
  612. t=time(NULL);
  613. if(difftime(t, lastTime)>0)
  614. {
  615. tmStartToday=localtime(&t);
  616. tmStartToday->tm_hour = 0;
  617. tmStartToday->tm_min = 0;
  618. tmStartToday->tm_sec = 0;
  619. tbStartToday.time = mktime(tmStartToday);
  620. tbStartToday.millitm = 0;
  621. result = DiffTimebWithNow(tbStartToday)/1000;
  622. lastTime = t;
  623. }
  624. return result;
  625. }
  626. void getNowDatetime(uint8_t *data)
  627. {
  628. time_t t = time(NULL);
  629. struct tm tm = *localtime(&t);
  630. sprintf((char*)data, "%04d-%02d-%02dT%02d:%02d:%02dZ", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
  631. }
  632. int syncDateTimeRTC(uint8_t *data)
  633. {
  634. struct ParsingResult
  635. {
  636. int result;
  637. int scanedElement;
  638. int year;
  639. int month;
  640. int mday;
  641. int hour;
  642. int min;
  643. int sec;
  644. int tz_hour;
  645. int tz_min;
  646. float minSec;
  647. }result;
  648. struct tm tmOrg;
  649. struct tm *tmTarget;
  650. struct timeb tbTarget;
  651. char buf[128];
  652. memset(&result, 0x00, sizeof(struct ParsingResult));
  653. result.result = PASS;
  654. if(strstr((char*)data, ".") != NULL)
  655. {
  656. // Original data with mini second
  657. if(strstr((char*)data, "Z") != NULL)
  658. {
  659. // Original data with Z
  660. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  661. &result.year,
  662. &result.month,
  663. &result.mday,
  664. &result.hour,
  665. &result.min,
  666. &result.sec,
  667. &result.minSec);
  668. }
  669. else
  670. {
  671. // Original data without Z
  672. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  673. &result.year,
  674. &result.month,
  675. &result.mday,
  676. &result.hour,
  677. &result.min,
  678. &result.sec,
  679. &result.minSec,
  680. &result.tz_hour,
  681. &result.tz_min);
  682. }
  683. }
  684. else
  685. {
  686. // Original data without mini second
  687. if(strstr((char*)data, "Z") != NULL)
  688. {
  689. // Original data with Z
  690. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  691. &result.year,
  692. &result.month,
  693. &result.mday,
  694. &result.hour,
  695. &result.min,
  696. &result.sec);
  697. }
  698. else
  699. {
  700. // Original data without Z
  701. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  702. &result.year,
  703. &result.month,
  704. &result.mday,
  705. &result.hour,
  706. &result.min,
  707. &result.sec,
  708. &result.tz_hour,
  709. &result.tz_min);
  710. }
  711. }
  712. tmOrg.tm_year = result.year - 1900;
  713. tmOrg.tm_mon = result.month - 1;
  714. tmOrg.tm_mday = result.mday;
  715. tmOrg.tm_hour = result.hour;
  716. tmOrg.tm_min = result.min;
  717. tmOrg.tm_sec = result.sec;
  718. tmOrg.tm_gmtoff = 0;
  719. tbTarget.time = mktime(&tmOrg);
  720. tbTarget.timezone = 0;
  721. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  722. tmTarget = gmtime(&tbTarget.time);
  723. sprintf(buf, "date -s '%04d-%02d-%02d %02d:%02d:%02d'", (tmTarget->tm_year+1900), (tmTarget->tm_mon+1), tmTarget->tm_mday, tmTarget->tm_hour, tmTarget->tm_min, tmTarget->tm_sec);
  724. //DEBUG_INFO(" org date time: %s\n", data);
  725. //DEBUG_INFO("parse date time: %s\n", buf);
  726. system(buf);
  727. system("/sbin/hwclock -w --systohc");
  728. if(result.scanedElement < 6)
  729. result.result = FAIL;
  730. return result.result;
  731. }
  732. //==========================================
  733. // GetCompositeSchedule logic related function
  734. //==========================================
  735. int DiffTimebSec(struct timeb ST, struct timeb ET)
  736. {
  737. //return milli-second
  738. unsigned int StartTime,StopTime;
  739. StartTime=(unsigned int)ST.time;
  740. StopTime=(unsigned int)ET.time;
  741. return (StopTime-StartTime);
  742. }
  743. int DiffTimebWithNowSec(struct timeb ST)
  744. {
  745. //return milli-second
  746. struct timeb ET;
  747. unsigned int StartTime,StopTime;
  748. ftime(&ET);
  749. StartTime=(unsigned int)ST.time;
  750. StopTime=(unsigned int)ET.time;
  751. return (StopTime-StartTime);
  752. }
  753. int getStartStop(uint8_t *start, uint8_t *stop)
  754. {
  755. int result = -1;
  756. struct tm tmStart;
  757. struct timeb tbStart;
  758. struct tm tmStop;
  759. struct timeb tbStop;
  760. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  761. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  762. {
  763. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  764. //DEBUG_INFO("Stop: %d-%d-%d %d:%d:%d\n", tmStop.tm_year, tmStop.tm_mon, tmStop.tm_mday, tmStop.tm_hour, tmStop.tm_min, tmStop.tm_sec);
  765. tmStart.tm_year -= 1900;
  766. tmStart.tm_mon -= 1;
  767. tbStart.time = mktime(&tmStart);
  768. tbStart.millitm = 0;
  769. tmStop.tm_year -= 1900;
  770. tmStop.tm_mon -= 1;
  771. tbStop.time = mktime(&tmStop);
  772. tbStop.millitm = 0;
  773. result = DiffTimebSec(tbStart, tbStop);
  774. //DEBUG_INFO("getStartStop(): %d\n", result);
  775. }
  776. else
  777. {
  778. DEBUG_WARN("Start or stop date parsing error.\r\n");
  779. }
  780. return result;
  781. }
  782. int isOvertNow(uint8_t *start)
  783. {
  784. int result = NO;
  785. struct tm tmStart;
  786. struct timeb tbStart;
  787. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6))
  788. {
  789. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  790. tmStart.tm_year -= 1900;
  791. tmStart.tm_mon -= 1;
  792. tbStart.time = mktime(&tmStart);
  793. tbStart.millitm = 0;
  794. if(DiffTimebWithNowSec(tbStart) <= 0)
  795. result = NO;
  796. else
  797. result = YES;
  798. }
  799. else
  800. {
  801. DEBUG_WARN("Start date parsing error.\n");
  802. }
  803. return result;
  804. }
  805. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  806. {
  807. int result = -1;
  808. struct tm tmStart;
  809. struct timeb tbStart;
  810. struct tm tmStop;
  811. struct timeb tbStop;
  812. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  813. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  814. {
  815. tmStart.tm_year -= 1900;
  816. tmStart.tm_mon -= 1;
  817. tbStart.time = mktime(&tmStart);
  818. tbStart.millitm = 0;
  819. tmStop.tm_year -= 1900;
  820. tmStop.tm_mon -= 1;
  821. tbStop.time = mktime(&tmStop);
  822. tbStop.millitm = 0;
  823. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  824. }
  825. return result;
  826. }
  827. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  828. {
  829. FILE *fp;
  830. char profileFileName[128];
  831. char *line = NULL;
  832. size_t len = 0;
  833. time_t CurrentTime;
  834. struct tm *tmComposite;
  835. struct StructChargingProfile maxProfile;
  836. struct StructChargingProfile defaultTxProfile;
  837. struct StructChargingProfile txProfile;
  838. struct StructChargingSchedulePeriod tmpPeriod;
  839. uint8_t limitMax=0;
  840. uint8_t limitDef=0;
  841. uint8_t limitTx=0;
  842. int compositePeriodIdx = 0;
  843. CurrentTime = time(NULL);
  844. tmComposite=localtime(&CurrentTime);
  845. sprintf((char*)compositeProfile->ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec);
  846. if(isUnitA)
  847. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  848. else
  849. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  850. compositeProfile->ChargingSchedule.Duration = durationReq;
  851. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  852. {
  853. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  854. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  855. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  856. }
  857. compositeProfile->ChargingProfileId = 0;
  858. compositeProfile->StackLevel = 99 ;
  859. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  860. maxProfile.ChargingProfileId = -1;
  861. defaultTxProfile.ChargingProfileId = -1;
  862. txProfile.ChargingProfileId = -1;
  863. maxProfile.ChargingSchedule.Duration = -1;
  864. defaultTxProfile.ChargingSchedule.Duration = -1;
  865. txProfile.ChargingSchedule.Duration = -1;
  866. system("yes|rm /tmp/*.json");
  867. system("cp /Storage/OCPP/*.json /tmp");
  868. /*
  869. * Search valid charging profile
  870. */
  871. //DEBUG_INFO("====================================\n");
  872. // Search tx profile
  873. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  874. if((access(profileFileName, F_OK))!=-1)
  875. {
  876. fp = fopen(profileFileName, "r");
  877. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  878. {
  879. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  880. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  881. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  882. }
  883. txProfile.ChargingProfileId = -1;
  884. txProfile.StackLevel = -1;
  885. while(getline(&line, &len, fp) != -1)
  886. {
  887. json_object *obj = NULL;
  888. obj = json_tokener_parse(line);
  889. if(is_error(obj))
  890. {
  891. DEBUG_ERROR("Parse txProfile from file error.\n");
  892. }
  893. else
  894. {
  895. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  896. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  897. )
  898. {
  899. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  900. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  901. )
  902. {
  903. struct tm tmFrom, tmTo;
  904. struct timeb tbFrom, tbTo;
  905. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  906. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  907. {
  908. tmFrom.tm_year -= 1900;
  909. tmFrom.tm_mon -= 1;
  910. tbFrom.time = mktime(&tmFrom);
  911. tmTo.tm_year -= 1900;
  912. tmTo.tm_mon -= 1;
  913. tbTo.time = mktime(&tmTo);
  914. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  915. {
  916. if(txProfile.ChargingProfileId == -1)
  917. DEBUG_INFO("TxProfile found.\n");
  918. else
  919. DEBUG_INFO("TxProfile updated.\n");
  920. // Required item
  921. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  922. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  923. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  924. if(isUnitA)
  925. {
  926. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  927. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  928. {
  929. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  930. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  931. 3:
  932. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  933. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  934. }
  935. }
  936. else
  937. {
  938. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  939. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  940. {
  941. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  942. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  943. 3:
  944. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  945. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  946. }
  947. }
  948. // Optional item
  949. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  950. {
  951. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  952. }
  953. else
  954. {
  955. sprintf((char*)txProfile.ValidFrom, " ");
  956. }
  957. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  958. {
  959. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  960. }
  961. else
  962. {
  963. sprintf((char*)txProfile.ValidTo, " ");
  964. }
  965. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  966. {
  967. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  968. }
  969. else
  970. {
  971. sprintf((char*)txProfile.RecurrencyKind, " ");
  972. }
  973. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  974. {
  975. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  976. }
  977. else
  978. {
  979. txProfile.TransactionId = -1;
  980. }
  981. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  982. {
  983. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  984. }
  985. else
  986. {
  987. txProfile.ChargingSchedule.Duration = 86400;
  988. }
  989. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  990. {
  991. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  992. }
  993. else
  994. {
  995. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  996. }
  997. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  998. {
  999. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1000. }
  1001. else
  1002. {
  1003. txProfile.ChargingSchedule.MinChargingRate = -1;
  1004. }
  1005. }
  1006. }
  1007. }
  1008. else
  1009. {
  1010. if(txProfile.ChargingProfileId == -1)
  1011. DEBUG_INFO("TxProfile found.\n");
  1012. else
  1013. DEBUG_INFO("TxProfile updated.\n");
  1014. // Required item
  1015. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1016. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1017. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1018. if(isUnitA)
  1019. {
  1020. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1021. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1022. {
  1023. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1024. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1025. 3:
  1026. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1027. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1028. }
  1029. }
  1030. else
  1031. {
  1032. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1033. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1034. {
  1035. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1036. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1037. 3:
  1038. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1039. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1040. }
  1041. }
  1042. // Optional item
  1043. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1044. {
  1045. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1046. }
  1047. else
  1048. {
  1049. sprintf((char*)txProfile.ValidFrom, " ");
  1050. }
  1051. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1052. {
  1053. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1054. }
  1055. else
  1056. {
  1057. sprintf((char*)txProfile.ValidTo, " ");
  1058. }
  1059. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1060. {
  1061. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1062. }
  1063. else
  1064. {
  1065. sprintf((char*)txProfile.RecurrencyKind, " ");
  1066. }
  1067. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1068. {
  1069. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1070. }
  1071. else
  1072. {
  1073. txProfile.TransactionId = -1;
  1074. }
  1075. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1076. {
  1077. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1078. }
  1079. else
  1080. {
  1081. txProfile.ChargingSchedule.Duration = 86400;
  1082. }
  1083. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1084. {
  1085. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1086. }
  1087. else
  1088. {
  1089. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1090. }
  1091. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1092. {
  1093. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1094. }
  1095. else
  1096. {
  1097. txProfile.ChargingSchedule.MinChargingRate = -1;
  1098. }
  1099. }
  1100. }
  1101. }
  1102. json_object_put(obj);
  1103. }
  1104. fclose(fp);
  1105. /*
  1106. if(txProfile.ChargingProfileId != -1)
  1107. {
  1108. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1109. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1110. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1111. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1112. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1113. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1114. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1115. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1116. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1117. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1118. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1119. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1120. {
  1121. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1122. {
  1123. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1124. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1125. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1126. }
  1127. }
  1128. }
  1129. else
  1130. DEBUG_INFO("TxProfile not found.\n");*/
  1131. }
  1132. // Search default tx profile
  1133. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1134. if((access(profileFileName, F_OK))==-1)
  1135. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1136. if((access(profileFileName, F_OK))!=-1)
  1137. {
  1138. fp = fopen(profileFileName, "r");
  1139. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1140. {
  1141. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1142. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1143. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1144. }
  1145. defaultTxProfile.ChargingProfileId = -1;
  1146. defaultTxProfile.StackLevel = -1;
  1147. while(getline(&line, &len, fp) != -1)
  1148. {
  1149. json_object *obj = NULL;
  1150. obj = json_tokener_parse(line);
  1151. if(is_error(obj))
  1152. {
  1153. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1154. }
  1155. else
  1156. {
  1157. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1158. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1159. )
  1160. {
  1161. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1162. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1163. )
  1164. {
  1165. struct tm tmFrom, tmTo;
  1166. struct timeb tbFrom, tbTo;
  1167. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  1168. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  1169. {
  1170. tmFrom.tm_year -= 1900;
  1171. tmFrom.tm_mon -= 1;
  1172. tbFrom.time = mktime(&tmFrom);
  1173. tmTo.tm_year -= 1900;
  1174. tmTo.tm_mon -= 1;
  1175. tbTo.time = mktime(&tmTo);
  1176. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1177. {
  1178. if(defaultTxProfile.ChargingProfileId == -1)
  1179. DEBUG_INFO("TxDefaultProfile found.\n");
  1180. else
  1181. DEBUG_INFO("TxDefaultProfile updated.\n");
  1182. // Required item
  1183. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1184. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1185. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1186. if(isUnitA)
  1187. {
  1188. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1189. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1190. {
  1191. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1192. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1193. 3:
  1194. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1195. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1196. }
  1197. }
  1198. else
  1199. {
  1200. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1201. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1202. {
  1203. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1204. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1205. 3:
  1206. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1207. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1208. }
  1209. }
  1210. // Optional item
  1211. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1212. {
  1213. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1214. }
  1215. else
  1216. {
  1217. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1218. }
  1219. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1220. {
  1221. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1222. }
  1223. else
  1224. {
  1225. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1226. }
  1227. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1228. {
  1229. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1230. }
  1231. else
  1232. {
  1233. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1234. }
  1235. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1236. {
  1237. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1238. }
  1239. else
  1240. {
  1241. defaultTxProfile.TransactionId = -1;
  1242. }
  1243. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1244. {
  1245. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1246. }
  1247. else
  1248. {
  1249. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1250. }
  1251. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1252. {
  1253. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1254. }
  1255. else
  1256. {
  1257. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1258. }
  1259. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1260. {
  1261. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1262. }
  1263. else
  1264. {
  1265. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1266. }
  1267. }
  1268. }
  1269. }
  1270. else
  1271. {
  1272. if(defaultTxProfile.ChargingProfileId == -1)
  1273. DEBUG_INFO("TxDefaultProfile found.\n");
  1274. else
  1275. DEBUG_INFO("TxDefaultProfile updated.\n");
  1276. // Required item
  1277. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1278. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1279. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1280. if(isUnitA)
  1281. {
  1282. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1283. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1284. {
  1285. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1286. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1287. 3:
  1288. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1289. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1290. }
  1291. }
  1292. else
  1293. {
  1294. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1295. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1296. {
  1297. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1298. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1299. 3:
  1300. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1301. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1302. }
  1303. }
  1304. // Optional item
  1305. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1306. {
  1307. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1308. }
  1309. else
  1310. {
  1311. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1312. }
  1313. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1314. {
  1315. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1316. }
  1317. else
  1318. {
  1319. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1320. }
  1321. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1322. {
  1323. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1324. }
  1325. else
  1326. {
  1327. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1328. }
  1329. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1330. {
  1331. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1332. }
  1333. else
  1334. {
  1335. defaultTxProfile.TransactionId = -1;
  1336. }
  1337. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1338. {
  1339. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1340. }
  1341. else
  1342. {
  1343. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1344. }
  1345. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1346. {
  1347. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1348. }
  1349. else
  1350. {
  1351. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1352. }
  1353. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1354. {
  1355. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1356. }
  1357. else
  1358. {
  1359. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1360. }
  1361. }
  1362. }
  1363. }
  1364. json_object_put(obj);
  1365. }
  1366. fclose(fp);
  1367. /*
  1368. if(defaultTxProfile.ChargingProfileId != -1)
  1369. {
  1370. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1371. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1372. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1373. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1374. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1375. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1376. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1377. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  1378. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1379. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1380. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1381. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1382. {
  1383. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1384. {
  1385. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1386. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1387. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1388. }
  1389. }
  1390. }
  1391. else
  1392. DEBUG_INFO("TxDefaultProfile not found.\n");
  1393. DEBUG_INFO("------------------------------------\n");*/
  1394. }
  1395. // Search max profile
  1396. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1397. if((access(profileFileName, F_OK))!=-1)
  1398. {
  1399. fp = fopen(profileFileName, "r");
  1400. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1401. {
  1402. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1403. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1404. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1405. }
  1406. maxProfile.ChargingProfileId = -1;
  1407. maxProfile.StackLevel = -1;
  1408. while(getline(&line, &len, fp) != -1)
  1409. {
  1410. json_object *obj = NULL;
  1411. obj = json_tokener_parse(line);
  1412. if(is_error(obj))
  1413. {
  1414. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1415. }
  1416. else
  1417. {
  1418. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  1419. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1420. )
  1421. {
  1422. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1423. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1424. )
  1425. {
  1426. struct tm tmFrom, tmTo;
  1427. struct timeb tbFrom, tbTo;
  1428. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  1429. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  1430. {
  1431. tmFrom.tm_year -= 1900;
  1432. tmFrom.tm_mon -= 1;
  1433. tbFrom.time = mktime(&tmFrom);
  1434. tmTo.tm_year -= 1900;
  1435. tmTo.tm_mon -= 1;
  1436. tbTo.time = mktime(&tmTo);
  1437. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1438. {
  1439. if(maxProfile.ChargingProfileId == -1)
  1440. DEBUG_INFO("MaxProfile found.\n");
  1441. else
  1442. DEBUG_INFO("MaxProfile updated.\n");
  1443. // Required item
  1444. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1445. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1446. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1447. if(isUnitA)
  1448. {
  1449. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1450. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1451. {
  1452. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1453. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1454. 3:
  1455. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1456. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1457. }
  1458. }
  1459. else
  1460. {
  1461. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1462. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1463. {
  1464. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1465. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1466. 3:
  1467. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1468. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1469. }
  1470. }
  1471. // Optional item
  1472. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1473. {
  1474. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1475. }
  1476. else
  1477. {
  1478. sprintf((char*)maxProfile.ValidFrom, " ");
  1479. }
  1480. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1481. {
  1482. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1483. }
  1484. else
  1485. {
  1486. sprintf((char*)maxProfile.ValidTo, " ");
  1487. }
  1488. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1489. {
  1490. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1491. }
  1492. else
  1493. {
  1494. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1495. }
  1496. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1497. {
  1498. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1499. }
  1500. else
  1501. {
  1502. maxProfile.TransactionId = -1;
  1503. }
  1504. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1505. {
  1506. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1507. }
  1508. else
  1509. {
  1510. maxProfile.ChargingSchedule.Duration = 86400;
  1511. }
  1512. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1513. {
  1514. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1515. }
  1516. else
  1517. {
  1518. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1519. }
  1520. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1521. {
  1522. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1523. }
  1524. else
  1525. {
  1526. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1527. }
  1528. }
  1529. }
  1530. }
  1531. else
  1532. {
  1533. if(maxProfile.ChargingProfileId == -1)
  1534. DEBUG_INFO("MaxProfile found.\n");
  1535. else
  1536. DEBUG_INFO("MaxProfile updated.\n");
  1537. // Required item
  1538. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1539. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1540. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1541. if(isUnitA)
  1542. {
  1543. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1544. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1545. {
  1546. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1547. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1548. 3:
  1549. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1550. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1551. }
  1552. }
  1553. else
  1554. {
  1555. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1556. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1557. {
  1558. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1559. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1560. 3:
  1561. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1562. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1563. }
  1564. }
  1565. // Optional item
  1566. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1567. {
  1568. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1569. }
  1570. else
  1571. {
  1572. sprintf((char*)maxProfile.ValidFrom, " ");
  1573. }
  1574. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1575. {
  1576. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1577. }
  1578. else
  1579. {
  1580. sprintf((char*)maxProfile.ValidTo, " ");
  1581. }
  1582. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1583. {
  1584. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1585. }
  1586. else
  1587. {
  1588. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1589. }
  1590. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1591. {
  1592. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1593. }
  1594. else
  1595. {
  1596. maxProfile.TransactionId = -1;
  1597. }
  1598. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1599. {
  1600. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1601. }
  1602. else
  1603. {
  1604. maxProfile.ChargingSchedule.Duration = 86400;
  1605. }
  1606. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1607. {
  1608. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1609. }
  1610. else
  1611. {
  1612. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1613. }
  1614. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1615. {
  1616. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1617. }
  1618. else
  1619. {
  1620. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1621. }
  1622. }
  1623. }
  1624. }
  1625. json_object_put(obj);
  1626. }
  1627. fclose(fp);
  1628. /*
  1629. if(maxProfile.ChargingProfileId !=-1)
  1630. {
  1631. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1632. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1633. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1634. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1635. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1636. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1637. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1638. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1639. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1640. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1641. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1642. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1643. {
  1644. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1645. {
  1646. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1647. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1648. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1649. }
  1650. }
  1651. }
  1652. else
  1653. DEBUG_INFO("MaxProfile not found.\n");
  1654. DEBUG_INFO("------------------------------------\n");*/
  1655. }
  1656. /*
  1657. * Align found profile start schedule & periods
  1658. */
  1659. //DEBUG_INFO("====================================\n");
  1660. /*
  1661. // For local test usage, force modify found profile start schedule info
  1662. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-10);
  1663. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-5);
  1664. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-3);
  1665. */
  1666. if(txProfile.ChargingProfileId != -1)
  1667. {
  1668. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  1669. {
  1670. if(txProfile.ChargingSchedule.Duration != -1)
  1671. {
  1672. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1673. 0:
  1674. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1675. }
  1676. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1677. {
  1678. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1679. {
  1680. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1681. 0:
  1682. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1683. if(idxPeriod > 0)
  1684. {
  1685. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1686. {
  1687. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1688. }
  1689. }
  1690. }
  1691. }
  1692. }
  1693. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  1694. {
  1695. if(txProfile.ChargingSchedule.Duration != -1)
  1696. {
  1697. txProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?txProfile.ChargingSchedule.Duration:((txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1698. 0:
  1699. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1700. }
  1701. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1702. {
  1703. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1704. {
  1705. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1706. 0:
  1707. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1708. if(idxPeriod > 0)
  1709. {
  1710. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1711. {
  1712. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1713. }
  1714. }
  1715. }
  1716. }
  1717. }
  1718. else
  1719. {
  1720. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  1721. {
  1722. if(txProfile.ChargingSchedule.Duration != -1)
  1723. {
  1724. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1725. 0:
  1726. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1727. }
  1728. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1729. {
  1730. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1731. {
  1732. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1733. 0:
  1734. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1735. if(idxPeriod > 0)
  1736. {
  1737. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1738. {
  1739. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1740. }
  1741. }
  1742. }
  1743. }
  1744. }
  1745. else
  1746. {
  1747. if(txProfile.ChargingSchedule.Duration != -1)
  1748. {
  1749. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1750. 0:
  1751. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1752. }
  1753. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1754. {
  1755. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1756. {
  1757. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1758. 0:
  1759. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1760. if(idxPeriod > 0)
  1761. {
  1762. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1763. {
  1764. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1765. }
  1766. }
  1767. }
  1768. }
  1769. }
  1770. }
  1771. /*
  1772. DEBUG_INFO("txProfile after align.\n");
  1773. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1774. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1775. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1776. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1777. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1778. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1779. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1780. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1781. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1782. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1783. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1784. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1785. {
  1786. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1787. {
  1788. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1789. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1790. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1791. }
  1792. }*/
  1793. }
  1794. if(defaultTxProfile.ChargingProfileId != -1)
  1795. {
  1796. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  1797. {
  1798. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1799. {
  1800. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1801. 0:
  1802. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1803. }
  1804. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1805. {
  1806. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1807. {
  1808. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1809. 0:
  1810. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1811. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1812. {
  1813. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1814. }
  1815. if(idxPeriod > 0)
  1816. {
  1817. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1818. {
  1819. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1820. }
  1821. }
  1822. }
  1823. }
  1824. }
  1825. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  1826. {
  1827. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1828. {
  1829. defaultTxProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?defaultTxProfile.ChargingSchedule.Duration:((defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1830. 0:
  1831. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1832. }
  1833. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1834. {
  1835. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1836. {
  1837. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1838. 0:
  1839. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1840. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1841. {
  1842. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1843. }
  1844. if(idxPeriod > 0)
  1845. {
  1846. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1847. {
  1848. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1849. }
  1850. }
  1851. }
  1852. }
  1853. }
  1854. else
  1855. {
  1856. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  1857. {
  1858. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1859. {
  1860. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1861. 0:
  1862. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1863. }
  1864. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1865. {
  1866. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1867. {
  1868. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1869. 0:
  1870. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1871. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1872. {
  1873. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1874. }
  1875. if(idxPeriod > 0)
  1876. {
  1877. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1878. {
  1879. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1880. }
  1881. }
  1882. }
  1883. }
  1884. }
  1885. else
  1886. {
  1887. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1888. {
  1889. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1890. 0:
  1891. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1892. }
  1893. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1894. {
  1895. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1896. {
  1897. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1898. 0:
  1899. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1900. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1901. {
  1902. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1903. }
  1904. if(idxPeriod > 0)
  1905. {
  1906. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1907. {
  1908. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1909. }
  1910. }
  1911. }
  1912. }
  1913. }
  1914. }
  1915. /*
  1916. DEBUG_INFO("defaultTxProfile after align.\n");
  1917. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1918. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1919. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1920. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1921. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1922. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1923. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1924. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1925. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1926. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1927. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1928. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1929. {
  1930. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1931. {
  1932. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1933. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1934. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1935. }
  1936. }
  1937. DEBUG_INFO("------------------------------------\n");*/
  1938. }
  1939. if(maxProfile.ChargingProfileId != -1)
  1940. {
  1941. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1942. {
  1943. if(maxProfile.ChargingSchedule.Duration != -1)
  1944. {
  1945. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1946. 0:
  1947. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1948. }
  1949. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1950. {
  1951. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1952. {
  1953. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1954. 0:
  1955. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1956. if(idxPeriod > 0)
  1957. {
  1958. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1959. {
  1960. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1961. }
  1962. }
  1963. }
  1964. }
  1965. }
  1966. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1967. {
  1968. if(maxProfile.ChargingSchedule.Duration != -1)
  1969. {
  1970. maxProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?maxProfile.ChargingSchedule.Duration:((maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1971. 0:
  1972. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1973. }
  1974. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1975. {
  1976. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1977. {
  1978. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1979. 0:
  1980. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1981. if(idxPeriod > 0)
  1982. {
  1983. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1984. {
  1985. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1986. }
  1987. }
  1988. }
  1989. }
  1990. }
  1991. else
  1992. {
  1993. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1994. {
  1995. if(maxProfile.ChargingSchedule.Duration != -1)
  1996. {
  1997. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1998. 0:
  1999. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2000. }
  2001. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2002. {
  2003. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2004. {
  2005. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2006. 0:
  2007. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2008. if(idxPeriod > 0)
  2009. {
  2010. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2011. {
  2012. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2013. }
  2014. }
  2015. }
  2016. }
  2017. }
  2018. else
  2019. {
  2020. if(maxProfile.ChargingSchedule.Duration != -1)
  2021. {
  2022. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2023. 0:
  2024. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2025. }
  2026. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2027. {
  2028. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2029. {
  2030. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2031. 0:
  2032. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2033. if(idxPeriod > 0)
  2034. {
  2035. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2036. {
  2037. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2038. }
  2039. }
  2040. }
  2041. }
  2042. }
  2043. }
  2044. /*
  2045. DEBUG_INFO("MaxProfile after align.\n");
  2046. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2047. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2048. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2049. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2050. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2051. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2052. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2053. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2054. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2055. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2056. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2057. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2058. {
  2059. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2060. {
  2061. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2062. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2063. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2064. }
  2065. }
  2066. DEBUG_INFO("------------------------------------\n");*/
  2067. }
  2068. /*
  2069. * Merge to conposite schedule
  2070. */
  2071. //DEBUG_INFO("====================================\n");
  2072. // Find each profile period quantity
  2073. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2074. {
  2075. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2076. limitMax = idx+1;
  2077. }
  2078. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2079. {
  2080. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2081. limitDef = idx+1;
  2082. }
  2083. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2084. {
  2085. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2086. limitTx = idx+1;
  2087. }
  2088. // TxProfile found, composite schedule based on it
  2089. if(txProfile.ChargingProfileId != -1)
  2090. {
  2091. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2092. {
  2093. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  2094. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  2095. (txProfile.ChargingSchedule.Duration > 0))
  2096. {
  2097. if(maxProfile.ChargingProfileId != -1)
  2098. {
  2099. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2100. {
  2101. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2102. {
  2103. if((maxProfile.ChargingSchedule.Duration > 0))
  2104. {
  2105. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2106. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2107. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2108. }
  2109. else
  2110. {
  2111. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2112. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2113. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2114. }
  2115. }
  2116. if(idxMaxPeriod == (limitMax-1))
  2117. {
  2118. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2119. {
  2120. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2121. {
  2122. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2123. compositePeriodIdx++;
  2124. }
  2125. else
  2126. {
  2127. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2128. }
  2129. }
  2130. }
  2131. }
  2132. }
  2133. else
  2134. {
  2135. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2136. {
  2137. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2138. compositePeriodIdx++;
  2139. }
  2140. else
  2141. {
  2142. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2143. }
  2144. }
  2145. }
  2146. if(idxTxPeriod == (limitTx-1))
  2147. {
  2148. if(defaultTxProfile.ChargingProfileId != -1)
  2149. {
  2150. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2151. {
  2152. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  2153. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2154. (defaultTxProfile.ChargingSchedule.Duration>0))
  2155. {
  2156. if(maxProfile.ChargingProfileId != -1)
  2157. {
  2158. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2159. {
  2160. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2161. {
  2162. if((maxProfile.ChargingSchedule.Duration > 0))
  2163. {
  2164. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2165. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2166. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2167. }
  2168. else
  2169. {
  2170. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2171. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2172. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2173. }
  2174. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2175. {
  2176. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2177. {
  2178. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2179. compositePeriodIdx++;
  2180. }
  2181. else
  2182. {
  2183. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2184. }
  2185. }
  2186. break;
  2187. }
  2188. }
  2189. }
  2190. else
  2191. {
  2192. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2193. {
  2194. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2195. compositePeriodIdx++;
  2196. }
  2197. else
  2198. {
  2199. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2200. }
  2201. }
  2202. }
  2203. }
  2204. }
  2205. }
  2206. }
  2207. }
  2208. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  2209. else if(defaultTxProfile.ChargingProfileId != -1)
  2210. {
  2211. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2212. {
  2213. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  2214. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2215. (defaultTxProfile.ChargingSchedule.Duration > 0))
  2216. {
  2217. if(maxProfile.ChargingProfileId != -1)
  2218. {
  2219. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2220. {
  2221. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2222. {
  2223. if((maxProfile.ChargingSchedule.Duration > 0))
  2224. {
  2225. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2226. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2227. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  2228. }
  2229. else
  2230. {
  2231. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2232. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2233. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2234. }
  2235. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2236. {
  2237. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2238. {
  2239. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2240. compositePeriodIdx++;
  2241. }
  2242. else
  2243. {
  2244. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2245. }
  2246. }
  2247. break;
  2248. }
  2249. }
  2250. }
  2251. else
  2252. {
  2253. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2254. {
  2255. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2256. compositePeriodIdx++;
  2257. }
  2258. else
  2259. {
  2260. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2261. }
  2262. }
  2263. }
  2264. }
  2265. }
  2266. // Fill other period by MaxProfile
  2267. if(maxProfile.ChargingProfileId != -1)
  2268. {
  2269. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2270. {
  2271. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2272. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2273. (maxProfile.ChargingSchedule.Duration > 0))
  2274. {
  2275. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  2276. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2277. {
  2278. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  2279. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  2280. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2281. }
  2282. if((maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2283. {
  2284. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.Duration;
  2285. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  2286. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2287. }
  2288. if(tmpPeriod.Limit != -1)
  2289. {
  2290. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2291. {
  2292. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2293. {
  2294. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2295. compositePeriodIdx++;
  2296. }
  2297. else
  2298. {
  2299. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2300. }
  2301. }
  2302. }
  2303. }
  2304. }
  2305. }
  2306. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  2307. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2308. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  2309. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  2310. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2311. {
  2312. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2313. {
  2314. compositeProfile->ChargingProfileId = 1;
  2315. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2316. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2317. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2318. }
  2319. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2320. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2321. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2322. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2323. }
  2324. if(line)
  2325. free(line);
  2326. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  2327. }
  2328. //==========================================
  2329. // Init all share memory
  2330. //==========================================
  2331. int InitShareMemory()
  2332. {
  2333. int result = PASS;
  2334. int MeterSMId;
  2335. //creat ShmSysConfigAndInfo
  2336. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  2337. {
  2338. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  2339. result = FAIL;
  2340. }
  2341. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2342. {
  2343. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  2344. result = FAIL;
  2345. }
  2346. else
  2347. {}
  2348. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  2349. {
  2350. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  2351. result = FAIL;
  2352. }
  2353. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2354. {
  2355. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  2356. result = FAIL;
  2357. }
  2358. else
  2359. {}
  2360. //creat ShmPsuData
  2361. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  2362. {
  2363. DEBUG_ERROR("shmget ShmPsuData NG\n");
  2364. result = FAIL;
  2365. }
  2366. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2367. {
  2368. DEBUG_ERROR("shmat ShmPsuData NG\n");
  2369. result = FAIL;
  2370. }
  2371. else
  2372. {}
  2373. //creat ShmOCPP16Data
  2374. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  2375. {
  2376. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  2377. result = FAIL;
  2378. }
  2379. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2380. {
  2381. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  2382. result = FAIL;
  2383. }
  2384. else
  2385. {}
  2386. /****************************** For Initial Settings************************************************/
  2387. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  2388. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  2389. // allocate Configuration memory address
  2390. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  2391. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  2392. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  2393. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  2394. //offline MeterValue Interval
  2395. TempMeterValueInterval = 0;
  2396. return result;
  2397. }
  2398. int ProcessShareMemory()
  2399. {
  2400. if(InitShareMemory() == FAIL)
  2401. {
  2402. DEBUG_ERROR("InitShareMemory NG\n");
  2403. if(ShmStatusCodeData!=NULL)
  2404. {
  2405. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  2406. }
  2407. sleep(5);
  2408. return FAIL;
  2409. }
  2410. return PASS;
  2411. }
  2412. void CheckSystemValue(void)
  2413. {
  2414. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  2415. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  2416. char filenmae[100]={0};
  2417. char str[100]={0};
  2418. int tempIndex = 0;
  2419. //===============================
  2420. // send Heartbeat
  2421. //===============================
  2422. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2423. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  2424. {
  2425. clientTime.Heartbeat=time((time_t*)NULL);
  2426. if(server_sign == TRUE)
  2427. {
  2428. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2429. }
  2430. else
  2431. {
  2432. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  2433. }
  2434. }
  2435. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  2436. {
  2437. //parameter for test
  2438. sendHeartbeatRequest(0);
  2439. //==============================================
  2440. // Reset Waiting Time
  2441. //==============================================
  2442. HeartBeatWithNOResponse += 1;
  2443. }
  2444. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  2445. {
  2446. //==========================================
  2447. // csu trigger DataTransferReq
  2448. //==========================================
  2449. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  2450. {
  2451. sendDataTransferRequest(gun_index);
  2452. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  2453. }
  2454. //===============================
  2455. // CSU Trigger Reset Conf
  2456. //===============================
  2457. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  2458. {
  2459. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  2460. }
  2461. //===============================
  2462. // CSU Trigger Authorize Request
  2463. //===============================
  2464. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  2465. {
  2466. sendAuthorizeRequest(0);
  2467. authorizeRetryTimes = authorizeRetryTimes + 1;
  2468. if(authorizeRetryTimes < 3)
  2469. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2470. }
  2471. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  2472. {
  2473. authorizeRetryTimes = 0;
  2474. SetOcppConnStatus(FALSE);
  2475. server_sign = FALSE;
  2476. }
  2477. else if((server_sign == FALSE) && (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0)&& (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1))
  2478. {
  2479. sendAuthorizeRequest(0);
  2480. }
  2481. //==============================================
  2482. // CSU Trigger Smart Charging Profilw
  2483. //==============================================
  2484. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  2485. {
  2486. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  2487. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  2488. }
  2489. //==============================================
  2490. // Charger start transaction
  2491. //==============================================
  2492. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2493. {
  2494. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  2495. sendStartTransactionRequest(gun_index);
  2496. clientTime.StartTransaction = time((time_t*)NULL);
  2497. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2498. storeTempStopTransaction(gun_index);
  2499. }
  2500. //==============================================
  2501. // Charger stop transaction
  2502. //==============================================
  2503. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2504. {
  2505. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2506. sendStopTransactionRequest(gun_index);
  2507. clientTime.StopTransaction = time((time_t*)NULL);
  2508. }
  2509. //==============================================
  2510. // Charger status report
  2511. //==============================================
  2512. //--- Check Mode Change ---//
  2513. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2514. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2515. {
  2516. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2517. {
  2518. tempIndex = ((gun_index==2) ? 1: 0);
  2519. }
  2520. else
  2521. {
  2522. tempIndex = gun_index;
  2523. }
  2524. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2525. {
  2526. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2527. {
  2528. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  2529. {
  2530. // Sent unplug message for California pricing logic
  2531. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  2532. {
  2533. uint8_t ts[20];
  2534. getNowDatetime(ts);
  2535. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2536. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2537. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2538. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2539. }
  2540. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2541. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2542. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2543. statusModeChage[gun_index] = TRUE;
  2544. }
  2545. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2546. {
  2547. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2548. if((access(filenmae,F_OK))!=-1)
  2549. {
  2550. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2551. sprintf(str,"rm -f %s",filenmae);
  2552. system(str);
  2553. }
  2554. }
  2555. #if 1 // for TempStopTransaction
  2556. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2557. {
  2558. checkTempStopTransaction(gun_index);
  2559. }
  2560. #endif
  2561. }
  2562. }
  2563. }
  2564. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2565. {
  2566. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2567. {
  2568. tempIndex = ((gun_index==2) ? 1: 0);
  2569. }
  2570. else
  2571. {
  2572. tempIndex = gun_index;
  2573. }
  2574. for (int index = 0; index < CCS_QUANTITY; index++)
  2575. {
  2576. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2577. {
  2578. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn != CcsPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  2579. {
  2580. // Sent unplug message for California pricing logic
  2581. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  2582. {
  2583. uint8_t ts[20];
  2584. getNowDatetime(ts);
  2585. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2586. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2587. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2588. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2589. }
  2590. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2591. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2592. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2593. statusModeChage[gun_index] = TRUE;
  2594. }
  2595. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2596. {
  2597. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2598. if((access(filenmae,F_OK))!=-1)
  2599. {
  2600. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2601. sprintf(str,"rm -f %s",filenmae);
  2602. system(str);
  2603. }
  2604. }
  2605. #if 1 // for TempStopTransaction
  2606. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2607. {
  2608. checkTempStopTransaction(gun_index);
  2609. }
  2610. #endif
  2611. }
  2612. }
  2613. }
  2614. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2615. {
  2616. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2617. {
  2618. tempIndex = ((gun_index==2) ? 1: 0);
  2619. }
  2620. else
  2621. {
  2622. tempIndex = gun_index;
  2623. }
  2624. for (int index = 0; index < GB_QUANTITY; index++)
  2625. {
  2626. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2627. {
  2628. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  2629. {
  2630. // Sent unplug message for California pricing logic
  2631. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  2632. {
  2633. uint8_t ts[20];
  2634. getNowDatetime(ts);
  2635. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2636. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2637. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2638. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2639. }
  2640. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2641. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2642. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2643. statusModeChage[gun_index] = TRUE;
  2644. }
  2645. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2646. {
  2647. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2648. if((access(filenmae,F_OK))!=-1)
  2649. {
  2650. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2651. sprintf(str,"rm -f %s",filenmae);
  2652. system(str);
  2653. }
  2654. }
  2655. #if 1 // for TempStopTransaction
  2656. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2657. {
  2658. checkTempStopTransaction(gun_index);
  2659. }
  2660. #endif
  2661. }
  2662. }
  2663. }
  2664. else if(gunType[gun_index] == GUN_TYPE_DO)
  2665. {
  2666. tempIndex = gun_index;
  2667. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2668. {
  2669. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2670. {
  2671. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  2672. {
  2673. // Sent unplug message for California pricing logic
  2674. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  2675. {
  2676. uint8_t ts[20];
  2677. getNowDatetime(ts);
  2678. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2679. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2680. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2681. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2682. }
  2683. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  2684. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  2685. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2686. statusModeChage[gun_index] = TRUE;
  2687. }
  2688. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARING))) // complete
  2689. {
  2690. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2691. if((access(filenmae,F_OK))!=-1)
  2692. {
  2693. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2694. sprintf(str,"rm -f %s",filenmae);
  2695. system(str);
  2696. }
  2697. }
  2698. #if 1 // for TempStopTransaction
  2699. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2700. {
  2701. checkTempStopTransaction(gun_index);
  2702. }
  2703. #endif
  2704. }
  2705. }
  2706. }
  2707. else
  2708. {
  2709. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2710. {
  2711. tempIndex = 2;
  2712. }
  2713. else
  2714. {
  2715. tempIndex = gun_index;
  2716. }
  2717. for (int index = 0; index < AC_QUANTITY; index++)
  2718. {
  2719. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2720. {
  2721. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  2722. {
  2723. // Sent unplug message for California pricing logic
  2724. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)
  2725. {
  2726. uint8_t ts[20];
  2727. getNowDatetime(ts);
  2728. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2729. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2730. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2731. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2732. }
  2733. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2734. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2735. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2736. statusModeChage[gun_index] = TRUE;
  2737. }
  2738. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2739. {
  2740. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2741. if((access(filenmae,F_OK))!=-1)
  2742. {
  2743. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2744. sprintf(str,"rm -f %s",filenmae);
  2745. system(str);
  2746. }
  2747. }
  2748. #if 1 // for TempStopTransaction
  2749. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2750. {
  2751. checkTempStopTransaction(gun_index);
  2752. }
  2753. #endif
  2754. }
  2755. }// END
  2756. }
  2757. if(isWebsocketSendable && (server_sign == TRUE) &&
  2758. (
  2759. (statusModeChage[gun_index] == TRUE) ||
  2760. //((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index))) ||
  2761. ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 10))
  2762. )
  2763. )
  2764. {
  2765. if(SystemInitial > 0)
  2766. SystemInitial -= 1;
  2767. sendStatusNotificationRequest(gun_index);
  2768. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2769. statusModeChage[gun_index] = FALSE;
  2770. }
  2771. //==============================================
  2772. // Meter report
  2773. //==============================================
  2774. // Trigger MeterValue
  2775. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  2776. {
  2777. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  2778. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  2779. }
  2780. // ClockAlign MeterValue
  2781. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  2782. {
  2783. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2784. {
  2785. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2786. {
  2787. tempIndex = ((gun_index==2) ? 1: 0);
  2788. }
  2789. else
  2790. {
  2791. tempIndex = gun_index;
  2792. }
  2793. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2794. {
  2795. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2796. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2797. {
  2798. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2799. {
  2800. reqClockAlignMeter[gun_index] = 1;
  2801. }
  2802. }
  2803. }// End for CHAdeMO
  2804. }
  2805. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2806. {
  2807. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2808. {
  2809. tempIndex = ((gun_index==2) ? 1: 0);
  2810. }
  2811. else
  2812. {
  2813. tempIndex = gun_index;
  2814. }
  2815. for (int index = 0; index < CCS_QUANTITY; index++)
  2816. {
  2817. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2818. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2819. {
  2820. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2821. {
  2822. reqClockAlignMeter[gun_index] = 1;
  2823. }
  2824. }
  2825. } // End for CCS
  2826. }
  2827. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2828. {
  2829. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2830. {
  2831. tempIndex = ((gun_index==2) ? 1: 0);
  2832. }
  2833. else
  2834. {
  2835. tempIndex = gun_index;
  2836. }
  2837. for (int index = 0; index < GB_QUANTITY; index++)
  2838. {
  2839. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2840. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2841. {
  2842. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2843. {
  2844. reqClockAlignMeter[gun_index] = 1;
  2845. }
  2846. }
  2847. }// End for GB
  2848. }
  2849. else if(gunType[gun_index] == GUN_TYPE_DO)
  2850. {
  2851. tempIndex = gun_index;
  2852. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2853. {
  2854. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2855. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2856. {
  2857. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_CHARGING)
  2858. {
  2859. reqClockAlignMeter[gun_index] = 1;
  2860. }
  2861. }
  2862. }
  2863. }
  2864. else
  2865. {
  2866. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2867. {
  2868. tempIndex = 2;
  2869. }
  2870. else
  2871. {
  2872. tempIndex = gun_index;
  2873. }
  2874. for (int index = 0; index < AC_QUANTITY; index++)
  2875. {
  2876. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2877. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2878. {
  2879. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2880. {
  2881. reqClockAlignMeter[gun_index] = 1;
  2882. }
  2883. }
  2884. }//End for AC
  2885. }
  2886. if(reqClockAlignMeter[gun_index] == 1)
  2887. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  2888. }
  2889. // Sample period MeterValue
  2890. if((((time((time_t*)NULL) - clientTime.MeterValues[gun_index]) > (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1))))
  2891. {
  2892. //check Transaction active
  2893. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2894. {
  2895. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2896. {
  2897. tempIndex = ((gun_index==2) ? 1: 0);
  2898. }
  2899. else
  2900. {
  2901. tempIndex = gun_index;
  2902. }
  2903. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2904. {
  2905. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2906. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2907. {
  2908. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2909. {
  2910. reqSampleMeter[gun_index] = 1;
  2911. }
  2912. }
  2913. }// End for CHAdeMO
  2914. }
  2915. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2916. {
  2917. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2918. {
  2919. tempIndex = ((gun_index==2) ? 1: 0);
  2920. }
  2921. else
  2922. {
  2923. tempIndex = gun_index;
  2924. }
  2925. for (int index = 0; index < CCS_QUANTITY; index++)
  2926. {
  2927. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2928. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2929. {
  2930. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2931. {
  2932. reqSampleMeter[gun_index] = 1;
  2933. }
  2934. }
  2935. } // End for CCS
  2936. }
  2937. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2938. {
  2939. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2940. {
  2941. tempIndex = ((gun_index==2) ? 1: 0);
  2942. }
  2943. else
  2944. {
  2945. tempIndex = gun_index;
  2946. }
  2947. for (int index = 0; index < GB_QUANTITY; index++)
  2948. {
  2949. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2950. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2951. {
  2952. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2953. {
  2954. reqSampleMeter[gun_index] = 1;
  2955. }
  2956. }
  2957. }// End for GB
  2958. }
  2959. else if(gunType[gun_index] == GUN_TYPE_DO)
  2960. {
  2961. tempIndex = gun_index;
  2962. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2963. {
  2964. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2965. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2966. {
  2967. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  2968. {
  2969. reqSampleMeter[gun_index] = 1;
  2970. }
  2971. }
  2972. }
  2973. }
  2974. else
  2975. {
  2976. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2977. {
  2978. tempIndex = 2;
  2979. }
  2980. else
  2981. {
  2982. tempIndex = gun_index;
  2983. }
  2984. for (int index = 0; index < AC_QUANTITY; index++)
  2985. {
  2986. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2987. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2988. {
  2989. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  2990. {
  2991. reqSampleMeter[gun_index] = 1;
  2992. }
  2993. }
  2994. }//End for AC
  2995. }
  2996. if(reqSampleMeter[gun_index] == 1)
  2997. {
  2998. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  2999. storeTempStopTransaction(gun_index);
  3000. }
  3001. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3002. }
  3003. //==============================================
  3004. // Check Connector reserved
  3005. //==============================================
  3006. //===============================
  3007. // Check if Reserve is expired
  3008. //===============================
  3009. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  3010. {
  3011. double diff_t;
  3012. struct tm tp;
  3013. // current time
  3014. time_t t = time(NULL);
  3015. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  3016. tp.tm_isdst = -1;
  3017. time_t utc = mktime(&tp);
  3018. diff_t = difftime(utc, t);
  3019. if(diff_t <= 0)
  3020. {
  3021. DEBUG_INFO("reserve expired.\n");
  3022. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  3023. }
  3024. }//END OF Check if Reserve is expired
  3025. //==========================================
  3026. // csu trigger FirmwareStatusNotificationReq
  3027. //==========================================
  3028. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  3029. {
  3030. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  3031. }
  3032. //==========================================
  3033. // csu trigger CancelReservationConf
  3034. //==========================================
  3035. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  3036. {
  3037. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  3038. }
  3039. //==========================================
  3040. // csu trigger ChangeAvailabilityConf
  3041. //==========================================
  3042. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  3043. {
  3044. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  3045. }
  3046. //==========================================
  3047. // csu trigger UnlockConnectorConf
  3048. //==========================================
  3049. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  3050. {
  3051. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  3052. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  3053. }
  3054. //==========================================
  3055. // csu trigger ReserveNowConf
  3056. //==========================================
  3057. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  3058. {
  3059. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  3060. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  3061. }
  3062. }
  3063. }
  3064. //==========================================
  3065. // send request routine
  3066. //==========================================
  3067. int sendAuthorizeRequest(int gun_index)
  3068. {
  3069. mtrace();
  3070. int result = FAIL;
  3071. char message[100]={0};
  3072. char guid[37];
  3073. char tempdata[65]={0};
  3074. DEBUG_INFO("sendAuthorizeRequest...\n");
  3075. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  3076. //Local Authorize
  3077. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  3078. {
  3079. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  3080. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  3081. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  3082. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  3083. result = PASS;
  3084. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3085. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3086. authorizeRetryTimes = 0;
  3087. return result;
  3088. }
  3089. else if(((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0))||
  3090. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  3091. {
  3092. // Query from cache
  3093. DEBUG_INFO("Authorize from cache.\n");
  3094. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3095. // Query from list
  3096. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3097. {
  3098. DEBUG_INFO("Authorize from list.\n");
  3099. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3100. }
  3101. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3102. {
  3103. if(strcmp(idTagQuery.idTagstr,"") == 0)
  3104. {
  3105. DEBUG_INFO("off-line Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  3106. }
  3107. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  3108. {
  3109. DEBUG_INFO("off-line Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  3110. }
  3111. DEBUG_INFO("off-line Local Authorization Fail !!!!\n");
  3112. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  3113. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3114. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  3115. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  3116. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3117. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3118. authorizeRetryTimes = 0;
  3119. return result;
  3120. }
  3121. else
  3122. {
  3123. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  3124. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3125. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3126. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  3127. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  3128. else
  3129. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  3130. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  3131. result = PASS;
  3132. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3133. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3134. authorizeRetryTimes = 0;
  3135. return result;
  3136. }
  3137. }
  3138. //initialize struct Authorize
  3139. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  3140. //get data from shared memory
  3141. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3142. random_uuid(guid);
  3143. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  3144. LWS_Send(message);
  3145. sprintf(tempdata, "Authorize,%d", gun_index);
  3146. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3147. {
  3148. result = PASS;
  3149. DEBUG_INFO("Authorize mapItem pass\n");
  3150. }
  3151. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3152. return result;
  3153. }
  3154. int sendBootNotificationRequest(void)
  3155. {
  3156. mtrace();
  3157. int result = FAIL;
  3158. char message[500]={0}, payload[700]={0};
  3159. char guid[37]={0};
  3160. char tempdata[65]={0};
  3161. // Fill BootNotification fields
  3162. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  3163. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  3164. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  3165. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3166. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  3167. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  3168. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  3169. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  3170. ShmOCPP16Data->ChargeBoxId
  3171. ,ShmSysConfigAndInfo->SysConfig.ModelName
  3172. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  3173. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  3174. ,ShmOCPP16Data->BootNotification.CpFwVersion
  3175. ,ShmOCPP16Data->BootNotification.CpIccid
  3176. ,ShmOCPP16Data->BootNotification.CpImsi);
  3177. random_uuid(guid);
  3178. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  3179. LWS_Send(message);
  3180. sprintf(tempdata, "BootNotification,0");
  3181. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid,mapItem, tempdata/*(void**)(&mapItem)*//*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  3182. {
  3183. result = PASS;
  3184. }
  3185. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3186. strcpy(queuedata,message);
  3187. return result;
  3188. }
  3189. int sendDataTransferRequest(int gun_index)
  3190. {
  3191. mtrace();
  3192. char message[1000]={0};
  3193. char guid[37]={0};
  3194. char tempdata[65]={0};
  3195. int result = FAIL;
  3196. random_uuid(guid);
  3197. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  3198. MESSAGE_TYPE_CALL,
  3199. guid,
  3200. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  3201. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  3202. ShmOCPP16Data->DataTransfer[gun_index].Data);
  3203. LWS_Send(message);
  3204. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  3205. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3206. {
  3207. result = PASS;
  3208. DEBUG_INFO("DataTransfer mapItem pass\n");
  3209. }
  3210. return result;
  3211. }
  3212. int sendDiagnosticsStatusNotificationRequest(char *status)
  3213. {
  3214. mtrace();
  3215. int result = FAIL;
  3216. char message[110]={0};
  3217. char guid[37]={0};
  3218. char tempdata[65]={0};
  3219. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  3220. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  3221. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  3222. random_uuid(guid);
  3223. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  3224. LWS_SendNow(message);
  3225. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  3226. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3227. {
  3228. result = PASS;
  3229. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  3230. }
  3231. //#ifdef SystemLogMessage
  3232. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  3233. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3234. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  3235. //#endif
  3236. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  3237. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  3238. //record status
  3239. if(strcmp(status,"Idle")==0)
  3240. {
  3241. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  3242. }
  3243. else if(strcmp(status,"Uploaded")==0)
  3244. {
  3245. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  3246. }
  3247. else if(strcmp(status,"UploadFailed")==0)
  3248. {
  3249. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  3250. }
  3251. else if(strcmp(status,"Uploading")==0)
  3252. {
  3253. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  3254. }
  3255. return result;
  3256. }
  3257. int sendFirmwareStatusNotificationRequest(char *status)
  3258. {
  3259. mtrace();
  3260. int result = FAIL;
  3261. char message[110]={0};
  3262. char guid[37]={0};
  3263. char tempdata[65]={0};
  3264. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  3265. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  3266. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  3267. random_uuid(guid);
  3268. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  3269. LWS_SendNow(message);
  3270. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  3271. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  3272. {
  3273. result = PASS;
  3274. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  3275. }
  3276. //#ifdef SystemLogMessage
  3277. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  3278. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3279. //#endif
  3280. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  3281. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  3282. //record status
  3283. if(strcmp(status,"Downloaded")==0)
  3284. {
  3285. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  3286. }
  3287. else if(strcmp(status,"DownloadFailed")==0)
  3288. {
  3289. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  3290. }
  3291. else if(strcmp(status,"Downloading")==0)
  3292. {
  3293. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  3294. }
  3295. else if(strcmp(status,"Idle")==0)
  3296. {
  3297. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  3298. }
  3299. else if(strcmp(status,"InstallationFailed")==0)
  3300. {
  3301. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  3302. }
  3303. else if(strcmp(status,"Installing")==0)
  3304. {
  3305. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  3306. }
  3307. else if(strcmp(status,"Installed")==0)
  3308. {
  3309. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  3310. }
  3311. return result;
  3312. }
  3313. int sendHeartbeatRequest(int gun_index)
  3314. {
  3315. mtrace();
  3316. int result = FAIL;
  3317. char message[80]={0};
  3318. char guid[37]={0};
  3319. char tempdata[65]={0};
  3320. random_uuid(guid);
  3321. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  3322. , MESSAGE_TYPE_CALL
  3323. , guid );
  3324. LWS_Send(message);
  3325. sprintf(tempdata, "Heartbeat,%d", 0);
  3326. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid, mapItem, tempdata/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  3327. {
  3328. result = PASS;
  3329. }
  3330. return result;
  3331. }
  3332. int sendStartTransactionRequest(int gun_index)
  3333. {
  3334. mtrace();
  3335. int result = FAIL;
  3336. char message[250]={0};
  3337. char guid[37]={0};
  3338. struct timeval tmnow;
  3339. struct tm *tm;
  3340. char buf[28];//, usec_buf[6];
  3341. char tempdata[65]={0};
  3342. int tempIndex = 0;
  3343. DEBUG_INFO("sendStartTransactionRequest...\n");
  3344. gettimeofday(&tmnow, NULL);
  3345. time_t t;
  3346. t = time(NULL);
  3347. /*UTC time and date*/
  3348. tm = gmtime(&t);
  3349. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3350. #if 0 // remove temporally
  3351. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3352. strcat(buf,".");
  3353. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3354. strcat(buf,usec_buf);
  3355. #endif
  3356. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  3357. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  3358. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3359. // clear StartTransaction Response
  3360. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  3361. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  3362. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  3363. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  3364. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3365. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3366. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3367. {
  3368. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3369. {
  3370. tempIndex = ((gun_index==2) ? 1: 0);
  3371. }
  3372. else
  3373. {
  3374. tempIndex = gun_index;
  3375. }
  3376. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3377. {
  3378. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3379. {
  3380. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3381. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  3382. }
  3383. }
  3384. }
  3385. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3386. {
  3387. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3388. {
  3389. tempIndex = ((gun_index==2) ? 1: 0);
  3390. }
  3391. else
  3392. {
  3393. tempIndex = gun_index;
  3394. }
  3395. for (int index = 0; index < CCS_QUANTITY; index++)
  3396. {
  3397. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3398. {
  3399. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3400. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  3401. }
  3402. }
  3403. }
  3404. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3405. {
  3406. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3407. {
  3408. tempIndex = ((gun_index==2) ? 1: 0);
  3409. }
  3410. else
  3411. {
  3412. tempIndex = gun_index;
  3413. }
  3414. for (int index = 0; index < GB_QUANTITY; index++)
  3415. {
  3416. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3417. {
  3418. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3419. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  3420. }
  3421. }
  3422. }
  3423. else if(gunType[gun_index] == GUN_TYPE_DO)
  3424. {
  3425. tempIndex = gun_index;
  3426. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3427. {
  3428. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3429. {
  3430. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3431. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  3432. }
  3433. }
  3434. }
  3435. else
  3436. {
  3437. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3438. {
  3439. tempIndex = 2;
  3440. }
  3441. else
  3442. {
  3443. tempIndex = gun_index;
  3444. }
  3445. for (int index = 0; index < AC_QUANTITY; index++)
  3446. {
  3447. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3448. {
  3449. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3450. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  3451. }
  3452. }
  3453. }
  3454. random_uuid(guid);
  3455. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  3456. {
  3457. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  3458. , gun_index +1
  3459. , MESSAGE_TYPE_CALL
  3460. , guid
  3461. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3462. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3463. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3464. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3465. }
  3466. else
  3467. {
  3468. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  3469. , gun_index +1
  3470. , MESSAGE_TYPE_CALL
  3471. , guid
  3472. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3473. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3474. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3475. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  3476. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3477. }
  3478. #if 1
  3479. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  3480. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  3481. {
  3482. result = PASS;
  3483. }
  3484. #endif
  3485. strcpy(queuedata, message);
  3486. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3487. OCPP_insert_transaction_msg(YES, queuedata);
  3488. return result;
  3489. }
  3490. int sendStatusNotificationRequest(int gun_index)
  3491. {
  3492. mtrace();
  3493. int result = FAIL;
  3494. char message[600]={0};
  3495. char guid[37];
  3496. int currentStatus = 0;
  3497. struct timeval tmnow;
  3498. struct tm *tm;
  3499. char buf[28];//, usec_buf[6];
  3500. char tempdata[65]={0};
  3501. int tempIndex = 0;
  3502. uint8_t isStateChanged = TRUE;
  3503. DEBUG_INFO("sendStatusNotificationRequest...\n");
  3504. gettimeofday(&tmnow, NULL);
  3505. time_t t;
  3506. t = time(NULL);
  3507. /*UTC time and date*/
  3508. tm = gmtime(&t);
  3509. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3510. #if 0 // remove temporally
  3511. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3512. strcat(buf,".");
  3513. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3514. strcat(buf,usec_buf);
  3515. #endif
  3516. printf("%s",buf);
  3517. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  3518. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  3519. // it's option
  3520. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  3521. /*
  3522. enum _SYSTEM_STATUS
  3523. {
  3524. S_BOOTING = 0,
  3525. S_IDLE, = 1
  3526. S_AUTHORIZING, =2
  3527. S_REASSIGN_CHECK, =3
  3528. S_REASSIGN, =4
  3529. S_PRECHARGE, =5
  3530. S_PREPARING_FOR_EV, =6
  3531. S_PREPARING_FOR_EVSE, =7
  3532. S_CHARGING, =8
  3533. S_TERMINATING, =9
  3534. S_COMPLETE, =10
  3535. S_ALARM, =11
  3536. S_FAULT =12
  3537. }
  3538. */
  3539. //check Transaction active
  3540. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3541. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3542. {
  3543. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3544. {
  3545. tempIndex = ((gun_index==2) ? 1: 0);
  3546. }
  3547. else
  3548. {
  3549. tempIndex = gun_index;
  3550. }
  3551. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3552. {
  3553. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  3554. {
  3555. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  3556. {
  3557. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3558. {
  3559. currentStatus = Preparing; //OCPP Status: Preparing
  3560. }
  3561. else
  3562. {
  3563. currentStatus = Available; //OCPP Status: Available
  3564. }
  3565. }
  3566. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3567. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3568. ) //S_PRECHARGE
  3569. {
  3570. currentStatus = Preparing; //OCPP Status: Preparing
  3571. }
  3572. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3573. {
  3574. currentStatus = Charging; //OCPP Status: Charging
  3575. }
  3576. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3577. {
  3578. currentStatus = Finishing; //OCPP Status: Finishing
  3579. }
  3580. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3581. {
  3582. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3583. }
  3584. 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
  3585. {
  3586. currentStatus = Unavailable; //OCPP Status: Unavailable
  3587. }
  3588. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3589. {
  3590. currentStatus = Faulted; //OCPP Status: Faulted
  3591. }
  3592. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3593. {
  3594. currentStatus = Reserved; //OCPP Status: Reserved
  3595. }
  3596. } //end of the same index
  3597. }//end of for CHAdeMO_QUANTITY
  3598. }
  3599. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3600. {
  3601. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3602. {
  3603. tempIndex = ((gun_index==2) ? 1: 0);
  3604. }
  3605. else
  3606. {
  3607. tempIndex = gun_index;
  3608. }
  3609. for (int index = 0; index < CCS_QUANTITY; index++)
  3610. {
  3611. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3612. {
  3613. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3614. {
  3615. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3616. {
  3617. currentStatus = Preparing; //OCPP Status: Preparing
  3618. }
  3619. else
  3620. {
  3621. currentStatus = Available; //OCPP Status: Available
  3622. }
  3623. }
  3624. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3625. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3626. ) //S_PRECHARGE
  3627. {
  3628. currentStatus = Preparing; //OCPP Status: Preparing
  3629. }
  3630. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3631. {
  3632. currentStatus = Charging; //OCPP Status: Charging
  3633. }
  3634. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3635. {
  3636. currentStatus = Finishing; //OCPP Status: Finishing
  3637. }
  3638. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3639. {
  3640. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3641. }
  3642. 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
  3643. {
  3644. currentStatus = Unavailable; //OCPP Status : Unavailable
  3645. }
  3646. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3647. {
  3648. currentStatus = Faulted; //OCPP Status: Faulted
  3649. }
  3650. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3651. {
  3652. currentStatus = Reserved; //OCPP Status: Reserved
  3653. }
  3654. } //end of the same index
  3655. } // end of for CCS_QUANTITY
  3656. }
  3657. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3658. {
  3659. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3660. {
  3661. tempIndex = ((gun_index==2) ? 1: 0);
  3662. }
  3663. else
  3664. {
  3665. tempIndex = gun_index;
  3666. }
  3667. for (int index = 0; index < GB_QUANTITY; index++)
  3668. {
  3669. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3670. {
  3671. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3672. {
  3673. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3674. {
  3675. currentStatus = Preparing; //OCPP Status: Preparing
  3676. }
  3677. else
  3678. {
  3679. currentStatus = Available; //OCPP Status: Available
  3680. }
  3681. }
  3682. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3683. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3684. ) //S_PRECHARGE
  3685. {
  3686. currentStatus = Preparing; //OCPP Status: Preparing
  3687. }
  3688. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3689. {
  3690. currentStatus = Charging; //OCPP Status: Charging
  3691. }
  3692. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3693. {
  3694. currentStatus = Finishing; //OCPP Status: Finishing
  3695. }
  3696. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3697. {
  3698. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3699. }
  3700. 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
  3701. {
  3702. currentStatus = Unavailable; //OCPP Status: Unavailable
  3703. }
  3704. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3705. {
  3706. currentStatus = Faulted; //OCPP Status: Faulted
  3707. }
  3708. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3709. {
  3710. currentStatus = Reserved; //OCPP Status: Reserved
  3711. }
  3712. } //end of the same index
  3713. } // end of for GB_QUANTITY
  3714. }
  3715. else if(gunType[gun_index] == GUN_TYPE_DO)
  3716. {
  3717. tempIndex = gun_index;
  3718. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3719. {
  3720. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3721. {
  3722. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3723. {
  3724. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3725. {
  3726. currentStatus = Preparing; //OCPP Status: Preparing
  3727. }
  3728. else
  3729. {
  3730. currentStatus = Available; //OCPP Status: Available
  3731. }
  3732. }
  3733. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3734. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3735. ) //S_PRECHARGE
  3736. {
  3737. currentStatus = Preparing; //OCPP Status: Preparing
  3738. }
  3739. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3740. {
  3741. currentStatus = Charging; //OCPP Status: Charging
  3742. }
  3743. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3744. {
  3745. currentStatus = Finishing; //OCPP Status: Finishing
  3746. }
  3747. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3748. {
  3749. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3750. }
  3751. 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
  3752. {
  3753. currentStatus = Unavailable; //OCPP Status: Unavailable
  3754. }
  3755. 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
  3756. {
  3757. currentStatus = Faulted; //OCPP Status: Faulted
  3758. }
  3759. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3760. {
  3761. currentStatus = Reserved; //OCPP Status: Reserved
  3762. }
  3763. } //end of the same index
  3764. }
  3765. }
  3766. else
  3767. {
  3768. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3769. {
  3770. tempIndex = 2;
  3771. }
  3772. else
  3773. {
  3774. tempIndex = gun_index;
  3775. }
  3776. for (int index = 0; index < AC_QUANTITY; index++)
  3777. {
  3778. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3779. {
  3780. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3781. {
  3782. 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))
  3783. {
  3784. currentStatus = Preparing; //OCPP Status: Preparing
  3785. }
  3786. else
  3787. {
  3788. currentStatus = Available; //OCPP Status: Available
  3789. }
  3790. }
  3791. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  3792. {
  3793. currentStatus = Preparing; //OCPP Status: Preparing
  3794. }
  3795. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3796. {
  3797. currentStatus = Charging; //OCPP Status: Charging
  3798. }
  3799. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3800. {
  3801. currentStatus = Finishing; //OCPP Status: Finishing
  3802. }
  3803. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3804. {
  3805. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3806. }
  3807. 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
  3808. {
  3809. currentStatus = Unavailable; //OCPP Status: Unavailable
  3810. }
  3811. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3812. {
  3813. currentStatus = Faulted; //OCPP Status: Faulted
  3814. }
  3815. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3816. {
  3817. currentStatus = Reserved; //OCPP Status: Reserved
  3818. }
  3819. }//end of the same index
  3820. }//end of for AC_QUANTITY
  3821. }
  3822. //it's option
  3823. if(strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL)
  3824. {
  3825. isStateChanged = FALSE;
  3826. }
  3827. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3828. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3829. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3830. random_uuid(guid);
  3831. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3832. , MESSAGE_TYPE_CALL
  3833. , guid
  3834. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3835. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3836. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3837. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3838. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3839. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3840. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3841. if((server_sign == TRUE) && isStateChanged)
  3842. {
  3843. LWS_Send(message);
  3844. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3845. 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*/)
  3846. {
  3847. //DEBUG_ERROR("statusNotification mapitem pass");
  3848. result = PASS;
  3849. }
  3850. }
  3851. else
  3852. {
  3853. result = PASS;
  3854. }
  3855. return result;
  3856. }
  3857. int sendStopTransactionRequest(int gun_index)
  3858. {
  3859. mtrace();
  3860. int result = FAIL;
  3861. //char message[1500]={0};
  3862. char guid[37]={0};
  3863. char tempdata[65]={0};
  3864. int tempIndex = 0;
  3865. char TempStopTransaction[256];
  3866. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  3867. //int idx_sample=0;
  3868. DEBUG_INFO("sendStopTransactionRequest \n");
  3869. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3870. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  3871. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  3872. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3873. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3874. {
  3875. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3876. {
  3877. tempIndex = ((gun_index==2) ? 1: 0);
  3878. }
  3879. else
  3880. {
  3881. tempIndex = gun_index;
  3882. }
  3883. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3884. {
  3885. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3886. {
  3887. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3888. }
  3889. }// END OF CHAdeMO_QUANTITY
  3890. }
  3891. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3892. {
  3893. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3894. {
  3895. tempIndex = ((gun_index==2) ? 1: 0);
  3896. }
  3897. else
  3898. {
  3899. tempIndex = gun_index;
  3900. }
  3901. for (int index = 0; index < CCS_QUANTITY; index++)
  3902. {
  3903. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3904. {
  3905. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3906. }
  3907. }// END OF CCS_QUANTITY
  3908. }
  3909. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3910. {
  3911. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3912. {
  3913. tempIndex = ((gun_index==2) ? 1: 0);
  3914. }
  3915. else
  3916. {
  3917. tempIndex = gun_index;
  3918. }
  3919. for (int index = 0; index < GB_QUANTITY; index++)
  3920. {
  3921. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3922. {
  3923. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3924. }
  3925. }// END OF GB_QUANTITY
  3926. }
  3927. else if(gunType[gun_index] == GUN_TYPE_DO)
  3928. {
  3929. tempIndex = gun_index;
  3930. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3931. {
  3932. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3933. {
  3934. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3935. }
  3936. }// END OF GB_QUANTITY
  3937. }
  3938. else
  3939. {
  3940. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3941. {
  3942. tempIndex = 2;
  3943. }
  3944. else
  3945. {
  3946. tempIndex = gun_index;
  3947. }
  3948. for (int index = 0; index < AC_QUANTITY; index++)
  3949. {
  3950. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3951. {
  3952. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3953. }
  3954. }// END OF AC_QUANTITY
  3955. }
  3956. //====================================== Stop Transaction Time =====================================================
  3957. struct timeval tmnow;
  3958. struct tm *tm;
  3959. char buf[28];//, usec_buf[6];
  3960. gettimeofday(&tmnow, NULL);
  3961. time_t t;
  3962. t = time(NULL);
  3963. /*UTC time and date*/
  3964. tm = gmtime(&t);
  3965. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3966. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  3967. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  3968. random_uuid(guid);
  3969. /***********************************transactionData******************************************************/
  3970. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  3971. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  3972. //=================================
  3973. // Transaction_Begin
  3974. //=================================
  3975. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  3976. {
  3977. //============================================ Energy.Active.Import.Interval ================================
  3978. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  3979. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  3980. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  3981. 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*/]);
  3982. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3983. 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))
  3984. {
  3985. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  3986. }
  3987. else
  3988. {
  3989. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  3990. }
  3991. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  3992. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3993. }
  3994. //=================================
  3995. // Transaction_End
  3996. //=================================
  3997. // ================================= Current.Import L1 ===============================================
  3998. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  3999. {
  4000. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  4001. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4002. {
  4003. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4004. {
  4005. tempIndex = ((gun_index==2) ? 1: 0);
  4006. }
  4007. else
  4008. {
  4009. tempIndex = gun_index;
  4010. }
  4011. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4012. {
  4013. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4014. {
  4015. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4016. }
  4017. }// End of for CHAdeMO_QUANTITY
  4018. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4019. }
  4020. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4021. {
  4022. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4023. {
  4024. tempIndex = ((gun_index==2) ? 1: 0);
  4025. }
  4026. else
  4027. {
  4028. tempIndex = gun_index;
  4029. }
  4030. for (int index = 0; index < CCS_QUANTITY; index++)
  4031. {
  4032. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4033. {
  4034. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4035. }
  4036. }// End of for CCS_QUANTITY
  4037. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4038. }
  4039. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4040. {
  4041. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4042. {
  4043. tempIndex = ((gun_index==2) ? 1: 0);
  4044. }
  4045. else
  4046. {
  4047. tempIndex = gun_index;
  4048. }
  4049. for (int index = 0; index < GB_QUANTITY; index++)
  4050. {
  4051. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4052. {
  4053. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4054. }
  4055. }// End of for GB_QUANTITY
  4056. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4057. }
  4058. else if(gunType[gun_index] == GUN_TYPE_DO)
  4059. {
  4060. tempIndex = gun_index;
  4061. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4062. {
  4063. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4064. {
  4065. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4066. }
  4067. }
  4068. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4069. }
  4070. else
  4071. {
  4072. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4073. {
  4074. tempIndex = 2;
  4075. }
  4076. else
  4077. {
  4078. tempIndex = gun_index;
  4079. }
  4080. for (int index = 0; index < AC_QUANTITY; index++)
  4081. {
  4082. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4083. {
  4084. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  4085. }
  4086. }// End of for AC_QUANTITY
  4087. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  4088. }
  4089. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4090. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  4091. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  4092. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  4093. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4094. }
  4095. // ================================= Energy.Active.Import.Interval ==============================================
  4096. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4097. {
  4098. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4099. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4100. {
  4101. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4102. {
  4103. tempIndex = ((gun_index==2) ? 1: 0);
  4104. }
  4105. else
  4106. {
  4107. tempIndex = gun_index;
  4108. }
  4109. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4110. {
  4111. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4112. {
  4113. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4114. }
  4115. }// END OF CHAdeMO_QUANTITY
  4116. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4117. }
  4118. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4119. {
  4120. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4121. {
  4122. tempIndex = ((gun_index==2) ? 1: 0);
  4123. }
  4124. else
  4125. {
  4126. tempIndex = gun_index;
  4127. }
  4128. for (int index = 0; index < CCS_QUANTITY; index++)
  4129. {
  4130. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4131. {
  4132. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4133. }
  4134. }// END OF CCS_QUANTITY
  4135. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4136. }
  4137. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4138. {
  4139. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4140. {
  4141. tempIndex = ((gun_index==2) ? 1: 0);
  4142. }
  4143. else
  4144. {
  4145. tempIndex = gun_index;
  4146. }
  4147. for (int index = 0; index < GB_QUANTITY; index++)
  4148. {
  4149. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4150. {
  4151. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4152. }
  4153. }// END OF GB_QUANTITY
  4154. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4155. }
  4156. else if(gunType[gun_index] == GUN_TYPE_DO)
  4157. {
  4158. tempIndex = gun_index;
  4159. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4160. {
  4161. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4162. {
  4163. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4164. }
  4165. }
  4166. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4167. }
  4168. else
  4169. {
  4170. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4171. {
  4172. tempIndex = 2;
  4173. }
  4174. else
  4175. {
  4176. tempIndex = gun_index;
  4177. }
  4178. for (int index = 0; index < AC_QUANTITY; index++)
  4179. {
  4180. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4181. {
  4182. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4183. }
  4184. }// END OF AC_QUANTITY
  4185. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  4186. }
  4187. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4188. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  4189. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  4190. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  4191. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4192. }
  4193. //=================================== Power.Active.Import ==================================================
  4194. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  4195. {
  4196. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4197. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4198. {
  4199. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4200. {
  4201. tempIndex = ((gun_index==2) ? 1: 0);
  4202. }
  4203. else
  4204. {
  4205. tempIndex = gun_index;
  4206. }
  4207. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4208. {
  4209. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4210. {
  4211. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4212. }
  4213. } // End for CHAdeMO_QUANTITY
  4214. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4215. }
  4216. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4217. {
  4218. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4219. {
  4220. tempIndex = ((gun_index==2) ? 1: 0);
  4221. }
  4222. else
  4223. {
  4224. tempIndex = gun_index;
  4225. }
  4226. for (int index = 0; index < CCS_QUANTITY; index++)
  4227. {
  4228. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4229. {
  4230. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4231. }
  4232. } // END for CCS_QUANTITY
  4233. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4234. }
  4235. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4236. {
  4237. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4238. {
  4239. tempIndex = ((gun_index==2) ? 1: 0);
  4240. }
  4241. else
  4242. {
  4243. tempIndex = gun_index;
  4244. }
  4245. for (int index = 0; index < GB_QUANTITY; index++)
  4246. {
  4247. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4248. {
  4249. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4250. }
  4251. }// END for GB_QUANTITY
  4252. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4253. }
  4254. else if(gunType[gun_index] == GUN_TYPE_DO)
  4255. {
  4256. tempIndex = gun_index;
  4257. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4258. {
  4259. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4260. {
  4261. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4262. }
  4263. }
  4264. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4265. }
  4266. else
  4267. {
  4268. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4269. {
  4270. tempIndex = 2;
  4271. }
  4272. else
  4273. {
  4274. tempIndex = gun_index;
  4275. }
  4276. for (int index = 0; index < AC_QUANTITY; index++)
  4277. {
  4278. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4279. {
  4280. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4281. }
  4282. } // END for AC_QUANTITY
  4283. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  4284. }
  4285. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4286. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  4287. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  4288. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  4289. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  4290. }
  4291. //============================ Voltage L1 ====================================
  4292. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4293. {
  4294. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4295. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4296. {
  4297. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4298. {
  4299. tempIndex = ((gun_index==2) ? 1: 0);
  4300. }
  4301. else
  4302. {
  4303. tempIndex = gun_index;
  4304. }
  4305. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4306. {
  4307. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4308. {
  4309. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4310. }
  4311. } // END OF FOR CHAdeMO_QUANTITY
  4312. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4313. }
  4314. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4315. {
  4316. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4317. {
  4318. tempIndex = ((gun_index==2) ? 1: 0);
  4319. }
  4320. else
  4321. {
  4322. tempIndex = gun_index;
  4323. }
  4324. for (int index = 0; index < CCS_QUANTITY; index++)
  4325. {
  4326. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4327. {
  4328. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4329. }
  4330. } // END OF FOR CCS_QUANTITY
  4331. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4332. }
  4333. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4334. {
  4335. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4336. {
  4337. tempIndex = ((gun_index==2) ? 1: 0);
  4338. }
  4339. else
  4340. {
  4341. tempIndex = gun_index;
  4342. }
  4343. for (int index = 0; index < GB_QUANTITY; index++)
  4344. {
  4345. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4346. {
  4347. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4348. }
  4349. } // END OF FOR GB_QUANTITY
  4350. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4351. }
  4352. else if(gunType[gun_index] == GUN_TYPE_DO)
  4353. {
  4354. tempIndex = gun_index;
  4355. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4356. {
  4357. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4358. {
  4359. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4360. }
  4361. }
  4362. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4363. }
  4364. else
  4365. {
  4366. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4367. {
  4368. tempIndex = 2;
  4369. }
  4370. else
  4371. {
  4372. tempIndex = gun_index;
  4373. }
  4374. for (int index = 0; index < AC_QUANTITY; index++)
  4375. {
  4376. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4377. {
  4378. 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
  4379. }
  4380. } // END OF FOR AC_QUANTITY
  4381. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  4382. }
  4383. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4384. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  4385. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  4386. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  4387. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4388. }
  4389. //====================== End SoC ================================
  4390. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4391. {
  4392. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4393. 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))
  4394. {
  4395. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4396. {
  4397. tempIndex = ((gun_index==2) ? 1: 0);
  4398. }
  4399. else
  4400. {
  4401. tempIndex = gun_index;
  4402. }
  4403. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4404. {
  4405. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4406. {
  4407. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4408. {
  4409. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  4410. }
  4411. }
  4412. }
  4413. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4414. {
  4415. for (int index = 0; index < CCS_QUANTITY; index++)
  4416. {
  4417. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4418. {
  4419. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  4420. }
  4421. }
  4422. }
  4423. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4424. {
  4425. for (int index = 0; index < GB_QUANTITY; index++)
  4426. {
  4427. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4428. {
  4429. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  4430. }
  4431. }
  4432. }
  4433. else if(gunType[gun_index] == GUN_TYPE_DO)
  4434. {
  4435. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4436. {
  4437. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4438. {
  4439. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  4440. }
  4441. }
  4442. }
  4443. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4444. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  4445. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4446. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  4447. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  4448. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4449. } // END FOR DC CASE
  4450. }
  4451. // ================================= Current.Import L2 ===============================================
  4452. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4453. {
  4454. // AC 3 phse L2 current
  4455. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4456. {
  4457. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4458. {
  4459. tempIndex = 2;
  4460. }
  4461. else
  4462. {
  4463. tempIndex = gun_index;
  4464. }
  4465. for (int index = 0; index < AC_QUANTITY; index++)
  4466. {
  4467. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4468. {
  4469. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  4470. }
  4471. }// End of for AC_QUANTITY
  4472. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  4473. }
  4474. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4475. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  4476. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  4477. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  4478. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4479. }
  4480. // ================================= Current.Import L3 ===============================================
  4481. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4482. {
  4483. // AC 3 phse L3 current
  4484. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4485. {
  4486. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4487. {
  4488. tempIndex = 2;
  4489. }
  4490. else
  4491. {
  4492. tempIndex = gun_index;
  4493. }
  4494. for (int index = 0; index < AC_QUANTITY; index++)
  4495. {
  4496. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4497. {
  4498. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  4499. }
  4500. }// End of for AC_QUANTITY
  4501. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  4502. }
  4503. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4504. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  4505. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  4506. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  4507. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4508. }
  4509. //============================ Voltage L2 ====================================
  4510. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4511. {
  4512. // AC 3 phse L2 voltage
  4513. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4514. {
  4515. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4516. {
  4517. tempIndex = 2;
  4518. }
  4519. else
  4520. {
  4521. tempIndex = gun_index;
  4522. }
  4523. for (int index = 0; index < AC_QUANTITY; index++)
  4524. {
  4525. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4526. {
  4527. 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
  4528. }
  4529. } // END OF FOR AC_QUANTITY
  4530. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  4531. }
  4532. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4533. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  4534. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  4535. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  4536. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4537. }
  4538. //============================ Voltage L3 ====================================
  4539. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4540. {
  4541. // AC 3 phse L3 voltage
  4542. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4543. {
  4544. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4545. {
  4546. tempIndex = 2;
  4547. }
  4548. else
  4549. {
  4550. tempIndex = gun_index;
  4551. }
  4552. for (int index = 0; index < AC_QUANTITY; index++)
  4553. {
  4554. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4555. {
  4556. 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
  4557. }
  4558. } // END OF FOR AC_QUANTITY
  4559. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  4560. }
  4561. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4562. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  4563. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  4564. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  4565. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4566. }
  4567. //====================== Start SoC ================================
  4568. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4569. {
  4570. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4571. 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))
  4572. {
  4573. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4574. {
  4575. tempIndex = ((gun_index==2) ? 1: 0);
  4576. }
  4577. else
  4578. {
  4579. tempIndex = gun_index;
  4580. }
  4581. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4582. {
  4583. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4584. {
  4585. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4586. {
  4587. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  4588. }
  4589. }
  4590. }
  4591. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4592. {
  4593. for (int index = 0; index < CCS_QUANTITY; index++)
  4594. {
  4595. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4596. {
  4597. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  4598. }
  4599. }
  4600. }
  4601. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4602. {
  4603. for (int index = 0; index < GB_QUANTITY; index++)
  4604. {
  4605. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4606. {
  4607. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  4608. }
  4609. }
  4610. }
  4611. else if(gunType[gun_index] == GUN_TYPE_DO)
  4612. {
  4613. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4614. {
  4615. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4616. {
  4617. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  4618. }
  4619. }
  4620. }
  4621. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4622. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  4623. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4624. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  4625. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  4626. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4627. } // END FOR DC CASE
  4628. }
  4629. //================================================ Message create ====================================================
  4630. json_object *StopTransaction = json_object_new_object();
  4631. json_object *transactionDatas = json_object_new_array();
  4632. json_object *sampledValues = json_object_new_array();
  4633. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  4634. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  4635. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  4636. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  4637. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  4638. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  4639. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  4640. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  4641. {
  4642. json_object *transactionData = json_object_new_object();
  4643. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  4644. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  4645. {
  4646. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  4647. {
  4648. json_object *sampledValue = json_object_new_object();
  4649. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  4650. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  4651. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  4652. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  4653. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  4654. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  4655. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  4656. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  4657. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  4658. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  4659. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  4660. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  4661. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  4662. json_object_array_add(sampledValues, sampledValue);
  4663. }
  4664. }
  4665. json_object_object_add(transactionData, "sampledValue", sampledValues);
  4666. json_object_array_add(transactionDatas, transactionData);
  4667. }
  4668. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  4669. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  4670. ,MESSAGE_TYPE_CALL
  4671. ,guid
  4672. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  4673. json_object_put(StopTransaction);
  4674. #if 1 // for TempStopTransaction
  4675. //Delete TempStopTransaction
  4676. if((access(TempStopTransaction,F_OK))!=-1)
  4677. {
  4678. remove(TempStopTransaction); // remove file "TempStopTransaction"
  4679. }
  4680. #endif
  4681. #if 1
  4682. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4683. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4684. {
  4685. result = PASS;
  4686. //DEBUG_INFO("StopTransaction mapitem pass\n");
  4687. }
  4688. #endif
  4689. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4690. OCPP_insert_transaction_msg(NO, queuedata);
  4691. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4692. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  4693. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  4694. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4695. {
  4696. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  4697. }
  4698. //for test
  4699. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4700. return result;
  4701. }
  4702. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  4703. {
  4704. mtrace();
  4705. int result = FAIL;
  4706. char guid[37]={0};
  4707. char tempdata[65]={0};
  4708. int tempIndex = 0;
  4709. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4710. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4711. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  4712. //set value
  4713. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4714. 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) )?
  4715. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  4716. -1);
  4717. random_uuid(guid);
  4718. //UTC Date time
  4719. struct timeval tmnow;
  4720. struct tm *tm;
  4721. char buf[28];//, usec_buf[6];
  4722. gettimeofday(&tmnow, NULL);
  4723. time_t t;
  4724. t = time(NULL);
  4725. /*UTC time and date*/
  4726. tm = gmtime(&t);
  4727. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4728. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4729. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4730. //********************************(1)Current.Import L1************************************************/
  4731. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  4732. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  4733. (dataType == ReadingContext_Trigger))
  4734. {
  4735. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4736. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4737. {
  4738. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4739. {
  4740. tempIndex = ((gun_index==2) ? 1: 0);
  4741. }
  4742. else
  4743. {
  4744. tempIndex = gun_index;
  4745. }
  4746. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4747. {
  4748. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4749. {
  4750. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4751. }
  4752. }
  4753. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4754. }
  4755. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4756. {
  4757. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4758. {
  4759. tempIndex = ((gun_index==2) ? 1: 0);
  4760. }
  4761. else
  4762. {
  4763. tempIndex = gun_index;
  4764. }
  4765. for (int index = 0; index < CCS_QUANTITY; index++)
  4766. {
  4767. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4768. {
  4769. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4770. }
  4771. }
  4772. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4773. }
  4774. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4775. {
  4776. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4777. {
  4778. tempIndex = ((gun_index==2) ? 1: 0);
  4779. }
  4780. else
  4781. {
  4782. tempIndex = gun_index;
  4783. }
  4784. for (int index = 0; index < GB_QUANTITY; index++)
  4785. {
  4786. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4787. {
  4788. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4789. }
  4790. }
  4791. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4792. }
  4793. else if(gunType[gun_index] == GUN_TYPE_DO)
  4794. {
  4795. tempIndex = gun_index;
  4796. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4797. {
  4798. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4799. {
  4800. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  4801. }
  4802. }
  4803. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4804. }
  4805. else
  4806. {
  4807. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4808. {
  4809. tempIndex = 2;
  4810. }
  4811. else
  4812. {
  4813. tempIndex = gun_index;
  4814. }
  4815. for (int index = 0; index < AC_QUANTITY; index++)
  4816. {
  4817. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4818. {
  4819. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4820. }
  4821. }
  4822. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4823. }
  4824. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4825. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4826. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4827. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4828. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4829. }
  4830. //********************************(2)Energy.Active.Import.Register ************************************************/
  4831. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4832. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4833. (dataType == ReadingContext_Trigger))
  4834. {
  4835. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4836. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4837. {
  4838. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4839. {
  4840. tempIndex = ((gun_index==2) ? 1: 0);
  4841. }
  4842. else
  4843. {
  4844. tempIndex = gun_index;
  4845. }
  4846. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4847. {
  4848. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4849. {
  4850. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4851. }
  4852. }
  4853. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4854. }
  4855. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4856. {
  4857. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4858. {
  4859. tempIndex = ((gun_index==2) ? 1: 0);
  4860. }
  4861. else
  4862. {
  4863. tempIndex = gun_index;
  4864. }
  4865. for (int index = 0; index < CCS_QUANTITY; index++)
  4866. {
  4867. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4868. {
  4869. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4870. }
  4871. }
  4872. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4873. }
  4874. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4875. {
  4876. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4877. {
  4878. tempIndex = ((gun_index==2) ? 1: 0);
  4879. }
  4880. else
  4881. {
  4882. tempIndex = gun_index;
  4883. }
  4884. for (int index = 0; index < GB_QUANTITY; index++)
  4885. {
  4886. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4887. {
  4888. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4889. }
  4890. }
  4891. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4892. }
  4893. else if(gunType[gun_index] == GUN_TYPE_DO)
  4894. {
  4895. tempIndex = gun_index;
  4896. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4897. {
  4898. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4899. {
  4900. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  4901. }
  4902. }
  4903. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4904. }
  4905. else
  4906. {
  4907. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4908. {
  4909. tempIndex = 2;
  4910. }
  4911. else
  4912. {
  4913. tempIndex = gun_index;
  4914. }
  4915. for (int index = 0; index < AC_QUANTITY; index++)
  4916. {
  4917. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4918. {
  4919. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  4920. }
  4921. }
  4922. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4923. }
  4924. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  4925. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  4926. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  4927. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  4928. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4929. }
  4930. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  4931. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  4932. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  4933. (dataType == ReadingContext_Trigger))
  4934. {
  4935. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4936. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4937. {
  4938. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4939. {
  4940. tempIndex = ((gun_index==2) ? 1: 0);
  4941. }
  4942. else
  4943. {
  4944. tempIndex = gun_index;
  4945. }
  4946. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4947. {
  4948. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4949. {
  4950. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  4951. }
  4952. } // END OF FOR CHAdeMO_QUANTITY
  4953. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4954. }
  4955. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4956. {
  4957. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4958. {
  4959. tempIndex = ((gun_index==2) ? 1: 0);
  4960. }
  4961. else
  4962. {
  4963. tempIndex = gun_index;
  4964. }
  4965. for (int index = 0; index < CCS_QUANTITY; index++)
  4966. {
  4967. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4968. {
  4969. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  4970. }
  4971. } // END OF CCS_QUANTITY
  4972. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4973. }
  4974. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4975. {
  4976. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4977. {
  4978. tempIndex = ((gun_index==2) ? 1: 0);
  4979. }
  4980. else
  4981. {
  4982. tempIndex = gun_index;
  4983. }
  4984. for (int index = 0; index < GB_QUANTITY; index++)
  4985. {
  4986. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4987. {
  4988. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  4989. }
  4990. } // END OF GB_QUANTITY
  4991. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4992. }
  4993. else if(gunType[gun_index] == GUN_TYPE_DO)
  4994. {
  4995. tempIndex = gun_index;
  4996. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4997. {
  4998. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4999. {
  5000. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  5001. }
  5002. }
  5003. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5004. }
  5005. else
  5006. {
  5007. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5008. {
  5009. tempIndex = 2;
  5010. }
  5011. else
  5012. {
  5013. tempIndex = gun_index;
  5014. }
  5015. for (int index = 0; index < AC_QUANTITY; index++)
  5016. {
  5017. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5018. {
  5019. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  5020. }
  5021. }
  5022. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  5023. }
  5024. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  5025. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  5026. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  5027. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  5028. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5029. }
  5030. //********************************(4)Power.Active.Import************************************************/
  5031. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Power.Active.Import") != NULL)) ||
  5032. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Power.Active.Import") != NULL)) ||
  5033. (dataType == ReadingContext_Trigger))
  5034. {
  5035. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5036. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5037. {
  5038. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5039. {
  5040. tempIndex = ((gun_index==2) ? 1: 0);
  5041. }
  5042. else
  5043. {
  5044. tempIndex = gun_index;
  5045. }
  5046. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5047. {
  5048. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5049. {
  5050. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  5051. }
  5052. } // END OF FOR
  5053. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5054. }
  5055. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5056. {
  5057. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5058. {
  5059. tempIndex = ((gun_index==2) ? 1: 0);
  5060. }
  5061. else
  5062. {
  5063. tempIndex = gun_index;
  5064. }
  5065. for (int index = 0; index < CCS_QUANTITY; index++)
  5066. {
  5067. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5068. {
  5069. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  5070. }
  5071. }
  5072. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5073. }
  5074. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5075. {
  5076. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5077. {
  5078. tempIndex = ((gun_index==2) ? 1: 0);
  5079. }
  5080. else
  5081. {
  5082. tempIndex = gun_index;
  5083. }
  5084. for (int index = 0; index < GB_QUANTITY; index++)
  5085. {
  5086. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5087. {
  5088. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5089. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  5090. }
  5091. }
  5092. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5093. }
  5094. else if(gunType[gun_index] == GUN_TYPE_DO)
  5095. {
  5096. tempIndex = gun_index;
  5097. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5098. {
  5099. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5100. {
  5101. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5102. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  5103. }
  5104. }
  5105. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5106. }
  5107. else
  5108. {
  5109. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5110. {
  5111. tempIndex = 2;
  5112. }
  5113. else
  5114. {
  5115. tempIndex = gun_index;
  5116. }
  5117. for (int index = 0; index < AC_QUANTITY; index++)
  5118. {
  5119. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5120. {
  5121. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  5122. }
  5123. }
  5124. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  5125. }
  5126. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  5127. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  5128. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  5129. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  5130. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  5131. }
  5132. //***********************************************(5)VOLTAGE L1******************************************************/
  5133. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5134. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5135. (dataType == ReadingContext_Trigger))
  5136. {
  5137. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5138. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5139. {
  5140. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5141. {
  5142. tempIndex = ((gun_index==2) ? 1: 0);
  5143. }
  5144. else
  5145. {
  5146. tempIndex = gun_index;
  5147. }
  5148. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5149. {
  5150. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5151. {
  5152. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  5153. }
  5154. }
  5155. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5156. }
  5157. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5158. {
  5159. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5160. {
  5161. tempIndex = ((gun_index==2) ? 1: 0);
  5162. }
  5163. else
  5164. {
  5165. tempIndex = gun_index;
  5166. }
  5167. for (int index = 0; index < CCS_QUANTITY; index++)
  5168. {
  5169. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5170. {
  5171. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  5172. }
  5173. }
  5174. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5175. }
  5176. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5177. {
  5178. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5179. {
  5180. tempIndex = ((gun_index==2) ? 1: 0);
  5181. }
  5182. else
  5183. {
  5184. tempIndex = gun_index;
  5185. }
  5186. for (int index = 0; index < GB_QUANTITY; index++)
  5187. {
  5188. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5189. {
  5190. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  5191. }
  5192. }
  5193. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5194. }
  5195. else if(gunType[gun_index] == GUN_TYPE_DO)
  5196. {
  5197. tempIndex = gun_index;
  5198. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5199. {
  5200. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5201. {
  5202. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  5203. }
  5204. }
  5205. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5206. }
  5207. else
  5208. {
  5209. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5210. {
  5211. tempIndex = 2;
  5212. }
  5213. else
  5214. {
  5215. tempIndex = gun_index;
  5216. }
  5217. for (int index = 0; index < AC_QUANTITY; index++)
  5218. {
  5219. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5220. {
  5221. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  5222. }
  5223. }
  5224. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  5225. }
  5226. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  5227. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  5228. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  5229. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  5230. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5231. }
  5232. //***********************************************(6)SOC******************************************************/
  5233. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "SOC") != NULL)) ||
  5234. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "SOC") != NULL)) ||
  5235. (dataType == ReadingContext_Trigger))
  5236. {
  5237. 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))
  5238. {
  5239. //idx_sample=5;
  5240. //sampledValue = NULL;
  5241. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5242. {
  5243. tempIndex = ((gun_index==2) ? 1: 0);
  5244. }
  5245. else
  5246. {
  5247. tempIndex = gun_index;
  5248. }
  5249. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5250. {
  5251. //tempIndex = ((gun_index==2) ? 1: 0);
  5252. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5253. {
  5254. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5255. {
  5256. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  5257. }
  5258. }
  5259. }
  5260. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5261. {
  5262. //tempIndex = ((gun_index==2) ? 1: 0);
  5263. for (int index = 0; index < CCS_QUANTITY; index++)
  5264. {
  5265. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5266. {
  5267. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  5268. }
  5269. }
  5270. }
  5271. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5272. {
  5273. //tempIndex = ((gun_index==2) ? 1: 0);
  5274. for (int index = 0; index < GB_QUANTITY; index++)
  5275. {
  5276. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5277. {
  5278. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  5279. }
  5280. }
  5281. }
  5282. else if(gunType[gun_index] == GUN_TYPE_DO)
  5283. {
  5284. //tempIndex = ((gun_index==2) ? 1: 0);
  5285. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5286. {
  5287. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5288. {
  5289. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  5290. }
  5291. }
  5292. }
  5293. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  5294. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  5295. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  5296. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  5297. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  5298. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  5299. }
  5300. }
  5301. //********************************(7)Current.Import L2************************************************/
  5302. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5303. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5304. (dataType == ReadingContext_Trigger))
  5305. {
  5306. // Only for AC 3 phase
  5307. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5308. {
  5309. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5310. {
  5311. tempIndex = 2;
  5312. }
  5313. else
  5314. {
  5315. tempIndex = gun_index;
  5316. }
  5317. for (int index = 0; index < AC_QUANTITY; index++)
  5318. {
  5319. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5320. {
  5321. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  5322. }
  5323. }
  5324. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  5325. }
  5326. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  5327. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  5328. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  5329. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  5330. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5331. }
  5332. //********************************(8)Current.Import L3************************************************/
  5333. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5334. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5335. (dataType == ReadingContext_Trigger))
  5336. {
  5337. // Only for AC 3 phase
  5338. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5339. {
  5340. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5341. {
  5342. tempIndex = 2;
  5343. }
  5344. else
  5345. {
  5346. tempIndex = gun_index;
  5347. }
  5348. for (int index = 0; index < AC_QUANTITY; index++)
  5349. {
  5350. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5351. {
  5352. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  5353. }
  5354. }
  5355. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  5356. }
  5357. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  5358. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  5359. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  5360. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  5361. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5362. }
  5363. //***********************************************(9)VOLTAGE L2******************************************************/
  5364. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5365. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5366. (dataType == ReadingContext_Trigger))
  5367. {
  5368. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5369. {
  5370. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5371. {
  5372. tempIndex = 2;
  5373. }
  5374. else
  5375. {
  5376. tempIndex = gun_index;
  5377. }
  5378. for (int index = 0; index < AC_QUANTITY; index++)
  5379. {
  5380. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5381. {
  5382. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  5383. }
  5384. }
  5385. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  5386. }
  5387. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  5388. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  5389. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  5390. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  5391. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5392. }
  5393. //***********************************************(10)VOLTAGE L3******************************************************/
  5394. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5395. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5396. (dataType == ReadingContext_Trigger))
  5397. {
  5398. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5399. {
  5400. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5401. {
  5402. tempIndex = 2;
  5403. }
  5404. else
  5405. {
  5406. tempIndex = gun_index;
  5407. }
  5408. for (int index = 0; index < AC_QUANTITY; index++)
  5409. {
  5410. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5411. {
  5412. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  5413. }
  5414. }
  5415. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  5416. }
  5417. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  5418. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  5419. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  5420. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  5421. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5422. }
  5423. // Message create ====================================================================================================
  5424. if(TRUE)
  5425. {
  5426. json_object *MeterValueReq = json_object_new_object();
  5427. json_object *MeterValues = json_object_new_array();
  5428. json_object *sampledValues = json_object_new_array();
  5429. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  5430. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  5431. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  5432. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  5433. {
  5434. json_object *MeterValue = json_object_new_object();
  5435. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  5436. {
  5437. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  5438. {
  5439. json_object *sampledValue = json_object_new_object();
  5440. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  5441. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  5442. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  5443. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  5444. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  5445. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  5446. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  5447. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  5448. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  5449. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  5450. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  5451. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  5452. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  5453. json_object_array_add(sampledValues, sampledValue);
  5454. }
  5455. }
  5456. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  5457. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  5458. json_object_array_add(MeterValues, MeterValue);
  5459. }
  5460. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  5461. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  5462. ,gun_index + 1
  5463. ,MESSAGE_TYPE_CALL
  5464. ,guid
  5465. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  5466. json_object_put(MeterValueReq);
  5467. }
  5468. // Put request guid to hash map
  5469. sprintf(tempdata, "MeterValues,%d", (gun_index));
  5470. 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*/)
  5471. {
  5472. result = PASS;
  5473. //DEBUG_INFO("MeterValues mapitem pass\n");
  5474. }
  5475. if((dataType != ReadingContext_Trigger) &&
  5476. (dataType != ReadingContext_Sample_Clock) &&
  5477. (ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1))
  5478. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  5479. else
  5480. {
  5481. if(FirstHeartBeat)
  5482. LWS_Send(queuedata +2);
  5483. }
  5484. return result;
  5485. }
  5486. int sendLogStatusNotificationRequest(char *status)
  5487. {
  5488. mtrace();
  5489. int result = PASS;
  5490. char message[4096]={0};
  5491. char guid[37]={0};
  5492. char tempdata[128]={0};
  5493. json_object *LogStatusNotification = json_object_new_object();
  5494. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  5495. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  5496. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  5497. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  5498. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  5499. random_uuid(guid);
  5500. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  5501. json_object_put(LogStatusNotification);
  5502. LWS_SendNow(message);
  5503. sprintf(tempdata, "LogStatusNotification,%d", 0);
  5504. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5505. {
  5506. result = PASS;
  5507. }
  5508. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  5509. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  5510. return result;
  5511. }
  5512. int sendSecurityEventNotificationRequest(int gun_index)
  5513. {
  5514. mtrace();
  5515. int result = PASS;
  5516. char message[4096]={0};
  5517. char guid[37]={0};
  5518. char tempdata[128]={0};
  5519. json_object *SecurityEventNotification = json_object_new_object();
  5520. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  5521. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  5522. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  5523. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  5524. random_uuid(guid);
  5525. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  5526. json_object_put(SecurityEventNotification);
  5527. LWS_Send(message);
  5528. sprintf(tempdata, "SecurityEventNotification,0");
  5529. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5530. {
  5531. result = PASS;
  5532. }
  5533. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  5534. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  5535. return result;
  5536. }
  5537. int sendSignCertificateRequest(int gun_index)
  5538. {
  5539. mtrace();
  5540. int result = PASS;
  5541. char message[4096]={0};
  5542. char guid[37]={0};
  5543. char tempdata[128]={0};
  5544. json_object *SignCertificate = json_object_new_object();
  5545. DEBUG_INFO("sendSignCertificateRequest...\n");
  5546. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  5547. random_uuid(guid);
  5548. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  5549. json_object_put(SignCertificate);
  5550. LWS_Send(message);
  5551. sprintf(tempdata, "SignCertificate,0");
  5552. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5553. {
  5554. result = PASS;
  5555. }
  5556. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  5557. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  5558. return result;
  5559. }
  5560. int sendSignedFirmwareStatusNotificationRequest(char *status)
  5561. {
  5562. mtrace();
  5563. int result = PASS;
  5564. char message[110]={0};
  5565. char guid[37]={0};
  5566. char tempdata[65]={0};
  5567. json_object *FirmwareStatusNotification = json_object_new_object();
  5568. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  5569. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  5570. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  5571. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  5572. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  5573. random_uuid(guid);
  5574. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  5575. json_object_put(FirmwareStatusNotification);
  5576. LWS_SendNow(message);
  5577. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  5578. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5579. {
  5580. result = PASS;
  5581. }
  5582. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  5583. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  5584. return result;
  5585. }
  5586. //==========================================
  5587. // send confirm routine
  5588. //==========================================
  5589. int sendCancelReservationConfirmation(char *uuid,char *payload)
  5590. {
  5591. mtrace();
  5592. int result = FAIL;
  5593. char message[100]={0};
  5594. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  5595. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5596. LWS_Send(message);
  5597. result = TRUE;
  5598. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  5599. return result;
  5600. }
  5601. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  5602. {
  5603. mtrace();
  5604. int result = FAIL;
  5605. char message[100]={0};
  5606. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  5607. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5608. LWS_Send(message);
  5609. result = TRUE;
  5610. return result;
  5611. }
  5612. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  5613. {
  5614. mtrace();
  5615. int result = FAIL;
  5616. char message[100]={0};
  5617. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  5618. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5619. LWS_Send(message);
  5620. result = TRUE;
  5621. return result;
  5622. }
  5623. int sendClearCacheConfirmation(char *uuid,char *payload)
  5624. {
  5625. mtrace();
  5626. int result = FAIL;
  5627. char message[500]={0};
  5628. DEBUG_INFO("sendClearCacheConfirmation...\n");
  5629. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5630. LWS_Send(message);
  5631. return result;
  5632. }
  5633. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  5634. {
  5635. mtrace();
  5636. int result = FAIL;
  5637. char message[500]={0};
  5638. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  5639. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5640. LWS_Send(message);
  5641. return result;
  5642. }
  5643. int sendDataTransferConfirmation(char *uuid,char *payload)
  5644. {
  5645. mtrace();
  5646. char statusStr[20]={0};
  5647. char dataStr[10]={0};
  5648. char sstr[20]={0};
  5649. int c = 0;
  5650. char *loc;
  5651. int result = FAIL;
  5652. DEBUG_INFO("sendDataTransferConfirmation...\n");
  5653. /**********************status**************************/
  5654. loc = strstr(payload, "status");
  5655. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5656. c = 0;
  5657. while (loc[3+strlen("status")+c] != '\"')
  5658. {
  5659. sstr[c] = loc[3+strlen("status")+c];
  5660. c++;
  5661. }
  5662. sstr[c] = '\0';
  5663. strcpy(statusStr, sstr);
  5664. /**********************data**************************/
  5665. loc = strstr(payload, "data");
  5666. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5667. c = 0;
  5668. while (loc[3+strlen("data")+c] != '\"')
  5669. {
  5670. sstr[c] = loc[3+strlen("data")+c];
  5671. c++;
  5672. }
  5673. sstr[c] = '\0';
  5674. strcpy(dataStr, sstr);
  5675. return result;
  5676. }
  5677. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  5678. {
  5679. mtrace();
  5680. int result = FAIL;
  5681. char message[1000]={0};
  5682. int CompositeScheduleIndex = 0;
  5683. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  5684. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  5685. if(nPeriod == 0)
  5686. {
  5687. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  5688. {
  5689. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  5690. ,MESSAGE_TYPE_CALLRESULT
  5691. ,uuid
  5692. ,payload
  5693. ,connectorIdInt);
  5694. }
  5695. else
  5696. {
  5697. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  5698. ,MESSAGE_TYPE_CALLRESULT
  5699. ,uuid
  5700. ,payload
  5701. ,connectorIdInt
  5702. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5703. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5704. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5705. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  5706. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  5707. }
  5708. }
  5709. else
  5710. {
  5711. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  5712. ,MESSAGE_TYPE_CALLRESULT
  5713. ,uuid
  5714. ,payload
  5715. ,connectorIdInt
  5716. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5717. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5718. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5719. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  5720. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  5721. {
  5722. if (idx_sample == 0)
  5723. {
  5724. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5725. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5726. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5727. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5728. }
  5729. else
  5730. {
  5731. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5732. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5733. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5734. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5735. }
  5736. }
  5737. sprintf(message + strlen(message), "]}}]");
  5738. }
  5739. LWS_Send(message);
  5740. result = TRUE;
  5741. return result;
  5742. }
  5743. int sendGetConfigurationConfirmation(char *uuid)
  5744. {
  5745. mtrace();
  5746. int result = FAIL;
  5747. int MaxKeySupported = 0;
  5748. int sentConfigurationNumber= 0;
  5749. int sentunConfigurationNumber= 0;
  5750. char message[4000]={0};
  5751. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  5752. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  5753. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  5754. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  5755. ,MESSAGE_TYPE_CALLRESULT
  5756. ,uuid );
  5757. //configuration key
  5758. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  5759. {
  5760. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  5761. {
  5762. if (sentConfigurationNumber == 0)
  5763. {
  5764. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5765. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5766. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5767. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5768. }
  5769. else
  5770. {
  5771. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5772. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5773. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5774. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5775. }
  5776. sentConfigurationNumber = sentConfigurationNumber + 1;
  5777. }
  5778. }
  5779. sprintf(message + strlen(message), "]");
  5780. if(UnknownKeynum != 0)
  5781. {
  5782. sprintf(message + strlen(message), ",\"unknownKey\":[");
  5783. //unkown key
  5784. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  5785. {
  5786. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  5787. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  5788. if(sentunConfigurationNumber == 0)
  5789. {
  5790. sprintf(message + strlen(message), "\"%s\""
  5791. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5792. }
  5793. else
  5794. {
  5795. sprintf(message + strlen(message), ",\"%s\""
  5796. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5797. }
  5798. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  5799. }
  5800. sprintf(message + strlen(message), "]");
  5801. }
  5802. sprintf(message + strlen(message), "}]");
  5803. LWS_Send(message);
  5804. return result;
  5805. }
  5806. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  5807. {
  5808. mtrace();
  5809. int result = FAIL;
  5810. char message[400]={0};
  5811. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  5812. if(strcmp(payload,"")==0)
  5813. {
  5814. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5815. }
  5816. else
  5817. {
  5818. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5819. }
  5820. LWS_Send(message);
  5821. result = TRUE;
  5822. return result;
  5823. }
  5824. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  5825. {
  5826. mtrace();
  5827. int result = FAIL;
  5828. char message[80]={0};
  5829. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  5830. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  5831. LWS_Send(message);
  5832. result = TRUE;
  5833. return result;
  5834. }
  5835. int sendRemoteStartConfirmation(char *uuid,char *payload)
  5836. {
  5837. mtrace();
  5838. int result = FAIL;
  5839. char message[80]={0};
  5840. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  5841. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5842. LWS_Send(message);
  5843. result = TRUE;
  5844. return result;
  5845. }
  5846. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5847. {
  5848. mtrace();
  5849. int result = FAIL;
  5850. char message[80]={0};
  5851. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5852. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5853. LWS_Send(message);
  5854. result = TRUE;
  5855. return result;
  5856. }
  5857. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5858. {
  5859. mtrace();
  5860. int result = FAIL;
  5861. char message[80]={0};
  5862. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5863. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  5864. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5865. LWS_Send(message);
  5866. result = TRUE;
  5867. return result;
  5868. }
  5869. int sendResetConfirmation(char *uuid,char *payload)
  5870. {
  5871. mtrace();
  5872. int result = FAIL;
  5873. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  5874. char message[80]={0};
  5875. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  5876. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5877. LWS_Send(message);
  5878. result = TRUE;
  5879. return result;
  5880. }
  5881. int sendSendLocalListConfirmation(char *uuid,char *payload)
  5882. {
  5883. mtrace();
  5884. int result = FAIL;
  5885. char message[500]={0};
  5886. // [ 3, "1571284266109", { "status": "Accepted" } ]
  5887. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5888. LWS_Send(message);
  5889. result = TRUE;
  5890. return result;
  5891. }
  5892. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  5893. {
  5894. mtrace();
  5895. int result = FAIL;
  5896. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  5897. char message[80]={0};
  5898. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  5899. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5900. LWS_Send(message);
  5901. result = TRUE;
  5902. return result;
  5903. }
  5904. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  5905. {
  5906. mtrace();
  5907. int result = FAIL;
  5908. char message[80]={0};
  5909. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  5910. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5911. LWS_Send(message);
  5912. result = TRUE;
  5913. return result;
  5914. }
  5915. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  5916. {
  5917. mtrace();
  5918. int result = FAIL;
  5919. char message[80]={0};
  5920. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5921. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  5922. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5923. LWS_Send(message);
  5924. result = TRUE;
  5925. return result;
  5926. }
  5927. int sendUpdateFirmwareConfirmation(char *uuid)
  5928. {
  5929. mtrace();
  5930. int result = FAIL;
  5931. char message[60]={0};
  5932. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5933. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  5934. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5935. LWS_Send(message);
  5936. result = TRUE;
  5937. return result;
  5938. }
  5939. int sendCertificateSignedConfirmation(char *uuid)
  5940. {
  5941. mtrace();
  5942. int result = PASS;
  5943. char message[4096]={0};
  5944. json_object *CertificateSigned = json_object_new_object();
  5945. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  5946. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  5947. sprintf(message,"[%d,\"%s\",%s]"
  5948. ,MESSAGE_TYPE_CALLRESULT
  5949. ,uuid
  5950. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  5951. json_object_put(CertificateSigned);
  5952. LWS_Send(message);
  5953. return result;
  5954. }
  5955. int sendDeleteCertificateConfirmation(char *uuid)
  5956. {
  5957. mtrace();
  5958. int result = PASS;
  5959. char message[4096]={0};
  5960. json_object *DeleteCertificate = json_object_new_object();
  5961. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  5962. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  5963. sprintf(message,"[%d,\"%s\",%s]"
  5964. ,MESSAGE_TYPE_CALLRESULT
  5965. ,uuid
  5966. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  5967. json_object_put(DeleteCertificate);
  5968. LWS_Send(message);
  5969. return result;
  5970. }
  5971. int sendExtendedTriggerMessageConfirmation(char *uuid)
  5972. {
  5973. mtrace();
  5974. int result = PASS;
  5975. char message[4096]={0};
  5976. json_object *ExtendedTriggerMessage = json_object_new_object();
  5977. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  5978. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  5979. sprintf(message,"[%d,\"%s\",%s]"
  5980. ,MESSAGE_TYPE_CALLRESULT
  5981. ,uuid
  5982. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  5983. json_object_put(ExtendedTriggerMessage);
  5984. LWS_Send(message);
  5985. return result;
  5986. }
  5987. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  5988. {
  5989. mtrace();
  5990. int result = PASS;
  5991. char message[4096]={0};
  5992. json_object *GetInstalledCertificateIds = json_object_new_object();
  5993. json_object *certificateHashDataDatas = json_object_new_array();
  5994. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  5995. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  5996. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  5997. {
  5998. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  5999. {
  6000. json_object *certificateHashData = json_object_new_object();
  6001. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  6002. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  6003. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  6004. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  6005. json_object_array_add(certificateHashDataDatas, certificateHashData);
  6006. }
  6007. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  6008. }
  6009. else
  6010. {
  6011. json_object_put(certificateHashDataDatas);
  6012. }
  6013. sprintf(message,"[%d,\"%s\",%s]"
  6014. ,MESSAGE_TYPE_CALLRESULT
  6015. ,uuid
  6016. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  6017. json_object_put(GetInstalledCertificateIds);
  6018. LWS_Send(message);
  6019. return result;
  6020. }
  6021. int sendGetLogConfirmation(char *uuid)
  6022. {
  6023. mtrace();
  6024. int result = PASS;
  6025. char message[4096]={0};
  6026. json_object *GetLog = json_object_new_object();
  6027. DEBUG_INFO("sendGetLogConfirmation...\n");
  6028. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  6029. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  6030. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  6031. sprintf(message,"[%d,\"%s\",%s]"
  6032. ,MESSAGE_TYPE_CALLRESULT
  6033. ,uuid
  6034. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  6035. json_object_put(GetLog);
  6036. LWS_Send(message);
  6037. return result;
  6038. }
  6039. int sendInstallCertificateConfirmation(char *uuid)
  6040. {
  6041. mtrace();
  6042. int result = PASS;
  6043. char message[4096]={0};
  6044. json_object *InstallCertificate = json_object_new_object();
  6045. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  6046. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  6047. sprintf(message,"[%d,\"%s\",%s]"
  6048. ,MESSAGE_TYPE_CALLRESULT
  6049. ,uuid
  6050. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  6051. json_object_put(InstallCertificate);
  6052. LWS_Send(message);
  6053. return result;
  6054. }
  6055. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  6056. {
  6057. mtrace();
  6058. int result = PASS;
  6059. char message[4096]={0};
  6060. json_object *SignedUpdateFirmware = json_object_new_object();
  6061. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  6062. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  6063. sprintf(message,"[%d,\"%s\",%s]"
  6064. ,MESSAGE_TYPE_CALLRESULT
  6065. ,uuid
  6066. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  6067. json_object_put(SignedUpdateFirmware);
  6068. LWS_Send(message);
  6069. return result;
  6070. }
  6071. int sendUnknownConfirmation(char *uuid)
  6072. {
  6073. mtrace();
  6074. int result = PASS;
  6075. char message[256]={0};
  6076. DEBUG_INFO("sendUnknownConfirmation...\n");
  6077. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  6078. LWS_Send(message);
  6079. return result;
  6080. }
  6081. //==========================================
  6082. // Handle server request routine Start
  6083. //==========================================
  6084. int handleCancelReservationRequest(char *uuid, char *payload)
  6085. {
  6086. mtrace();
  6087. int result = FAIL;
  6088. int gunNO = 0;
  6089. int reservationIdInt = -1;
  6090. char comfirmstr[20];
  6091. DEBUG_INFO("handleCancelReservationRequest...\n");
  6092. json_object *CancelReservation;
  6093. CancelReservation = json_tokener_parse(payload);
  6094. if(!is_error(CancelReservation))
  6095. {
  6096. // Required data
  6097. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  6098. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  6099. }
  6100. json_object_put(CancelReservation);
  6101. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  6102. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6103. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  6104. if(reservationIdInt != -1)
  6105. {
  6106. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6107. //check Transaction active
  6108. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6109. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6110. {
  6111. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  6112. {
  6113. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6114. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6115. if(gunType[2] == GUN_TYPE_CHAdeMO)
  6116. {
  6117. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  6118. }
  6119. else
  6120. {
  6121. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  6122. }
  6123. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6124. goto end;
  6125. }
  6126. }
  6127. for (int index = 0; index < CCS_QUANTITY; index++)
  6128. {
  6129. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  6130. {
  6131. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6132. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6133. if(gunType[2] == GUN_TYPE_CCS)
  6134. {
  6135. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  6136. }
  6137. else
  6138. {
  6139. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  6140. }
  6141. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6142. goto end;
  6143. }
  6144. }
  6145. for (int index = 0; index < GB_QUANTITY; index++)
  6146. {
  6147. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  6148. {
  6149. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6150. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6151. if(gunType[2] == GUN_TYPE_GBT)
  6152. {
  6153. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  6154. }
  6155. else
  6156. {
  6157. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  6158. }
  6159. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6160. goto end;
  6161. }
  6162. }
  6163. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6164. {
  6165. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  6166. {
  6167. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6168. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6169. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  6170. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6171. goto end;
  6172. }
  6173. }
  6174. for (int index = 0; index < AC_QUANTITY; index++)
  6175. {
  6176. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  6177. {
  6178. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6179. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6180. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6181. {
  6182. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  6183. }
  6184. else
  6185. {
  6186. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  6187. }
  6188. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6189. goto end;
  6190. }
  6191. }
  6192. }
  6193. //The reservationId does NOT match the reservationId
  6194. sendCancelReservationConfirmation(uuid, comfirmstr);
  6195. end:
  6196. // Fill in ocpp packet uuid
  6197. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  6198. return result;
  6199. }
  6200. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  6201. {
  6202. mtrace();
  6203. int result = FAIL;
  6204. int gunIndex = 0;
  6205. char typeStr[16]={0};
  6206. char comfirmstr[20];
  6207. int specificId = FALSE;
  6208. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  6209. json_object *ChangeAvailability;
  6210. ChangeAvailability = json_tokener_parse(payload);
  6211. if(!is_error(ChangeAvailability))
  6212. {
  6213. // Required data
  6214. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  6215. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  6216. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  6217. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  6218. }
  6219. json_object_put(ChangeAvailability);
  6220. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6221. {
  6222. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  6223. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  6224. }
  6225. else if(gunIndex == 0)
  6226. {
  6227. for(int i=0; i < gunTotalNumber; i++)
  6228. {
  6229. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  6230. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  6231. }
  6232. }
  6233. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6234. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6235. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  6236. {
  6237. specificId = TRUE;
  6238. }
  6239. if(specificId == FALSE)
  6240. goto end;
  6241. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  6242. {
  6243. //----------------------gunIndex is 0 ------------------------------------------------//
  6244. if(gunIndex == 0)
  6245. {
  6246. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6247. {
  6248. for(int i=0; i < gunTotalNumber; i++)
  6249. {
  6250. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6251. {
  6252. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  6253. {
  6254. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6255. {
  6256. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6257. goto end;
  6258. }
  6259. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6260. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6261. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6262. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6263. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6264. {
  6265. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6266. goto end;
  6267. }
  6268. }
  6269. }//END FOR CHAdeMO_QUANTITY
  6270. for (int index = 0; index < CCS_QUANTITY; index++)
  6271. {
  6272. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  6273. {
  6274. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  6275. {
  6276. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6277. goto end;
  6278. }
  6279. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6280. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6281. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6282. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6283. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6284. {
  6285. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6286. goto end;
  6287. }
  6288. }
  6289. }//END FOR CCS_QUANTITY
  6290. for (int index = 0; index < GB_QUANTITY; index++)
  6291. {
  6292. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  6293. {
  6294. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6295. {
  6296. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6297. goto end;
  6298. }
  6299. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6300. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6301. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6302. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6303. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6304. {
  6305. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6306. goto end;
  6307. }
  6308. }
  6309. }// END FOR GB_QUANTITY
  6310. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6311. {
  6312. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  6313. {
  6314. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6315. {
  6316. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6317. goto end;
  6318. }
  6319. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  6320. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  6321. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  6322. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  6323. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6324. {
  6325. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6326. goto end;
  6327. }
  6328. }
  6329. }// END FOR GENERAL_GUN_QUANTITY
  6330. for (int index = 0; index < AC_QUANTITY; index++)
  6331. {
  6332. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  6333. {
  6334. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6335. {
  6336. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6337. goto end;
  6338. }
  6339. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6340. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6341. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6342. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6343. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6344. {
  6345. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6346. goto end;
  6347. }
  6348. }
  6349. }//END FOR AC_QUANTITY
  6350. }// END FOR gunTotalNumber
  6351. }
  6352. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6353. {
  6354. for(int i=0; i < gunTotalNumber; i++)
  6355. {
  6356. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6357. {
  6358. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6359. goto end;
  6360. }
  6361. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6362. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  6363. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  6364. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  6365. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6366. {
  6367. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6368. goto end;
  6369. }
  6370. }
  6371. }
  6372. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6373. goto end;
  6374. }
  6375. //----------------------gunIndex is not 0 ------------------------------------------------//
  6376. //check Transaction active
  6377. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6378. {
  6379. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  6380. {
  6381. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  6382. {
  6383. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6384. goto end;
  6385. }
  6386. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6387. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6388. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6389. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6390. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6391. {
  6392. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6393. goto end;
  6394. }
  6395. else
  6396. {
  6397. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  6398. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6399. goto end;
  6400. }
  6401. }
  6402. }//END FOR CHAdeMO_QUANTITY
  6403. for (int index = 0; index < CCS_QUANTITY; index++)
  6404. {
  6405. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  6406. {
  6407. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  6408. {
  6409. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6410. goto end;
  6411. }
  6412. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6413. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6414. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6415. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6416. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6417. {
  6418. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6419. goto end;
  6420. }
  6421. else
  6422. {
  6423. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  6424. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6425. goto end;
  6426. }
  6427. }
  6428. }//END FOR CCS_QUANTITY
  6429. for (int index = 0; index < GB_QUANTITY; index++)
  6430. {
  6431. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  6432. {
  6433. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6434. {
  6435. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6436. goto end;
  6437. }
  6438. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6439. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6440. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6441. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6442. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6443. {
  6444. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6445. goto end;
  6446. }
  6447. else
  6448. {
  6449. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  6450. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6451. goto end;
  6452. }
  6453. }
  6454. }// END FOR GB_QUANTITY
  6455. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6456. {
  6457. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  6458. {
  6459. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6460. {
  6461. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6462. goto end;
  6463. }
  6464. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  6465. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  6466. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  6467. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  6468. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6469. {
  6470. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6471. goto end;
  6472. }
  6473. else
  6474. {
  6475. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  6476. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6477. goto end;
  6478. }
  6479. }
  6480. }// END FOR GENERAL_GUN_QUANTITY
  6481. for (int index = 0; index < AC_QUANTITY; index++)
  6482. {
  6483. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  6484. {
  6485. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6486. {
  6487. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6488. goto end;
  6489. }
  6490. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6491. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6492. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6493. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6494. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6495. {
  6496. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6497. goto end;
  6498. }
  6499. else
  6500. {
  6501. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  6502. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6503. goto end;
  6504. }
  6505. }
  6506. }//END FOR AC_QUANTITY
  6507. }//END FOR AvailabilityTypeStr[Inoperative]
  6508. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  6509. {
  6510. //----------------------gunIndex is 0 ------------------------------------------------//
  6511. if(gunIndex == 0)
  6512. {
  6513. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6514. {
  6515. for(int i=0; i < gunTotalNumber; i++)
  6516. {
  6517. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6518. {
  6519. 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
  6520. {
  6521. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6522. goto end;
  6523. }
  6524. }//END FOR CHAdeMO_QUANTITY
  6525. for (int index = 0; index < CCS_QUANTITY; index++)
  6526. {
  6527. 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
  6528. {
  6529. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6530. goto end;
  6531. }
  6532. }//END FOR CCS_QUANTITY
  6533. for (int index = 0; index < GB_QUANTITY; index++)
  6534. {
  6535. 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
  6536. {
  6537. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6538. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6539. goto end;
  6540. }
  6541. }// END FOR GB_QUANTITY
  6542. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6543. {
  6544. 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
  6545. {
  6546. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6547. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6548. goto end;
  6549. }
  6550. }// END FOR GENERAL_GUN_QUANTITY
  6551. for (int index = 0; index < AC_QUANTITY; index++)
  6552. {
  6553. 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
  6554. {
  6555. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6556. goto end;
  6557. }
  6558. }//END FOR CHAdeMO_QUANTITY
  6559. }// END FOR gunTotalNumber
  6560. }
  6561. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6562. {
  6563. for(int i=0; i < gunTotalNumber; i++)
  6564. {
  6565. for (int index = 0; index < AC_QUANTITY; index++)
  6566. {
  6567. 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
  6568. {
  6569. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6570. goto end;
  6571. }
  6572. }//END FOR CHAdeMO_QUANTITY
  6573. } // END FOR gunTotalNumber
  6574. }
  6575. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6576. goto end;
  6577. }
  6578. //----------------------gunIndex is not 0 ------------------------------------------------//
  6579. //check Transaction active
  6580. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6581. {
  6582. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6583. {
  6584. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6585. goto end;
  6586. }
  6587. }//END FOR CHAdeMO_QUANTITY
  6588. for (int index = 0; index < CCS_QUANTITY; index++)
  6589. {
  6590. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6591. {
  6592. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6593. goto end;
  6594. }
  6595. }//END FOR CCS_QUANTITY
  6596. for (int index = 0; index < GB_QUANTITY; index++)
  6597. {
  6598. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6599. {
  6600. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6601. goto end;
  6602. }
  6603. }// END FOR GB_QUANTITY
  6604. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6605. {
  6606. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6607. {
  6608. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6609. goto end;
  6610. }
  6611. }// END FOR GENERAL_GUN_QUANTITY
  6612. for (int index = 0; index < AC_QUANTITY; index++)
  6613. {
  6614. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6615. {
  6616. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6617. goto end;
  6618. }
  6619. }//END FOR AC_QUANTITY
  6620. }//END FOR AvailabilityTypeStr[Operative]
  6621. end:
  6622. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6623. {
  6624. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  6625. }
  6626. else
  6627. {
  6628. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  6629. }
  6630. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6631. {
  6632. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6633. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6634. }
  6635. else if(gunIndex == 0)
  6636. {
  6637. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6638. {
  6639. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  6640. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  6641. }
  6642. }
  6643. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  6644. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6645. return result;
  6646. }
  6647. int handleChangeConfigurationRequest(char *uuid, char *payload)
  6648. {
  6649. mtrace();
  6650. int result = FAIL;
  6651. char keystr[40]={0};
  6652. char valuestr[256]={0};
  6653. char comfirmstr[20]={0};
  6654. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  6655. json_object *ChangeConfiguration;
  6656. ChangeConfiguration = json_tokener_parse(payload);
  6657. if(!is_error(ChangeConfiguration))
  6658. {
  6659. // Required data
  6660. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  6661. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  6662. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  6663. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  6664. }
  6665. json_object_put(ChangeConfiguration);
  6666. if((uuid==NULL) || (payload ==NULL) )
  6667. {
  6668. DEBUG_ERROR("Payload is null\n");
  6669. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6670. }
  6671. else
  6672. {
  6673. int status = setKeyValue(keystr, valuestr);
  6674. switch(status)
  6675. {
  6676. case ConfigurationStatus_Accepted:
  6677. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  6678. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  6679. StoreConfigurationTable();
  6680. break;
  6681. case RebootRequired:
  6682. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  6683. StoreConfigurationTable();
  6684. break;
  6685. case NotSupported:
  6686. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  6687. break;
  6688. case ConfigurationStatus_Rejected:
  6689. default:
  6690. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6691. break;
  6692. }
  6693. }
  6694. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  6695. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  6696. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6697. {
  6698. ChageWebSocketPingInterval(atoi(valuestr));
  6699. }
  6700. if((strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6701. {
  6702. SetOcppConnStatus(FALSE);
  6703. }
  6704. return result;
  6705. }
  6706. int handleClearCacheRequest(char *uuid, char *payload)
  6707. {
  6708. mtrace();
  6709. int result = FAIL;
  6710. char comfirmstr[20];
  6711. char rmFileCmd[100]={0};
  6712. struct stat stats;
  6713. DEBUG_INFO("handleClearCacheRequest...\n");
  6714. stat("/Storage/OCPP", &stats);
  6715. // Check for directory existence
  6716. if (S_ISDIR(stats.st_mode) == 1)
  6717. {}
  6718. else
  6719. {
  6720. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  6721. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  6722. system(rmFileCmd);
  6723. }
  6724. if(OCPP_cleanLocalCache())
  6725. {
  6726. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  6727. }
  6728. else
  6729. {
  6730. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  6731. }
  6732. sendClearCacheConfirmation(uuid, comfirmstr);
  6733. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6734. return result;
  6735. }
  6736. int handleClearChargingProfileRequest(char *uuid, char *payload)
  6737. {
  6738. mtrace();
  6739. int result = FAIL;
  6740. int resultRename;
  6741. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  6742. char chargingProfilePurposeStr[26]={0};
  6743. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  6744. char tempchargingProfilePurposeStr[26]={0};
  6745. char str[100]={0};
  6746. char fname[200]={0};
  6747. char comfirmstr[20]={0};
  6748. char word[1600]={0};
  6749. int clearflag = FALSE;
  6750. int chargingProfileIdIsNULL = FALSE;
  6751. int connectorIsNULL = FALSE;
  6752. int chargingProfilePurposeIsNULL = FALSE;
  6753. int stackLevelIsNULL = FALSE;
  6754. //int GotoEnd = FALSE;
  6755. FILE *fptr1, *fptr2;
  6756. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  6757. int n_chargingProfile=0;
  6758. int isEmptyFile = FALSE;
  6759. char sLineWord[1600]={0};
  6760. char chargingProfiles[10][100]={0};
  6761. int ChargeProfileCount = 0;
  6762. int ch;
  6763. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  6764. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  6765. json_object *ClearChargingProfile;
  6766. ClearChargingProfile = json_tokener_parse(payload);
  6767. if(!is_error(ClearChargingProfile))
  6768. {
  6769. // Optional data
  6770. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  6771. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  6772. else
  6773. chargingProfileIdIsNULL = TRUE;
  6774. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  6775. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  6776. else
  6777. connectorIsNULL = TRUE;
  6778. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  6779. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  6780. else
  6781. chargingProfilePurposeIsNULL = TRUE;
  6782. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  6783. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  6784. else
  6785. stackLevelIsNULL = TRUE;
  6786. }
  6787. json_object_put(ClearChargingProfile);
  6788. if(connectorIsNULL == FALSE)
  6789. {
  6790. switch(connectorIdInt)
  6791. {
  6792. case 0:
  6793. if(chargingProfilePurposeIsNULL == TRUE)
  6794. {
  6795. int l = 0;
  6796. strcpy(fname, ChargePointMaxProfile_JSON);
  6797. if((access(fname,F_OK))!=-1)
  6798. {
  6799. strcpy(chargingProfiles[l], fname);
  6800. l = l + 1;
  6801. }
  6802. strcpy(fname, TxDefaultProfile_0_JSON);
  6803. if((access(fname,F_OK))!=-1)
  6804. {
  6805. strcpy(chargingProfiles[l], fname);
  6806. l = l + 1;
  6807. }
  6808. ChargeProfileCount = l;
  6809. }
  6810. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  6811. {
  6812. strcpy(fname, ChargePointMaxProfile_JSON);
  6813. if((access(fname,F_OK))!=-1)
  6814. {
  6815. strcpy(chargingProfiles[0], fname);
  6816. ChargeProfileCount = 1;
  6817. }
  6818. }
  6819. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6820. {
  6821. strcpy(fname, TxDefaultProfile_0_JSON);
  6822. if((access(fname,F_OK))!=-1)
  6823. {
  6824. strcpy(chargingProfiles[0], fname);
  6825. ChargeProfileCount = 1;
  6826. }
  6827. }
  6828. break;
  6829. default:
  6830. if(chargingProfilePurposeIsNULL == TRUE)
  6831. {
  6832. int m = 0;
  6833. memset(fname, 0, ARRAY_SIZE(fname));
  6834. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6835. if((access(fname,F_OK))!=-1)
  6836. {
  6837. strcpy(chargingProfiles[m], fname);
  6838. m = m + 1;
  6839. }
  6840. memset(fname, 0, ARRAY_SIZE(fname));
  6841. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6842. if((access(fname,F_OK))!=-1)
  6843. {
  6844. strcpy(chargingProfiles[m], fname);
  6845. m = m + 1;
  6846. }
  6847. ChargeProfileCount = m;
  6848. }
  6849. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6850. {
  6851. //strcpy(fname, TxDefaultProfile_1_JSON);
  6852. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6853. if((access(fname,F_OK))!=-1)
  6854. {
  6855. strcpy(chargingProfiles[0], fname);
  6856. ChargeProfileCount = 1;
  6857. }
  6858. }
  6859. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  6860. {
  6861. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6862. if((access(fname,F_OK))!=-1)
  6863. {
  6864. strcpy(chargingProfiles[0], fname);
  6865. ChargeProfileCount = 1;
  6866. }
  6867. //strcpy(fname, TxProfile_1_JSON);
  6868. }
  6869. //strcpy(fname, ChargePointMaxProfile_JSON );
  6870. break;
  6871. }
  6872. }
  6873. else // Check all Charging Profiles
  6874. {
  6875. int i = 0;
  6876. char fnametemp[200]={0};
  6877. ChargeProfileCount = 0;
  6878. //Check ChargePointMaxProfile.json exit
  6879. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  6880. {
  6881. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  6882. i = i + 1;
  6883. }
  6884. //Check TxDefaultProfile_0.json exit
  6885. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  6886. {
  6887. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  6888. i = i + 1;
  6889. }
  6890. //Check TxDefaultProfile_%d.json
  6891. for(int j=1; j <= gunTotalNumber; j++)
  6892. {
  6893. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6894. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  6895. if((access(fnametemp,F_OK))!=-1)
  6896. {
  6897. strcpy(chargingProfiles[i], fnametemp);
  6898. i = i + 1;
  6899. }
  6900. }
  6901. //Check TxProfile_%d.json
  6902. for(int j=1; j <= gunTotalNumber; j++)
  6903. {
  6904. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6905. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  6906. if((access(fnametemp,F_OK))!=-1)
  6907. {
  6908. strcpy(chargingProfiles[i], fnametemp);
  6909. i = i + 1;
  6910. }
  6911. }
  6912. ChargeProfileCount = i;
  6913. }// End connectorIsNULL is TRUE
  6914. if(ChargeProfileCount == 0)
  6915. {
  6916. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6917. goto end;
  6918. }
  6919. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  6920. {
  6921. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6922. goto end;
  6923. }
  6924. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  6925. {
  6926. memset(str, 0, ARRAY_SIZE(str));
  6927. // clear temp file
  6928. sprintf(str,"rm -f %s",temp);
  6929. system(str);
  6930. for(int k=0; k < ChargeProfileCount; k++)
  6931. {
  6932. memset(str, 0, ARRAY_SIZE(str));
  6933. //clear file in C
  6934. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6935. system(str);
  6936. }
  6937. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6938. goto end;
  6939. }
  6940. else if(connectorIsNULL == TRUE)
  6941. {
  6942. for(int k=0; k < ChargeProfileCount; k++)
  6943. {
  6944. fptr1 = fopen(chargingProfiles[k], "r");
  6945. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  6946. //Check Charging Profile Count
  6947. while(fscanf(fptr1, "%s", word) != EOF)
  6948. {
  6949. //DEBUG_INFO("word=%s\n",word);
  6950. if(strstr(word, "chargingProfileId")!= NULL)
  6951. {
  6952. //DEBUG_INFO("test chargingProfileId \n");
  6953. n_chargingProfile = n_chargingProfile + 1;
  6954. //DEBUG_INFO("chargingProfileId Found\n");
  6955. }
  6956. }
  6957. rewind(fptr1);
  6958. //search Charging Profile Element
  6959. //int i= 0;
  6960. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6961. {
  6962. json_object *tmpProfilee;
  6963. tmpProfilee = json_tokener_parse(sLineWord);
  6964. if(!is_error(tmpProfilee))
  6965. {
  6966. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  6967. {
  6968. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  6969. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  6970. }
  6971. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  6972. {
  6973. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  6974. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  6975. }
  6976. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  6977. {
  6978. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  6979. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  6980. }
  6981. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  6982. {
  6983. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  6984. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  6985. }
  6986. }
  6987. json_object_put(tmpProfilee);
  6988. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6989. {
  6990. //------- not write to fptr2-------//
  6991. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6992. //clearflag = TRUE;
  6993. }
  6994. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  6995. {
  6996. //------- not write to fptr2-------//
  6997. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6998. }
  6999. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7000. {
  7001. //------- not write to fptr2-------//
  7002. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7003. }
  7004. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  7005. {
  7006. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7007. }
  7008. else
  7009. {
  7010. fprintf(fptr2, sLineWord);//writing data into file
  7011. }
  7012. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7013. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7014. if(clearflag == TRUE)
  7015. {
  7016. fclose(fptr1);
  7017. fclose(fptr2);
  7018. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7019. system(str);
  7020. // clear temp file
  7021. sprintf(str,"rm -f %s",temp);
  7022. system(str);
  7023. }
  7024. else
  7025. {
  7026. fclose(fptr1);
  7027. fclose(fptr2);
  7028. memset(str, 0, ARRAY_SIZE(str));
  7029. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7030. system(str);
  7031. resultRename = rename(temp, chargingProfiles[k]);
  7032. if(resultRename == 0)
  7033. {
  7034. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  7035. }
  7036. else
  7037. {
  7038. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  7039. }
  7040. if(comfirmstr[0]== 0)
  7041. {
  7042. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7043. }
  7044. //Check chargingProfile is empty file
  7045. /*------ Read the file ----------------*/
  7046. fptr1=fopen(chargingProfiles[k],"r");
  7047. ch=fgetc(fptr1);
  7048. rewind(fptr1);
  7049. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7050. if(ch!=EOF)
  7051. {
  7052. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7053. {
  7054. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7055. if(sLineWord[0]=='\0')
  7056. {
  7057. isEmptyFile = TRUE;
  7058. break;
  7059. }
  7060. else
  7061. {
  7062. isEmptyFile = FALSE;
  7063. break;
  7064. }
  7065. }
  7066. }
  7067. else
  7068. isEmptyFile = TRUE;
  7069. fclose(fptr1);
  7070. if(isEmptyFile == TRUE)
  7071. {
  7072. memset(str, 0, ARRAY_SIZE(str));
  7073. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7074. system(str);
  7075. }
  7076. }
  7077. }// End of while(int k=0; k < ChargePointCount; k++)
  7078. }
  7079. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  7080. {
  7081. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  7082. for(int k=0; k < ChargeProfileCount; k++)
  7083. {
  7084. fptr1 = fopen(chargingProfiles[k], "r");
  7085. fptr2 = fopen(temp, "w+");
  7086. //Check Charging Profile Count
  7087. while(fscanf(fptr1, "%s", word) != EOF)
  7088. {
  7089. //DEBUG_INFO("word=%s\n",word);
  7090. if(strstr(word, "chargingProfileId")!= NULL)
  7091. {
  7092. n_chargingProfile = n_chargingProfile + 1;
  7093. }
  7094. }
  7095. rewind(fptr1);
  7096. //search Charging Profile Element
  7097. //int i= 0;
  7098. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7099. {
  7100. json_object *tmpProfilee;
  7101. tmpProfilee = json_tokener_parse(sLineWord);
  7102. if(!is_error(tmpProfilee))
  7103. {
  7104. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7105. {
  7106. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7107. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7108. }
  7109. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7110. {
  7111. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7112. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7113. }
  7114. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7115. {
  7116. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7117. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7118. }
  7119. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7120. {
  7121. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7122. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7123. }
  7124. }
  7125. json_object_put(tmpProfilee);
  7126. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7127. {
  7128. //------- not write to fptr2-------//
  7129. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7130. //clearflag = TRUE;
  7131. }
  7132. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7133. {
  7134. //------- not write to fptr2-------//
  7135. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7136. }
  7137. else if(stackLevelIsNULL == TRUE)
  7138. {
  7139. //Clear Whole File
  7140. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7141. clearflag = TRUE;
  7142. break;
  7143. }
  7144. else
  7145. {
  7146. fprintf(fptr2, sLineWord);//writing data into file
  7147. }
  7148. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7149. }
  7150. if(clearflag == TRUE)
  7151. {
  7152. fclose(fptr1);
  7153. fclose(fptr2);
  7154. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7155. system(str);
  7156. // clear temp file
  7157. sprintf(str,"rm -f %s",temp);
  7158. system(str);
  7159. }
  7160. else
  7161. {
  7162. fclose(fptr1);
  7163. fclose(fptr2);
  7164. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7165. system(str);
  7166. resultRename = rename(temp, chargingProfiles[k]);
  7167. if(resultRename == 0)
  7168. {
  7169. DEBUG_INFO("File ChargingProfile renamed successfully");
  7170. }
  7171. else
  7172. {
  7173. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  7174. }
  7175. if(comfirmstr[0]== 0)
  7176. {
  7177. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7178. }
  7179. //Check chargingProfile is empty file
  7180. /*------ Read the file ----------------*/
  7181. fptr1=fopen(chargingProfiles[k],"r");
  7182. ch=fgetc(fptr1);
  7183. rewind(fptr1);
  7184. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7185. if(ch!=EOF)
  7186. {
  7187. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7188. {
  7189. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7190. if(sLineWord[0]=='\0')
  7191. {
  7192. isEmptyFile = TRUE;
  7193. break;
  7194. }
  7195. else
  7196. {
  7197. isEmptyFile = FALSE;
  7198. break;
  7199. }
  7200. }
  7201. }
  7202. else
  7203. isEmptyFile = TRUE;
  7204. fclose(fptr1);
  7205. if(isEmptyFile == TRUE)
  7206. {
  7207. memset(str, 0, ARRAY_SIZE(str));
  7208. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7209. system(str);
  7210. }
  7211. /*------- End of reading ---------------*/
  7212. }
  7213. } // while(int k=0; k < ChargeProfileCount; k++)
  7214. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  7215. end:
  7216. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  7217. {
  7218. if(connectorIdInt == 0)
  7219. {
  7220. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  7221. {
  7222. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  7223. }
  7224. }
  7225. else
  7226. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  7227. }
  7228. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  7229. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7230. return result;
  7231. }
  7232. void createFirmwareVersionByDataTransfer(void)
  7233. {
  7234. json_object *FirmwareDataTransfer = json_object_new_object();
  7235. // AC & DC model
  7236. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  7237. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  7238. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  7239. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  7240. // DC model
  7241. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O')
  7242. {
  7243. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  7244. {
  7245. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7246. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7247. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  7248. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  7249. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7250. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7251. }
  7252. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  7253. ((gunType[1] != GUN_TYPE_UNKNOWN) || (gunType[2] != GUN_TYPE_UNKNOWN) || (gunType[3] != GUN_TYPE_UNKNOWN)))
  7254. {
  7255. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  7256. }
  7257. }
  7258. else
  7259. {
  7260. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7261. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7262. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7263. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7264. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  7265. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  7266. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  7267. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  7268. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  7269. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  7270. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  7271. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  7272. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  7273. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  7274. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  7275. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  7276. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  7277. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  7278. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  7279. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  7280. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  7281. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  7282. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  7283. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  7284. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  7285. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  7286. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  7287. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  7288. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  7289. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  7290. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  7291. }
  7292. // 4G model
  7293. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  7294. {
  7295. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  7296. }
  7297. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  7298. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  7299. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  7300. json_object_put(FirmwareDataTransfer);
  7301. }
  7302. int handleDataTransferRequest(char *uuid, char *payload)
  7303. {
  7304. mtrace();
  7305. json_object *response = json_object_new_object();
  7306. int result = FAIL;
  7307. char tempvendorId[255]={0};
  7308. char tempmessageId[50]={0};
  7309. char tempdata[512]={0};
  7310. char message[2048]={0};
  7311. DEBUG_INFO("handleDataTransferRequest...\n");
  7312. if((uuid != NULL) && (payload != NULL))
  7313. {
  7314. json_object *DataTransfer;
  7315. DataTransfer = json_tokener_parse(payload);
  7316. if(!is_error(DataTransfer))
  7317. {
  7318. // Required data
  7319. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  7320. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  7321. // Optional data
  7322. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  7323. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  7324. if(json_object_object_get(DataTransfer, "data") != NULL)
  7325. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  7326. result = PASS;
  7327. }
  7328. json_object_put(DataTransfer);
  7329. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  7330. {
  7331. // Send all moudle firmware version on EVSE
  7332. createFirmwareVersionByDataTransfer();
  7333. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7334. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  7335. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7336. json_object_put(response);
  7337. }
  7338. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  7339. {
  7340. system("/usr/bin/run_tmate_restart.sh &");
  7341. }
  7342. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  7343. {
  7344. json_object *data;
  7345. data = json_tokener_parse(tempdata);
  7346. if(!is_error(data))
  7347. {
  7348. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  7349. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  7350. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  7351. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  7352. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  7353. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  7354. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  7355. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  7356. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  7357. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  7358. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7359. }
  7360. else
  7361. {
  7362. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7363. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7364. }
  7365. json_object_put(data);
  7366. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7367. json_object_put(response);
  7368. }
  7369. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  7370. {
  7371. json_object *data;
  7372. data = json_tokener_parse(tempdata);
  7373. if(!is_error(data))
  7374. {
  7375. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  7376. if(json_object_object_get(data, "idToken") != NULL)
  7377. {
  7378. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  7379. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  7380. }
  7381. if(json_object_object_get(data, "price") != NULL)
  7382. {
  7383. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  7384. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  7385. }
  7386. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7387. }
  7388. else
  7389. {
  7390. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7391. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7392. }
  7393. json_object_put(data);
  7394. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7395. json_object_put(response);
  7396. }
  7397. else if(strstr(tempmessageId, "RunningCost") != NULL)
  7398. {
  7399. json_object *data;
  7400. data = json_tokener_parse(tempdata);
  7401. if(!is_error(data))
  7402. {
  7403. if(json_object_object_get(data, "txId") != NULL)
  7404. {
  7405. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7406. for(int idx = 0;idx<gunTotalNumber;idx++)
  7407. {
  7408. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7409. {
  7410. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  7411. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7412. if(json_object_object_get(data, "description") != NULL)
  7413. {
  7414. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7415. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7416. }
  7417. }
  7418. }
  7419. }
  7420. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7421. }
  7422. else
  7423. {
  7424. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7425. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7426. }
  7427. json_object_put(data);
  7428. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7429. json_object_put(response);
  7430. }
  7431. else if(strstr(tempmessageId, "FinalCost") != NULL)
  7432. {
  7433. json_object *data;
  7434. data = json_tokener_parse(tempdata);
  7435. if(!is_error(data))
  7436. {
  7437. if(json_object_object_get(data, "txId") != NULL)
  7438. {
  7439. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7440. for(int idx = 0;idx<gunTotalNumber;idx++)
  7441. {
  7442. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7443. {
  7444. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  7445. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7446. if(json_object_object_get(data, "description") != NULL)
  7447. {
  7448. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7449. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7450. }
  7451. }
  7452. }
  7453. }
  7454. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7455. }
  7456. else
  7457. {
  7458. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7459. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7460. }
  7461. json_object_put(data);
  7462. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7463. json_object_put(response);
  7464. }
  7465. else
  7466. {
  7467. // Can not find valid message id
  7468. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  7469. }
  7470. }
  7471. else
  7472. {
  7473. // Payload is null
  7474. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  7475. }
  7476. LWS_Send(message);
  7477. return result;
  7478. }
  7479. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  7480. {
  7481. mtrace();
  7482. int result = FAIL;
  7483. int connectorIdInt, durationInt;
  7484. char chargingRateUnitStr[4]={0};
  7485. char comfirmstr[20];
  7486. int confirmPeriods = 0;
  7487. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  7488. json_object *GetCompositeSchedule;
  7489. GetCompositeSchedule = json_tokener_parse(payload);
  7490. if(!is_error(GetCompositeSchedule))
  7491. {
  7492. // Required data
  7493. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  7494. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  7495. else
  7496. connectorIdInt = -1;
  7497. if(json_object_object_get(GetCompositeSchedule, "duration"))
  7498. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  7499. else
  7500. durationInt = 86400;
  7501. // Optional data
  7502. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  7503. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  7504. }
  7505. json_object_put(GetCompositeSchedule);
  7506. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  7507. if((connectorIdInt == 0) ||
  7508. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  7509. {
  7510. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  7511. struct StructChargingProfile tmpProfile[1];
  7512. if(strstr(chargingRateUnitStr, "W") != NULL)
  7513. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  7514. else
  7515. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  7516. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7517. {
  7518. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7519. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7520. }
  7521. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  7522. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  7523. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  7524. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7525. {
  7526. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7527. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7528. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  7529. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0))
  7530. {
  7531. confirmPeriods = idx;
  7532. break;
  7533. }
  7534. }
  7535. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  7536. }
  7537. else
  7538. {
  7539. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  7540. }
  7541. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  7542. return result;
  7543. }
  7544. int handleGetConfigurationRequest(char *uuid, char *payload)
  7545. {
  7546. mtrace();
  7547. int result = FAIL;
  7548. int MaxKeySupported = 0;
  7549. int n_keys = 0;
  7550. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  7551. DEBUG_INFO("handleGetConfigurationRequest...\n");
  7552. json_object *GetConfiguration;
  7553. GetConfiguration = json_tokener_parse(payload);
  7554. if(!is_error(GetConfiguration))
  7555. {
  7556. // Optional data
  7557. if(json_object_object_get(GetConfiguration, "key") != NULL)
  7558. {
  7559. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  7560. {
  7561. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  7562. n_keys = idx + 1;
  7563. }
  7564. }
  7565. }
  7566. json_object_put(GetConfiguration);
  7567. UnknownKeynum = 0;
  7568. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  7569. MaxKeySupported = GetConfigurationMaxKeysNUM;
  7570. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  7571. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  7572. if(n_keys != 0)
  7573. {
  7574. for(int i=0;i<n_keys;i++)
  7575. {
  7576. getKeyValue(requestKey[i]);
  7577. }
  7578. }
  7579. else
  7580. {
  7581. DEBUG_INFO("There is no key in Message, get all configuration\n");
  7582. getKeyValue("");
  7583. }
  7584. processUnkownKey();
  7585. sendGetConfigurationConfirmation(uuid);
  7586. return result;
  7587. }
  7588. static char fnamePlusPath[100]={0};
  7589. static char fnamePWithNoPath[60]={0};
  7590. void checkUploadLog(void)
  7591. {
  7592. FILE *fp;
  7593. /* Open the command for reading. */
  7594. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  7595. if (fp == NULL) {
  7596. printf("Failed to run command\n" );
  7597. exit(1);
  7598. }
  7599. int ftppathlen = 0;
  7600. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  7601. int i = 0;
  7602. /* Read the output a line at a time - output it. */
  7603. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  7604. if(i==0)
  7605. {
  7606. ftppathlen = strlen(fnamePlusPath);
  7607. printf("%s\n", fnamePlusPath);
  7608. fnamePlusPath[ftppathlen]='\0';
  7609. break;
  7610. }
  7611. i= i+1;
  7612. }
  7613. /* close */
  7614. pclose(fp);
  7615. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  7616. {
  7617. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  7618. {
  7619. fnamePlusPath[k]='\0';
  7620. }
  7621. }
  7622. i=1;
  7623. //char fname[60]={0};
  7624. while(i < ftppathlen)
  7625. {
  7626. int len=ftppathlen-i;
  7627. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  7628. {
  7629. printf("compare '/' all right\n");
  7630. break;
  7631. }
  7632. i=i+1;
  7633. }
  7634. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  7635. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  7636. fnamePWithNoPath[i+1] = '\0';
  7637. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  7638. {
  7639. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  7640. {
  7641. fnamePWithNoPath[j]='\0';
  7642. }
  7643. }
  7644. FILE* fp1 = fopen(fnamePlusPath, "r");
  7645. if (fp1)
  7646. {
  7647. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  7648. // file exists
  7649. fclose(fp1);
  7650. }
  7651. else
  7652. {
  7653. // file doesn't exist
  7654. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  7655. }
  7656. }
  7657. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  7658. {
  7659. mtrace();
  7660. int result = FAIL;
  7661. time_t CurrentTime;
  7662. struct tm *tm;
  7663. pthread_t th_Status;
  7664. CurrentTime = time(NULL);
  7665. tm = localtime(&CurrentTime);
  7666. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  7667. 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);
  7668. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  7669. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  7670. return result;
  7671. }
  7672. void* GetDiagnosticsProcess(void* data)
  7673. {
  7674. pthread_detach(pthread_self());
  7675. mtrace();
  7676. int retriesInt=0, retryIntervalInt=0;
  7677. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  7678. 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};
  7679. int port=0;
  7680. int isSuccess = FALSE;
  7681. char ftpbuf[200]={0};
  7682. char cmdBuf[2048];
  7683. struct tm *tmNow;
  7684. time_t CurrentTime;
  7685. struct tm tmStart;
  7686. struct tm tmStop;
  7687. CurrentTime = time(NULL);
  7688. tmNow=localtime(&CurrentTime);
  7689. uint16_t targetYear, targetMonth;
  7690. json_object *GetDiagnostics;
  7691. DEBUG_INFO("GetDiagnosticsProcess...\n");
  7692. GetDiagnostics = json_tokener_parse(data);
  7693. if(!is_error(GetDiagnostics))
  7694. {
  7695. // Required data
  7696. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  7697. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  7698. // Optional data
  7699. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  7700. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  7701. else
  7702. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  7703. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  7704. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  7705. else
  7706. retryIntervalInt = 30;
  7707. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  7708. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  7709. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  7710. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  7711. }
  7712. json_object_put(GetDiagnostics);
  7713. // Pack log to compress file
  7714. 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) &&
  7715. (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))
  7716. {
  7717. // Pack system log
  7718. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  7719. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  7720. targetYear = tmStart.tm_year;
  7721. targetMonth = tmStart.tm_mon;
  7722. do
  7723. {
  7724. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7725. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7726. if(targetMonth+1>=13)
  7727. {
  7728. targetYear += 1;
  7729. targetMonth = 1;
  7730. }
  7731. else
  7732. {
  7733. targetMonth += 1;
  7734. }
  7735. }while((targetYear < (tmNow->tm_year+1900)) ||
  7736. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  7737. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  7738. system(cmdBuf);
  7739. // Pack charging & event log
  7740. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  7741. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  7742. targetYear = tmStart.tm_year;
  7743. targetMonth = tmStart.tm_mon;
  7744. do
  7745. {
  7746. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7747. if(targetMonth+1>=13)
  7748. {
  7749. targetYear += 1;
  7750. targetMonth = 1;
  7751. }
  7752. else
  7753. {
  7754. targetMonth += 1;
  7755. }
  7756. }while((targetYear < (tmNow->tm_year+1900)) ||
  7757. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  7758. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  7759. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  7760. system(cmdBuf);
  7761. // Combine log file
  7762. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  7763. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  7764. }
  7765. else
  7766. {
  7767. system("exec /root/logPackTools 'log' 6");
  7768. }
  7769. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  7770. system(cmdBuf);
  7771. checkUploadLog();
  7772. //****************location*******************/
  7773. if(strcmp(locationstr,"")==0)
  7774. {
  7775. DEBUG_INFO("location is <Empty>!\n");
  7776. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7777. goto end;
  7778. }
  7779. memset(protocol, 0, ARRAY_SIZE(protocol));
  7780. memset(user, 0, ARRAY_SIZE(user) );
  7781. memset(password, 0, ARRAY_SIZE(password));
  7782. memset(host, 0, ARRAY_SIZE(host));
  7783. memset(path, 0, ARRAY_SIZE(path));
  7784. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  7785. memset(host1, 0, ARRAY_SIZE(host1));
  7786. memset(path1, 0, ARRAY_SIZE(path1));
  7787. /*location: ftp://user:password@host:port/path*/
  7788. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  7789. if((access(fnamePlusPath,F_OK))!=-1)
  7790. {
  7791. DEBUG_INFO("fnamePlusPath exist.\n");
  7792. }
  7793. else
  7794. {
  7795. DEBUG_INFO("fnamePlusPath not exist!\n");
  7796. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7797. goto end;
  7798. }
  7799. if(strchr(locationstr,'@')==NULL)
  7800. {
  7801. sscanf(locationstr,
  7802. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  7803. protocol, host, &port, path);
  7804. strcpy(user,"anonymous");
  7805. strcpy(password,"");
  7806. }
  7807. else
  7808. {
  7809. //DEBUG_INFO("pch=%s\n", pch);
  7810. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  7811. protocol, user, password, host, &port, path);
  7812. }
  7813. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  7814. {
  7815. DEBUG_INFO("protocol is not ftp/http ! \n");
  7816. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7817. goto end;
  7818. }
  7819. if(strncmp(locationstr,"http", 4) == 0)
  7820. {
  7821. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  7822. sprintf(ftppath,"/%s", path);
  7823. do
  7824. {
  7825. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  7826. sleep(3);
  7827. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  7828. if(!isSuccess)
  7829. {
  7830. DEBUG_INFO("Diagnostics fail.\n");
  7831. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7832. sleep(retryIntervalInt);
  7833. }
  7834. else
  7835. {
  7836. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  7837. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  7838. }
  7839. retriesInt--;
  7840. }while((isSuccess == 0)&&(retriesInt >= 0));
  7841. }
  7842. else
  7843. {
  7844. sscanf(host,"%[^/]%s",host1, path1);
  7845. if(strlen(path) > 0)
  7846. sprintf(ftppath,"/%s", path);
  7847. else
  7848. sprintf(ftppath,"/%s", path1);
  7849. int ftppathlen=strlen(ftppath);
  7850. int i=1;
  7851. char filenametemp[50];
  7852. while(i < ftppathlen)
  7853. {
  7854. int len=ftppathlen-i;
  7855. if(ftppath[len]== 47) // '/' ascll code: 47
  7856. {
  7857. DEBUG_INFO("find '/' all right\n");
  7858. break;
  7859. }
  7860. i=i+1;
  7861. }
  7862. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  7863. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  7864. filenametemp[i+1] = 0;
  7865. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  7866. if(port == 0)
  7867. port = 21;
  7868. do
  7869. {
  7870. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  7871. sleep(3);
  7872. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  7873. if(!isSuccess)
  7874. {
  7875. DEBUG_INFO("Diagnostics fail.\n");
  7876. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7877. sleep(retryIntervalInt);
  7878. }
  7879. else
  7880. {
  7881. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  7882. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  7883. }
  7884. retriesInt--;
  7885. }while((!isSuccess)&&(retriesInt >= 0));
  7886. }
  7887. end:
  7888. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  7889. system("rm -f /mnt/*");
  7890. pthread_exit(NULL);
  7891. }
  7892. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  7893. {
  7894. mtrace();
  7895. int result = FAIL;
  7896. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  7897. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  7898. {
  7899. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  7900. localversion = -1;
  7901. }
  7902. else
  7903. {
  7904. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  7905. OCPP_getListVerion();
  7906. }
  7907. //from db.OCPP_getListVerion
  7908. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  7909. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  7910. sendGetLocalListVersionConfirmation(uuid,"");
  7911. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  7912. return result;
  7913. }
  7914. int handleRemoteStartRequest(char *uuid, char *payload)
  7915. {
  7916. mtrace();
  7917. int result = FAIL;
  7918. int connectorIdInt=0;
  7919. int tempIndex = 0;
  7920. int connectorIdIsNULL, chargingProfileIsNULL;
  7921. char comfirmstr[20]={0};
  7922. char cmdBuf[512];
  7923. json_object *RemoteStartTransaction;
  7924. FILE *fp;
  7925. DEBUG_INFO("handleRemoteStartRequest ...\n");
  7926. if(server_pending == TRUE)
  7927. {
  7928. return 0;
  7929. }
  7930. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  7931. RemoteStartTransaction = json_tokener_parse(payload);
  7932. if(!is_error(RemoteStartTransaction))
  7933. {
  7934. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  7935. {
  7936. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  7937. if(connectorIdInt <= gunTotalNumber)
  7938. {
  7939. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  7940. // Required data
  7941. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  7942. // Optional data
  7943. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  7944. {
  7945. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  7946. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  7947. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  7948. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  7949. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  7950. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  7951. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  7952. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  7953. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  7954. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  7955. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  7956. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  7957. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  7958. {
  7959. 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")));
  7960. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  7961. 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"));
  7962. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  7963. 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"));
  7964. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  7965. 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")));
  7966. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  7967. {
  7968. 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++)
  7969. {
  7970. 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"));
  7971. 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"));
  7972. 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)
  7973. 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"));
  7974. }
  7975. }
  7976. }
  7977. }
  7978. else
  7979. chargingProfileIsNULL = TRUE;
  7980. }
  7981. }
  7982. else
  7983. connectorIdIsNULL = TRUE;
  7984. }
  7985. else
  7986. connectorIdIsNULL = TRUE;
  7987. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  7988. {
  7989. DEBUG_WARN("Connector id is NULL\n.");
  7990. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7991. goto end;
  7992. }
  7993. /*
  7994. enum _SYSTEM_STATUS
  7995. {
  7996. S_BOOTING = 0,
  7997. S_IDLE, = 1
  7998. S_AUTHORIZING, = 2
  7999. S_REASSIGN_CHECK, = 3
  8000. S_REASSIGN, = 4
  8001. S_PRECHARGE, = 5
  8002. S_PREPARING_FOR_EV, = 6
  8003. S_PREPARING_FOR_EVSE, = 7
  8004. S_CHARGING, = 8
  8005. S_TERMINATING, = 9
  8006. S_COMPLETE, = 10
  8007. S_ALARM, = 11
  8008. S_FAULT = 12
  8009. }
  8010. */
  8011. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  8012. {
  8013. //check Transaction active
  8014. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8015. {
  8016. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8017. {
  8018. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8019. }
  8020. else
  8021. {
  8022. tempIndex = connectorIdInt -1;
  8023. }
  8024. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8025. {
  8026. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  8027. {
  8028. 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))
  8029. {
  8030. //Reserved
  8031. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8032. }
  8033. 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))
  8034. {
  8035. //Reserved
  8036. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8037. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8038. goto end;
  8039. }
  8040. else
  8041. {
  8042. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8043. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  8044. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  8045. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  8046. {
  8047. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  8048. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8049. goto end;
  8050. }
  8051. }//END FOR ELSE
  8052. }
  8053. }// END FOR CHAdeMO_QUANTITY
  8054. }
  8055. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8056. {
  8057. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8058. {
  8059. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8060. }
  8061. else
  8062. {
  8063. tempIndex = connectorIdInt -1;
  8064. }
  8065. for (int index = 0; index < CCS_QUANTITY; index++)
  8066. {
  8067. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8068. {
  8069. 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))
  8070. {
  8071. //Reserved
  8072. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8073. }
  8074. 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))
  8075. {
  8076. //Reserved
  8077. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8078. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8079. goto end;
  8080. }
  8081. else
  8082. {
  8083. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8084. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8085. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8086. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8087. {
  8088. DEBUG_WARN("CCS connector not allow start\n.");
  8089. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8090. goto end;
  8091. }
  8092. }// END FOR ELSE
  8093. }
  8094. }// END FOR CCS_QUANTITY
  8095. }
  8096. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8097. {
  8098. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8099. {
  8100. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8101. }
  8102. else
  8103. {
  8104. tempIndex = connectorIdInt -1;
  8105. }
  8106. for (int index = 0; index < GB_QUANTITY; index++)
  8107. {
  8108. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  8109. {
  8110. 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))
  8111. {
  8112. //Reserved
  8113. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8114. }
  8115. 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))
  8116. {
  8117. //Reserved
  8118. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8119. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8120. goto end;
  8121. }
  8122. else
  8123. {
  8124. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8125. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8126. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8127. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8128. {
  8129. DEBUG_WARN("GB connector not allow start\n.");
  8130. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8131. goto end;
  8132. }
  8133. }// END FOR ELSE
  8134. }
  8135. } // END FOR GB_QUANTITY
  8136. }
  8137. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8138. {
  8139. tempIndex = connectorIdInt -1;
  8140. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8141. {
  8142. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  8143. {
  8144. 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))
  8145. {
  8146. //Reserved
  8147. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8148. }
  8149. 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))
  8150. {
  8151. //Reserved
  8152. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8153. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8154. goto end;
  8155. }
  8156. else
  8157. {
  8158. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8159. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8160. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8161. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8162. {
  8163. DEBUG_WARN("GB connector not allow start\n.");
  8164. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8165. goto end;
  8166. }
  8167. }// END FOR ELSE
  8168. }
  8169. } // END FOR GB_QUANTITY
  8170. }
  8171. else
  8172. {
  8173. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8174. {
  8175. tempIndex = 2;
  8176. }
  8177. else
  8178. {
  8179. tempIndex = connectorIdInt -1;
  8180. }
  8181. for (int index = 0; index < AC_QUANTITY; index++)
  8182. {
  8183. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  8184. {
  8185. 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))
  8186. {
  8187. //Reserved
  8188. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8189. }
  8190. 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))
  8191. {
  8192. //Reserved
  8193. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8194. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8195. goto end;
  8196. }
  8197. else
  8198. {
  8199. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8200. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8201. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8202. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8203. {
  8204. DEBUG_WARN("AC connector not allow start\n.");
  8205. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8206. goto end;
  8207. }
  8208. }//END FOR ELSE
  8209. }
  8210. }// END FOR AC_QUANTITY
  8211. }
  8212. if(chargingProfileIsNULL == FALSE)
  8213. {
  8214. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8215. {
  8216. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  8217. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8218. //memset idTag
  8219. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  8220. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8221. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  8222. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8223. // Save profile to file
  8224. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8225. system(cmdBuf);
  8226. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8227. fp = fopen(cmdBuf, "w");
  8228. 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));
  8229. fclose(fp);
  8230. }
  8231. else
  8232. {
  8233. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  8234. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8235. }
  8236. }
  8237. else
  8238. {
  8239. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  8240. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8241. //memset idTag
  8242. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  8243. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8244. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  8245. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8246. }
  8247. }
  8248. else
  8249. {
  8250. DEBUG_WARN("Connector id over\n.");
  8251. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8252. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  8253. }
  8254. end:
  8255. json_object_put(RemoteStartTransaction);
  8256. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  8257. {
  8258. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  8259. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  8260. }
  8261. //OCPP send RemoteStartConfirmation by first.
  8262. sendRemoteStartConfirmation(uuid, comfirmstr);
  8263. return result;
  8264. }
  8265. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  8266. {
  8267. mtrace();
  8268. int result = FAIL;
  8269. int match = FALSE;
  8270. int GunNO = 0;
  8271. int tempIndex = 0;
  8272. int transactionIdInt=0;
  8273. int transactionIdIsNULL= TRUE;
  8274. char comfirmstr[20];
  8275. json_object *RemoteStopTransaction;
  8276. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  8277. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  8278. if(server_pending == TRUE)
  8279. {
  8280. return 0;
  8281. }
  8282. RemoteStopTransaction = json_tokener_parse(payload);
  8283. if(!is_error(RemoteStopTransaction))
  8284. {
  8285. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  8286. {
  8287. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  8288. transactionIdIsNULL = FALSE;
  8289. }
  8290. }
  8291. json_object_put(RemoteStopTransaction);
  8292. if(transactionIdIsNULL == FALSE)
  8293. {
  8294. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  8295. {
  8296. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  8297. {
  8298. //check Transaction active
  8299. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  8300. {
  8301. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8302. {
  8303. tempIndex = ((gun_index==2) ? 1: 0);
  8304. }
  8305. else
  8306. {
  8307. tempIndex = gun_index;
  8308. }
  8309. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8310. {
  8311. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8312. {
  8313. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8314. {
  8315. match = TRUE;
  8316. GunNO = gun_index;
  8317. }
  8318. }
  8319. }// END FOR CHAdeMO_QUANTITY
  8320. }
  8321. else if(gunType[gun_index] == GUN_TYPE_CCS)
  8322. {
  8323. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8324. {
  8325. tempIndex = ((gun_index==2) ? 1: 0);
  8326. }
  8327. else
  8328. {
  8329. tempIndex = gun_index;
  8330. }
  8331. for (int index = 0; index < CCS_QUANTITY; index++)
  8332. {
  8333. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8334. {
  8335. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8336. {
  8337. match = TRUE;
  8338. GunNO = gun_index;
  8339. }
  8340. }
  8341. }// END FOR CCS_QUANTITY
  8342. }
  8343. else if(gunType[gun_index] == GUN_TYPE_GBT)
  8344. {
  8345. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8346. {
  8347. tempIndex = ((gun_index==2) ? 1: 0);
  8348. }
  8349. else
  8350. {
  8351. tempIndex = gun_index;
  8352. }
  8353. for (int index = 0; index < GB_QUANTITY; index++)
  8354. {
  8355. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8356. {
  8357. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8358. {
  8359. match = TRUE;
  8360. GunNO = gun_index;
  8361. }
  8362. }
  8363. }// END FOR GB_QUANTITY
  8364. }
  8365. else if(gunType[gun_index] == GUN_TYPE_DO)
  8366. {
  8367. tempIndex = gun_index;
  8368. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8369. {
  8370. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8371. {
  8372. 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
  8373. {
  8374. match = TRUE;
  8375. GunNO = gun_index;
  8376. }
  8377. }
  8378. }// END FOR GB_QUANTITY
  8379. }
  8380. else
  8381. {
  8382. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8383. {
  8384. tempIndex = 2;
  8385. }
  8386. else
  8387. {
  8388. tempIndex = gun_index;
  8389. }
  8390. for (int index = 0; index < AC_QUANTITY; index++)
  8391. {
  8392. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8393. {
  8394. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8395. {
  8396. match = TRUE;
  8397. GunNO = gun_index;
  8398. }
  8399. }
  8400. }// END FOR CHAdeMO_QUANTITY
  8401. } // END FOR AC ELSE
  8402. }// CHECK IF ResponseTransactionId == transactionIdInt
  8403. }//END FOR
  8404. if( match == TRUE)
  8405. {
  8406. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  8407. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8408. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  8409. }
  8410. else
  8411. {
  8412. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8413. }
  8414. }
  8415. else
  8416. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8417. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  8418. return result;
  8419. }
  8420. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  8421. {
  8422. mtrace();
  8423. int result = FAIL;
  8424. int connectorIdInt=0, reservationIdInt=0;
  8425. int tempIndex = 0;
  8426. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  8427. char comfirmstr[20]={0};
  8428. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  8429. int c = 0;
  8430. char *loc;
  8431. //char *ptr;
  8432. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  8433. strcpy(sstrtemp, stringtrimspace(payload));
  8434. //***(1)connectorId ****/
  8435. c=0;
  8436. loc = strstr(sstrtemp, "connectorId");
  8437. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8438. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  8439. {
  8440. sstr[c] = loc[strlen("connectorId")+2+c];
  8441. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8442. c++;
  8443. }
  8444. sstr[c] = '\0';
  8445. connectorIdInt = atoi(sstr);
  8446. //***(2)expiryDate ****/
  8447. loc = strstr(sstrtemp, "expiryDate");
  8448. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8449. c = 0;
  8450. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  8451. {
  8452. sstr[c] = loc[3+strlen("expiryDate")+c];
  8453. c++;
  8454. }
  8455. sstr[c] = '\0';
  8456. strcpy(expiryDatestr, sstr);
  8457. //***(3)idTag ****/
  8458. loc = strstr(sstrtemp, "idTag");
  8459. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8460. c = 0;
  8461. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  8462. {
  8463. sstr[c] = loc[3+strlen("idTag")+c];
  8464. c++;
  8465. }
  8466. sstr[c] = '\0';
  8467. strcpy(idTagstr, sstr);
  8468. //***(4)parentIdTag ****/
  8469. loc = strstr(sstrtemp, "parentIdTag");
  8470. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8471. c = 0;
  8472. if(loc == NULL)
  8473. {
  8474. strcpy(parentIdTagstr, "");
  8475. }
  8476. else
  8477. {
  8478. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8479. {
  8480. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8481. c++;
  8482. }
  8483. sstr[c] = '\0';
  8484. strcpy(parentIdTagstr, sstr);
  8485. }
  8486. //***(5)reservationId ****/
  8487. c=0;
  8488. loc = strstr(sstrtemp, "reservationId");
  8489. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8490. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  8491. {
  8492. sstr[c] = loc[strlen("reservationId")+2+c];
  8493. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8494. c++;
  8495. }
  8496. sstr[c] = '\0';
  8497. reservationIdInt = atoi(sstr);
  8498. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8499. /*
  8500. enum SYSTEM_STATUS
  8501. {
  8502. SYS_MODE_BOOTING = 0,
  8503. SYS_MODE_IDLE = 1,
  8504. SYS_MODE_AUTHORIZING = 2,
  8505. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  8506. SYS_MODE_REASSIGN = 4,
  8507. SYS_MODE_PREPARING = 5,
  8508. SYS_MODE_PREPARE_FOR_EV = 6,
  8509. SYS_MODE_PREPARE_FOR_EVSE = 7,
  8510. SYS_MODE_CHARGING = 8,
  8511. SYS_MODE_TERMINATING = 9,
  8512. SYS_MODE_COMPLETE = 10,
  8513. SYS_MODE_ALARM = 11,
  8514. SYS_MODE_FAULT = 12,
  8515. SYS_MODE_RESERVATION = 13,
  8516. SYS_MODE_BOOKING = 14,
  8517. SYS_MODE_MAINTAIN = 15,
  8518. SYS_MODE_DEBUG = 16,
  8519. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  8520. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  8521. SYS_MODE_UPDATE = 19
  8522. };
  8523. */
  8524. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  8525. {
  8526. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8527. goto end;
  8528. }
  8529. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  8530. {
  8531. //check Transaction active
  8532. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8533. {
  8534. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8535. {
  8536. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8537. }
  8538. else
  8539. {
  8540. tempIndex = connectorIdInt -1;
  8541. }
  8542. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8543. {
  8544. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8545. {
  8546. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  8547. {
  8548. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8549. {
  8550. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8551. {
  8552. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8553. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8554. }
  8555. 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'))
  8556. {
  8557. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8558. }
  8559. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8560. {
  8561. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8562. }
  8563. else
  8564. {
  8565. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8566. }
  8567. }
  8568. 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
  8569. {
  8570. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8571. }
  8572. }
  8573. else
  8574. {
  8575. //replace reservation
  8576. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8577. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8578. }
  8579. }
  8580. } // END FOR CHAdeMO_QUANTITY
  8581. }
  8582. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8583. {
  8584. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8585. {
  8586. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8587. }
  8588. else
  8589. {
  8590. tempIndex = connectorIdInt -1;
  8591. }
  8592. for (int index = 0; index < CCS_QUANTITY; index++)
  8593. {
  8594. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8595. {
  8596. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8597. {
  8598. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8599. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8600. {
  8601. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8602. {
  8603. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8604. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8605. }
  8606. 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'))
  8607. {
  8608. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8609. }
  8610. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  8611. {
  8612. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8613. }
  8614. else
  8615. {
  8616. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8617. }
  8618. }
  8619. 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
  8620. {
  8621. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8622. }
  8623. }
  8624. else
  8625. {
  8626. //replace reservation
  8627. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8628. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8629. }
  8630. }
  8631. } // END FOR CCS_QUANTITY
  8632. }
  8633. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8634. {
  8635. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8636. {
  8637. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8638. }
  8639. else
  8640. {
  8641. tempIndex = connectorIdInt -1;
  8642. }
  8643. for (int index = 0; index < GB_QUANTITY; index++)
  8644. {
  8645. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8646. {
  8647. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8648. {
  8649. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8650. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  8651. {
  8652. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8653. {
  8654. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8655. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8656. }
  8657. 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'))
  8658. {
  8659. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8660. }
  8661. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8662. {
  8663. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8664. }
  8665. else
  8666. {
  8667. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8668. }
  8669. }
  8670. 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
  8671. {
  8672. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8673. }
  8674. }
  8675. else
  8676. {
  8677. //replace reservation
  8678. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8679. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8680. }
  8681. }
  8682. }// END FOR GB_QUANTITY
  8683. }
  8684. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8685. {
  8686. tempIndex = connectorIdInt -1;
  8687. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8688. {
  8689. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8690. {
  8691. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  8692. {
  8693. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8694. 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
  8695. {
  8696. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8697. {
  8698. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8699. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8700. }
  8701. 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'))
  8702. {
  8703. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8704. }
  8705. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8706. {
  8707. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8708. }
  8709. else
  8710. {
  8711. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8712. }
  8713. }
  8714. 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
  8715. {
  8716. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8717. }
  8718. }
  8719. else
  8720. {
  8721. //replace reservation
  8722. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8723. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8724. }
  8725. }
  8726. }// END FOR GB_QUANTITY
  8727. }
  8728. else
  8729. {
  8730. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8731. {
  8732. tempIndex = 2;
  8733. }
  8734. else
  8735. {
  8736. tempIndex = (connectorIdInt -1);
  8737. }
  8738. for (int index = 0; index < AC_QUANTITY; index++)
  8739. {
  8740. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8741. {
  8742. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  8743. {
  8744. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  8745. {
  8746. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8747. {
  8748. 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))
  8749. {
  8750. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8751. }
  8752. else
  8753. {
  8754. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8755. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8756. }
  8757. }
  8758. 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'))
  8759. {
  8760. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8761. }
  8762. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8763. {
  8764. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8765. }
  8766. else
  8767. {
  8768. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8769. }
  8770. }
  8771. 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
  8772. {
  8773. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8774. }
  8775. }
  8776. else
  8777. {
  8778. //replace reservation
  8779. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8780. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8781. }
  8782. }
  8783. } // END FOR AC_QUANTITY
  8784. }
  8785. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8786. }
  8787. else if(connectorIdInt == 0)
  8788. {
  8789. //check Transaction active
  8790. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8791. {
  8792. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  8793. {
  8794. 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'))
  8795. {
  8796. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8797. goto end;
  8798. }
  8799. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8800. {
  8801. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8802. goto end;
  8803. }
  8804. 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
  8805. {
  8806. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8807. goto end;
  8808. }
  8809. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8810. {
  8811. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8812. goto end;
  8813. }
  8814. }
  8815. }// END FOR CHAdeMO_QUANTITY
  8816. for (int index = 0; index < CCS_QUANTITY; index++)
  8817. {
  8818. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8819. {
  8820. 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'))
  8821. {
  8822. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8823. goto end;
  8824. }
  8825. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  8826. {
  8827. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8828. goto end;
  8829. }
  8830. 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
  8831. {
  8832. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8833. goto end;
  8834. }
  8835. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8836. {
  8837. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8838. goto end;
  8839. }
  8840. }
  8841. } // END FOR CCS_QUANTITY
  8842. for (int index = 0; index < GB_QUANTITY; index++)
  8843. {
  8844. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8845. {
  8846. 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'))
  8847. {
  8848. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8849. goto end;
  8850. }
  8851. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8852. {
  8853. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8854. goto end;
  8855. }
  8856. 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
  8857. {
  8858. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8859. goto end;
  8860. }
  8861. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8862. {
  8863. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8864. goto end;
  8865. }
  8866. }
  8867. } // END FOR GB_QUANTITY
  8868. for (int index = 0; index < AC_QUANTITY; index++)
  8869. {
  8870. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  8871. {
  8872. 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'))
  8873. {
  8874. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8875. goto end;
  8876. }
  8877. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8878. {
  8879. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8880. goto end;
  8881. }
  8882. 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
  8883. {
  8884. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8885. goto end;
  8886. }
  8887. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8888. {
  8889. 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))
  8890. {
  8891. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8892. goto end;
  8893. }
  8894. }
  8895. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8896. {
  8897. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8898. goto end;
  8899. }
  8900. }
  8901. }// END FOR AC_QUANTITY
  8902. //The connectorId is 0
  8903. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  8904. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8905. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  8906. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  8907. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  8908. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  8909. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  8910. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  8911. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  8912. result = TRUE;
  8913. return result;
  8914. }
  8915. else
  8916. {
  8917. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8918. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8919. }
  8920. if(strcmp(comfirmstr,"Accepted") == 0)
  8921. {
  8922. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  8923. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  8924. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  8925. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  8926. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  8927. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  8928. result = TRUE;
  8929. return result;
  8930. }
  8931. end:
  8932. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  8933. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  8934. return result;
  8935. }
  8936. int handleResetRequest(char *uuid, char *payload)
  8937. {
  8938. mtrace();
  8939. int result = FAIL;
  8940. char sstr[10]={0},sstrtemp[30]={ 0 };
  8941. char typestr[10]={0};
  8942. char comfirmstr[20]={0};
  8943. int c = 0;
  8944. char *loc;
  8945. DEBUG_INFO("handleResetRequest...\n");
  8946. strcpy(sstrtemp, stringtrimspace(payload));
  8947. loc = strstr(sstrtemp, "type");
  8948. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8949. c = 0;
  8950. while (loc[3+strlen("type")+c] != '\"')
  8951. {
  8952. sstr[c] = loc[3+strlen("type")+c];
  8953. c++;
  8954. }
  8955. sstr[c] = '\0';
  8956. strcpy(typestr,sstr);
  8957. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  8958. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  8959. {
  8960. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  8961. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  8962. result = TRUE;
  8963. return result;
  8964. }
  8965. else
  8966. {
  8967. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  8968. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  8969. goto errorend;
  8970. }
  8971. errorend:
  8972. sendResetConfirmation(uuid, comfirmstr);
  8973. return result;
  8974. }
  8975. int handleSendLocalListRequest(char *uuid, char *payload)
  8976. {
  8977. mtrace();
  8978. int result = FAIL;
  8979. int listVersionInt;
  8980. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  8981. char listsearch[]="listVersion";
  8982. char updateTypesearch[]="updateType";
  8983. char localAuthorizationListsearch[]="localAuthorizationList";
  8984. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  8985. char CardList[500][160]={0};
  8986. char updateTypestr[15]={0};
  8987. char idTagstr[20]={0};
  8988. char parentIdTag[20]={0};
  8989. char expiryDate[30]={0};
  8990. char idTagstatus[16]={0};
  8991. int c = 0;
  8992. int i = 0;
  8993. char *delim1 = "}";
  8994. char * pch;
  8995. char *loc;
  8996. //char *ptr;
  8997. char comfirmstr[20];
  8998. //int n_localAuthorizations = 0;
  8999. int checkState_Faulted = FALSE;
  9000. DEBUG_INFO("handleSendLocalListRequest...\n");
  9001. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  9002. {
  9003. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9004. goto end;
  9005. }
  9006. //check Charge Point state
  9007. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9008. {
  9009. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9010. {
  9011. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9012. }
  9013. }
  9014. for (int index = 0; index < CCS_QUANTITY; index++)
  9015. {
  9016. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9017. {
  9018. checkState_Faulted = TRUE; //OCPP Status
  9019. }
  9020. }
  9021. for (int index = 0; index < GB_QUANTITY; index++)
  9022. {
  9023. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9024. {
  9025. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9026. }
  9027. }
  9028. //check Charge Point state
  9029. for (int index = 0; index < AC_QUANTITY; index++)
  9030. {
  9031. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9032. {
  9033. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9034. }
  9035. }
  9036. if(checkState_Faulted == TRUE)
  9037. {
  9038. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9039. goto end;
  9040. }
  9041. //Filter payload space
  9042. strcpy(sstrtemp, stringtrimspace(payload));
  9043. //listVersion
  9044. c = 0;
  9045. loc = strstr(sstrtemp, listsearch);
  9046. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  9047. {
  9048. sstr[c] = loc[strlen("listVersion")+2+c];
  9049. c++;
  9050. }
  9051. sstr[c] = '\0';
  9052. listVersionInt = atoi(sstr);
  9053. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  9054. //updateType
  9055. loc = strstr(sstrtemp, updateTypesearch);
  9056. c = 0;
  9057. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  9058. {
  9059. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  9060. c++;
  9061. }
  9062. sstr[c] = '\0';
  9063. strcpy(updateTypestr, sstr);
  9064. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  9065. //localAuthorizationList
  9066. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9067. loc = strstr(sstrtemp, localAuthorizationListsearch);
  9068. if(loc != NULL) // localAuthorizationList is not NULL
  9069. {
  9070. //Check UpdateType
  9071. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  9072. {
  9073. //Local list full update
  9074. printf("Local list full update.\n");
  9075. OCPP_getListVerion();
  9076. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  9077. {
  9078. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9079. goto end;
  9080. }
  9081. OCPP_cleanLocalList();
  9082. }
  9083. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  9084. {
  9085. //Local list different update
  9086. printf("Local list different update.\n");
  9087. OCPP_getListVerion();
  9088. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  9089. {
  9090. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  9091. goto end;
  9092. }
  9093. }
  9094. else
  9095. {
  9096. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9097. goto end;
  9098. }
  9099. c = 0;
  9100. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  9101. {
  9102. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  9103. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9104. c++;
  9105. }
  9106. sstr[c] = '\0';
  9107. //DEBUG_INFO("sstr=%s\n", sstr);
  9108. //parsing strings to words
  9109. i = 0;
  9110. pch = strtok(sstr,delim1);
  9111. while (pch != NULL)
  9112. {
  9113. strcpy(CardList[i], pch);
  9114. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  9115. pch = strtok (NULL, delim1);
  9116. i = i + 1;
  9117. }
  9118. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  9119. //local Authorizations List Numbers
  9120. //n_localAuthorizations = i;
  9121. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  9122. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  9123. c= 0;
  9124. while(c < i) // i is CardList Number
  9125. {
  9126. //Search "IdToken"
  9127. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9128. loc = strstr(CardList[c], "idTag");
  9129. int j = 0;
  9130. while (loc[3+strlen("idTag")+j] != '\"')
  9131. {
  9132. sstr[j] = loc[3+strlen("idTag")+j];
  9133. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9134. j++;
  9135. }
  9136. sstr[j] = '\0';
  9137. strcpy(idTagstr, sstr);
  9138. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  9139. //Search "expiryDate"
  9140. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9141. loc = strstr(CardList[c], "expiryDate");
  9142. j = 0;
  9143. if(loc != NULL)
  9144. {
  9145. while (loc[3+strlen("expiryDate")+j] != '\"')
  9146. {
  9147. sstr[j] = loc[3+strlen("expiryDate")+j];
  9148. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9149. j++;
  9150. }
  9151. sstr[j] = '\0';
  9152. strcpy(expiryDate, sstr);
  9153. }
  9154. else
  9155. {
  9156. strcpy(expiryDate, "");
  9157. }
  9158. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  9159. //Search "parentIdTag"
  9160. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9161. loc = strstr(CardList[c], "parentIdTag");
  9162. j = 0;
  9163. if(loc != NULL)
  9164. {
  9165. while (loc[3+strlen("parentIdTag")+j] != '\"')
  9166. {
  9167. sstr[j] = loc[3+strlen("parentIdTag")+j];
  9168. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9169. j++;
  9170. }
  9171. sstr[j] = '\0';
  9172. strcpy(parentIdTag, sstr);
  9173. }
  9174. else
  9175. {
  9176. strcpy(parentIdTag, "");
  9177. }
  9178. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  9179. //Search "status"
  9180. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9181. loc = strstr(CardList[c], "status");
  9182. j = 0;
  9183. while (loc[3+strlen("status")+j] != '\"')
  9184. {
  9185. sstr[j] = loc[3+strlen("status")+j];
  9186. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9187. j++;
  9188. }
  9189. sstr[j] = '\0';
  9190. strcpy(idTagstatus, sstr);
  9191. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  9192. OCPP_getIdTagFromLocalList(idTagstr);
  9193. //OCPP_getIdTagFromLocalList("test"); For Test
  9194. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  9195. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  9196. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  9197. {
  9198. //Local list full update
  9199. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  9200. // update list
  9201. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  9202. //DEBUG_INFO("Local list full update. 1\n");
  9203. //OCPP_get_TableAuthlocalAllData();
  9204. //DEBUG_INFO("Local list full update. 2\n");
  9205. }
  9206. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  9207. {
  9208. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  9209. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  9210. }
  9211. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  9212. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  9213. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  9214. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  9215. c++;
  9216. }
  9217. }
  9218. else
  9219. {
  9220. //Check UpdateType
  9221. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  9222. {
  9223. //Local list full update
  9224. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  9225. OCPP_cleanLocalList();
  9226. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9227. goto end;
  9228. }
  9229. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  9230. {
  9231. //Local list different update
  9232. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  9233. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9234. goto end;
  9235. }
  9236. }
  9237. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9238. end:
  9239. sendSendLocalListConfirmation(uuid, comfirmstr);
  9240. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  9241. return result;
  9242. }
  9243. #define MAX 200
  9244. int handleSetChargingProfileRequest(char *uuid, char *payload)
  9245. {
  9246. mtrace();
  9247. int result = FAIL;
  9248. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  9249. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  9250. char chargingProfilePurposeStr[30]={0};
  9251. char chargingProfileKindStr[16]={0};
  9252. char recurrencyKindStr[10]={0};
  9253. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  9254. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  9255. int chargingSchedulePeriodCount = 0;
  9256. char comfirmstr[20]={0};
  9257. int meet= FALSE;
  9258. FILE *fptr1;
  9259. char filename[MAX]={0};
  9260. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  9261. char rmFileCmd[50]={0};
  9262. char tempchargingProfilePurposeStr[30]={0};
  9263. char word[1600]={0};
  9264. int n_chargingProfile = 0;
  9265. json_object *SetChargingProfile;
  9266. DEBUG_INFO("handleSetChargingProfileRequest\n");
  9267. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  9268. SetChargingProfile = json_tokener_parse(payload);
  9269. if(!is_error(SetChargingProfile))
  9270. {
  9271. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  9272. {
  9273. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  9274. if(connectorIdInt == 0)
  9275. {
  9276. memset(&ShmOCPP16Data->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  9277. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  9278. }
  9279. else
  9280. {
  9281. memset(&ShmOCPP16Data->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  9282. ShmOCPP16Data->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  9283. }
  9284. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  9285. }
  9286. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  9287. {
  9288. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  9289. {
  9290. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  9291. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9292. {
  9293. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  9294. }
  9295. else
  9296. {
  9297. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  9298. }
  9299. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  9300. }
  9301. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  9302. {
  9303. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  9304. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9305. {
  9306. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  9307. }
  9308. else
  9309. {
  9310. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  9311. }
  9312. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  9313. }
  9314. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9315. {
  9316. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  9317. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9318. {
  9319. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  9320. }
  9321. else
  9322. {
  9323. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  9324. }
  9325. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  9326. }
  9327. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  9328. {
  9329. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  9330. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9331. {
  9332. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  9333. }
  9334. else
  9335. {
  9336. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  9337. }
  9338. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  9339. }
  9340. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  9341. {
  9342. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  9343. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9344. {
  9345. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  9346. }
  9347. else
  9348. {
  9349. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  9350. }
  9351. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  9352. }
  9353. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  9354. {
  9355. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  9356. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9357. {
  9358. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9359. }
  9360. else
  9361. {
  9362. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9363. }
  9364. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  9365. }
  9366. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  9367. {
  9368. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  9369. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9370. {
  9371. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  9372. }
  9373. else
  9374. {
  9375. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  9376. }
  9377. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  9378. }
  9379. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  9380. {
  9381. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  9382. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9383. {
  9384. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  9385. }
  9386. else
  9387. {
  9388. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  9389. }
  9390. //DEBUG_INFO("validToStr: %s\n", validToStr);
  9391. }
  9392. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  9393. {
  9394. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  9395. {
  9396. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  9397. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9398. {
  9399. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9400. }
  9401. else
  9402. {
  9403. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9404. }
  9405. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  9406. }
  9407. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  9408. {
  9409. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  9410. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9411. {
  9412. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9413. }
  9414. else
  9415. {
  9416. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9417. }
  9418. //DEBUG_INFO("durationInt: %d\n", durationInt);
  9419. }
  9420. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  9421. {
  9422. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  9423. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9424. {
  9425. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9426. }
  9427. else
  9428. {
  9429. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9430. }
  9431. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  9432. }
  9433. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  9434. {
  9435. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  9436. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9437. {
  9438. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9439. }
  9440. else
  9441. {
  9442. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9443. }
  9444. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  9445. }
  9446. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9447. {
  9448. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  9449. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  9450. if(chargingSchedulePeriodCount <= 10)
  9451. {
  9452. 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++)
  9453. {
  9454. 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)
  9455. {
  9456. 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"));
  9457. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9458. {
  9459. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9460. }
  9461. else
  9462. {
  9463. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9464. }
  9465. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  9466. }
  9467. 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)
  9468. {
  9469. 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"));
  9470. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9471. {
  9472. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9473. }
  9474. else
  9475. {
  9476. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9477. }
  9478. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  9479. }
  9480. 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)
  9481. {
  9482. 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"));
  9483. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9484. {
  9485. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9486. }
  9487. else
  9488. {
  9489. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9490. }
  9491. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  9492. }
  9493. }
  9494. }
  9495. }
  9496. }
  9497. }
  9498. }
  9499. json_object_put(SetChargingProfile);
  9500. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  9501. {
  9502. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9503. goto end;
  9504. }
  9505. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  9506. {
  9507. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  9508. if(connectorIdInt != 0)
  9509. {
  9510. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9511. goto end;
  9512. }
  9513. strcpy(filename, ChargePointMaxProfile_JSON );
  9514. fptr1 = fopen(filename, "r");
  9515. if (!fptr1)
  9516. {
  9517. //file not exist
  9518. DEBUG_INFO("Unable to open the input file!!\n");
  9519. fptr1 = fopen(filename, "w+");
  9520. }
  9521. else
  9522. {
  9523. //Check Charging Profile Count
  9524. while(fscanf(fptr1, "%s", word) != EOF)
  9525. {
  9526. //DEBUG_INFO("word=%s\n",word);
  9527. if(strstr(word, "chargingProfileId")!= NULL)
  9528. {
  9529. //DEBUG_INFO("test chargingProfileId \n");
  9530. n_chargingProfile = n_chargingProfile + 1;
  9531. //DEBUG_INFO("chargingProfileId Found\n");
  9532. }
  9533. }
  9534. }
  9535. fclose(fptr1);
  9536. }
  9537. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  9538. {
  9539. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  9540. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9541. {
  9542. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9543. goto end;
  9544. }
  9545. memset(filename, 0, ARRAY_SIZE(filename));
  9546. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9547. fptr1 = fopen(filename, "r");
  9548. if (!fptr1)
  9549. {
  9550. //file not exist
  9551. //DEBUG_INFO("Unable to open the input file!!\n");
  9552. fptr1 = fopen(filename, "w+");
  9553. }
  9554. else
  9555. {
  9556. //Check Charging Profile Count
  9557. while(fscanf(fptr1, "%s", word) != EOF)
  9558. {
  9559. //DEBUG_INFO("word=%s\n",word);
  9560. if(strstr(word, "chargingProfileId")!= NULL)
  9561. {
  9562. //DEBUG_INFO("test chargingProfileId \n");
  9563. n_chargingProfile = n_chargingProfile + 1;
  9564. //DEBUG_INFO("chargingProfileId Found\n");
  9565. }
  9566. }
  9567. }
  9568. fclose(fptr1);
  9569. }
  9570. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9571. {
  9572. //printf("set chargingProfile 1-4\n");
  9573. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  9574. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  9575. if(connectorIdInt == 0)
  9576. {
  9577. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9578. goto end;
  9579. }
  9580. int tempIndex = 0;
  9581. //check Transaction active
  9582. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9583. {
  9584. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9585. {
  9586. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9587. }
  9588. else
  9589. {
  9590. tempIndex = connectorIdInt -1;
  9591. }
  9592. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9593. {
  9594. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9595. {
  9596. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9597. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9598. {
  9599. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9600. {
  9601. meet = TRUE;
  9602. break;
  9603. }
  9604. }
  9605. }
  9606. }
  9607. }
  9608. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9609. {
  9610. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9611. {
  9612. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9613. }
  9614. else
  9615. {
  9616. tempIndex = connectorIdInt -1;
  9617. }
  9618. for (int index = 0; index < CCS_QUANTITY; index++)
  9619. {
  9620. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9621. {
  9622. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9623. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9624. {
  9625. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9626. {
  9627. meet = TRUE;
  9628. break;
  9629. }
  9630. }
  9631. }
  9632. }
  9633. }
  9634. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9635. {
  9636. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9637. {
  9638. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9639. }
  9640. else
  9641. {
  9642. tempIndex = connectorIdInt -1;
  9643. }
  9644. for (int index = 0; index < GB_QUANTITY; index++)
  9645. {
  9646. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9647. {
  9648. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9649. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9650. {
  9651. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9652. {
  9653. meet = TRUE;
  9654. break;
  9655. }
  9656. }
  9657. }
  9658. }
  9659. }
  9660. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9661. {
  9662. tempIndex = connectorIdInt -1;
  9663. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9664. {
  9665. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9666. {
  9667. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  9668. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9669. {
  9670. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9671. {
  9672. meet = TRUE;
  9673. break;
  9674. }
  9675. }
  9676. }
  9677. }
  9678. }
  9679. else
  9680. {
  9681. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9682. {
  9683. tempIndex = 2;
  9684. }
  9685. else
  9686. {
  9687. tempIndex = (connectorIdInt -1);
  9688. }
  9689. for (int index = 0; index < AC_QUANTITY; index++)
  9690. {
  9691. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9692. {
  9693. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9694. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9695. {
  9696. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9697. {
  9698. meet = TRUE;
  9699. break;
  9700. }
  9701. }
  9702. }
  9703. }
  9704. }
  9705. //check Transaction active
  9706. if(meet == FALSE)
  9707. {
  9708. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9709. goto end;
  9710. }
  9711. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9712. {
  9713. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9714. goto end;
  9715. }
  9716. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9717. fptr1 = fopen(filename, "r");
  9718. if (!fptr1)
  9719. {
  9720. //file not exist
  9721. DEBUG_INFO("Unable to open the input file!!\n");
  9722. fptr1 = fopen(filename, "w+");
  9723. }
  9724. else
  9725. {
  9726. //Check Charging Profile Count
  9727. while(fscanf(fptr1, "%s", word) != EOF)
  9728. {
  9729. //DEBUG_INFO("word=%s\n",word);
  9730. if(strstr(word, "chargingProfileId")!= NULL)
  9731. {
  9732. //DEBUG_INFO("test chargingProfileId \n");
  9733. n_chargingProfile = n_chargingProfile + 1;
  9734. //DEBUG_INFO("chargingProfileId Found\n");
  9735. }
  9736. }
  9737. }
  9738. fclose(fptr1);
  9739. }
  9740. // Check ChargeProfileMaxStackLevel
  9741. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  9742. {
  9743. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9744. goto end;
  9745. }
  9746. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9747. {
  9748. int i = 0;
  9749. char fnametemp[200]={0};
  9750. n_chargingProfile = 0;
  9751. //Check ChargePointMaxProfile.json exit
  9752. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9753. {
  9754. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  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. i = i + 1;
  9764. //DEBUG_INFO("chargingProfileId Found\n");
  9765. }
  9766. memset(word, 0, ARRAY_SIZE(word));
  9767. }
  9768. fclose(fptr1);
  9769. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  9770. }
  9771. //Check TxDefaultProfile_0.json exit
  9772. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9773. {
  9774. i = 0;
  9775. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  9776. //Check Charging Profile Count
  9777. while(fscanf(fptr1, "%s", word) != EOF)
  9778. {
  9779. //DEBUG_INFO("word=%s\n",word);
  9780. if(strstr(word, "chargingProfileId")!= NULL)
  9781. {
  9782. //DEBUG_INFO("test chargingProfileId \n");
  9783. n_chargingProfile = n_chargingProfile + 1;
  9784. i = i + 1;
  9785. //DEBUG_INFO("chargingProfileId Found\n");
  9786. }
  9787. memset(word, 0, ARRAY_SIZE(word));
  9788. }
  9789. fclose(fptr1);
  9790. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  9791. }
  9792. //Check TxDefaultProfile_%d.json
  9793. for(int j=1; j <= gunTotalNumber; j++)
  9794. {
  9795. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9796. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9797. if((access(fnametemp,F_OK))!=-1)
  9798. {
  9799. i = 0;
  9800. fptr1 = fopen(fnametemp, "r");
  9801. //Check Charging Profile Count
  9802. while(fscanf(fptr1, "%s", word) != EOF)
  9803. {
  9804. //DEBUG_INFO("word=%s\n",word);
  9805. if(strstr(word, "chargingProfileId")!= NULL)
  9806. {
  9807. //DEBUG_INFO("test chargingProfileId \n");
  9808. n_chargingProfile = n_chargingProfile + 1;
  9809. i = i + 1;
  9810. //DEBUG_INFO("chargingProfileId Found\n");
  9811. }
  9812. memset(word, 0, ARRAY_SIZE(word));
  9813. }
  9814. fclose(fptr1);
  9815. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9816. }
  9817. }
  9818. //Check TxProfile_%d.json
  9819. for(int j=1; j <= gunTotalNumber; j++)
  9820. {
  9821. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9822. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9823. if((access(fnametemp,F_OK))!=-1)
  9824. {
  9825. i = 0;
  9826. fptr1 = fopen(fnametemp, "r");
  9827. //Check Charging Profile Count
  9828. while(fscanf(fptr1, "%s", word) != EOF)
  9829. {
  9830. //DEBUG_INFO("word=%s\n",word);
  9831. if(strstr(word, "chargingProfileId")!= NULL)
  9832. {
  9833. //DEBUG_INFO("test chargingProfileId \n");
  9834. n_chargingProfile = n_chargingProfile + 1;
  9835. i = i + 1;
  9836. //DEBUG_INFO("chargingProfileId Found\n");
  9837. }
  9838. memset(word, 0, ARRAY_SIZE(word));
  9839. }
  9840. fclose(fptr1);
  9841. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9842. }
  9843. }
  9844. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  9845. {
  9846. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9847. goto end;
  9848. }
  9849. }
  9850. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9851. //**********************************Write to File********************************************************/
  9852. FILE *infile;
  9853. FILE *outfile;
  9854. infile = fopen (filename, "r");
  9855. outfile = fopen (tempfile, "w");
  9856. int d =0;
  9857. d = fgetc(infile);
  9858. rewind(infile);
  9859. if(d == EOF)
  9860. {
  9861. // Profile is empty
  9862. fprintf(outfile,"%s\n",payload);
  9863. fclose(infile);
  9864. fclose(outfile);
  9865. sprintf(rmFileCmd,"rm -f %s",filename);
  9866. system(rmFileCmd);
  9867. rename(tempfile, filename);
  9868. }
  9869. else
  9870. {
  9871. // Profile is not empty
  9872. char buf[2048]={0};
  9873. int ChargingProfileAdded = FALSE;
  9874. while (fgets(buf, sizeof(buf), infile) != NULL)
  9875. {
  9876. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9877. json_object *tmpChargingProfile;
  9878. tmpChargingProfile = json_tokener_parse(buf);
  9879. if(!is_error(SetChargingProfile))
  9880. {
  9881. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  9882. {
  9883. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  9884. }
  9885. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  9886. {
  9887. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  9888. {
  9889. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  9890. }
  9891. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  9892. {
  9893. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  9894. }
  9895. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9896. {
  9897. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  9898. }
  9899. }
  9900. }
  9901. json_object_put(tmpChargingProfile);
  9902. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  9903. {
  9904. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9905. {
  9906. //DEBUG_INFO("update set chargingProfile to file -0\n");
  9907. if(ChargingProfileAdded == FALSE)
  9908. {
  9909. fprintf(outfile,"%s\n",payload);
  9910. ChargingProfileAdded = TRUE;
  9911. }
  9912. }
  9913. else
  9914. {
  9915. if(tempstackLevelInt < stackLevelInt)
  9916. {
  9917. if(ChargingProfileAdded == FALSE)
  9918. {
  9919. fprintf(outfile,"%s\n",buf);
  9920. fprintf(outfile,"%s\n",payload);
  9921. ChargingProfileAdded = TRUE;
  9922. }
  9923. else
  9924. {
  9925. fprintf(outfile,"%s\n",buf);
  9926. }
  9927. }
  9928. else
  9929. {
  9930. if(ChargingProfileAdded == FALSE)
  9931. {
  9932. fprintf(outfile,"%s\n",buf);
  9933. fprintf(outfile,"%s\n",payload);
  9934. ChargingProfileAdded = TRUE;
  9935. }
  9936. else
  9937. {
  9938. fprintf(outfile,"%s\n",buf);
  9939. }
  9940. }
  9941. }
  9942. }
  9943. else
  9944. {
  9945. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9946. {
  9947. if(ChargingProfileAdded == FALSE)
  9948. {
  9949. fprintf(outfile,"%s\n",buf);
  9950. fprintf(outfile,"%s\n",payload);
  9951. ChargingProfileAdded = TRUE;
  9952. }
  9953. else
  9954. {
  9955. fprintf(outfile,"%s\n",buf);
  9956. }
  9957. }
  9958. else if(tempstackLevelInt < stackLevelInt)
  9959. {
  9960. if(ChargingProfileAdded == FALSE)
  9961. {
  9962. fprintf(outfile,"%s\n",buf);
  9963. fprintf(outfile,"%s\n",payload);
  9964. ChargingProfileAdded = TRUE;
  9965. }
  9966. else
  9967. {
  9968. fprintf(outfile,"%s\n",buf);
  9969. }
  9970. }
  9971. else
  9972. {
  9973. if(ChargingProfileAdded == FALSE)
  9974. {
  9975. fprintf(outfile,"%s\n",buf);
  9976. fprintf(outfile,"%s\n",payload);
  9977. ChargingProfileAdded = TRUE;
  9978. }
  9979. else
  9980. {
  9981. fprintf(outfile,"%s\n",buf);
  9982. }
  9983. }
  9984. }
  9985. } // end of while loop
  9986. fclose(infile);
  9987. fclose(outfile);
  9988. sprintf(rmFileCmd,"rm -f %s",filename);
  9989. system(rmFileCmd);
  9990. rename(tempfile, filename);
  9991. }
  9992. sleep(1);
  9993. result = TRUE;
  9994. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9995. end:
  9996. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  9997. {
  9998. if(connectorIdInt == 0)
  9999. {
  10000. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  10001. {
  10002. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  10003. }
  10004. }
  10005. else
  10006. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  10007. }
  10008. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  10009. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10010. return result;
  10011. }
  10012. int handleTriggerMessageRequest(char *uuid, char *payload)
  10013. {
  10014. mtrace();
  10015. int result = FAIL;
  10016. int connectorIdIsNULL = FALSE;
  10017. int connectorIdInt =0;
  10018. char sstr[40]={0},sstrtemp[100]={ 0 };
  10019. char requestedMessagestr[40]={0};
  10020. char comfirmstr[20]={0};
  10021. int c = 0;
  10022. char *loc;
  10023. DEBUG_INFO("handleTriggerMessageRequest\n");
  10024. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  10025. strcpy(sstrtemp, stringtrimspace(payload));
  10026. c = 0;
  10027. loc = strstr(sstrtemp, "requestedMessage");
  10028. while (loc[3+strlen("requestedMessage")+c] != '\"')
  10029. {
  10030. sstr[c] = loc[3+strlen("requestedMessage")+c];
  10031. c++;
  10032. }
  10033. sstr[c] = '\0';
  10034. strcpy(requestedMessagestr, sstr);
  10035. c = 0;
  10036. loc = strstr(sstrtemp, "connectorId");
  10037. if(loc == NULL)
  10038. {
  10039. connectorIdIsNULL = TRUE;
  10040. }
  10041. else
  10042. {
  10043. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10044. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  10045. {
  10046. sstr[c] = loc[strlen("connectorId")+2+c];
  10047. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10048. c++;
  10049. }
  10050. sstr[c] = '\0';
  10051. connectorIdInt = atoi(sstr);
  10052. }
  10053. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  10054. {
  10055. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  10056. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  10057. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  10058. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  10059. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  10060. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  10061. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  10062. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  10063. {
  10064. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  10065. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10066. return TRUE;
  10067. }
  10068. else
  10069. {
  10070. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  10071. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10072. }
  10073. }
  10074. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  10075. {
  10076. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  10077. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10078. return TRUE;
  10079. }
  10080. //==========================
  10081. // Trigger message
  10082. //==========================
  10083. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  10084. {
  10085. if((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) &&
  10086. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) &&
  10087. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) &&
  10088. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING) )
  10089. {
  10090. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  10091. }
  10092. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  10093. }
  10094. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  10095. {
  10096. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  10097. }
  10098. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  10099. {
  10100. //sendBootNotificationRequest();
  10101. server_sign = FALSE;
  10102. }
  10103. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  10104. {
  10105. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  10106. }
  10107. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  10108. {
  10109. if(connectorIdIsNULL == FALSE)
  10110. {
  10111. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  10112. {
  10113. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  10114. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  10115. }
  10116. }
  10117. else
  10118. {
  10119. for(int idx=0;idx< gunTotalNumber;idx++)
  10120. {
  10121. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  10122. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  10123. }
  10124. }
  10125. }
  10126. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  10127. {
  10128. if(connectorIdIsNULL == FALSE)
  10129. {
  10130. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  10131. {
  10132. cpinitateMsg.bits[connectorIdInt -1].StatusNotificationReq = 1;
  10133. }
  10134. }
  10135. else
  10136. {
  10137. for(int idx=0;idx< gunTotalNumber;idx++)
  10138. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  10139. }
  10140. }
  10141. return result;
  10142. }
  10143. int handleUnlockConnectorRequest(char *uuid, char *payload)
  10144. {
  10145. mtrace();
  10146. int result = FAIL;
  10147. int connectorIdInt =0;
  10148. char comfirmstr[20]={0};
  10149. int tempIndex = 0;
  10150. json_object *UnlockConnector;
  10151. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  10152. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  10153. UnlockConnector = json_tokener_parse(payload);
  10154. if(!is_error(UnlockConnector))
  10155. {
  10156. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  10157. {
  10158. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  10159. }
  10160. }
  10161. json_object_put(UnlockConnector);
  10162. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  10163. if(gunTotalNumber == 0)
  10164. {
  10165. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10166. goto end;
  10167. }
  10168. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  10169. {
  10170. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10171. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10172. goto end;
  10173. }
  10174. else
  10175. {
  10176. //check Transaction active
  10177. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  10178. {
  10179. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10180. {
  10181. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10182. }
  10183. else
  10184. {
  10185. tempIndex = connectorIdInt -1;
  10186. }
  10187. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10188. {
  10189. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10190. {
  10191. //stop Transaction
  10192. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10193. }
  10194. }
  10195. }
  10196. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  10197. {
  10198. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10199. {
  10200. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10201. }
  10202. else
  10203. {
  10204. tempIndex = connectorIdInt -1;
  10205. }
  10206. for (int index = 0; index < CCS_QUANTITY; index++)
  10207. {
  10208. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10209. {
  10210. //stop Transaction
  10211. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10212. }
  10213. }
  10214. }
  10215. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  10216. {
  10217. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10218. {
  10219. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10220. }
  10221. else
  10222. {
  10223. tempIndex = connectorIdInt -1;
  10224. }
  10225. for (int index = 0; index < GB_QUANTITY; index++)
  10226. {
  10227. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  10228. {
  10229. //stop Transaction
  10230. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10231. }
  10232. }
  10233. }
  10234. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  10235. {
  10236. tempIndex = connectorIdInt -1;
  10237. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10238. {
  10239. 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)))
  10240. {
  10241. //stop Transaction
  10242. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10243. }
  10244. }
  10245. }
  10246. else
  10247. {
  10248. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10249. {
  10250. tempIndex = 2;
  10251. }
  10252. else
  10253. {
  10254. tempIndex = connectorIdInt-1;
  10255. }
  10256. for (int index = 0; index < AC_QUANTITY; index++)
  10257. {
  10258. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10259. {
  10260. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10261. }
  10262. }
  10263. }
  10264. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  10265. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  10266. result = TRUE;
  10267. return result;
  10268. }
  10269. end:
  10270. //json_object_put(obj); --- remove temporally
  10271. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  10272. return result;
  10273. }
  10274. static char UpdateFirmwarepayloadData[300]={0};
  10275. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  10276. {
  10277. mtrace();
  10278. int result = FAIL;
  10279. pthread_t t;
  10280. sendUpdateFirmwareConfirmation(uuid);
  10281. memset(UpdateFirmwarepayloadData, 0, 300);
  10282. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  10283. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  10284. ////pthread_join(t, NULL); //
  10285. //pthread_detach(t);
  10286. //sendUpdateFirmwareConfirmation(uuid);
  10287. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  10288. return result;
  10289. }
  10290. void *UpdateFirmwareProcess(void *data)
  10291. {
  10292. pthread_detach(pthread_self());
  10293. mtrace();
  10294. int retriesInt =0, retryIntervalInt=0;
  10295. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  10296. int port=0;
  10297. char locationstr[160]={0}, retrieveDatestr[30]={0};
  10298. int isSuccess = 0;
  10299. char ftpbuf[200];
  10300. char temp[100];
  10301. char * pch;
  10302. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  10303. json_object *UpdateFirmware;
  10304. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  10305. if(!is_error(UpdateFirmware))
  10306. {
  10307. // Required data
  10308. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  10309. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  10310. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  10311. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  10312. // Optional data
  10313. if(json_object_object_get(UpdateFirmware, "retries"))
  10314. {
  10315. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  10316. }
  10317. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  10318. {
  10319. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  10320. }
  10321. }
  10322. json_object_put(UpdateFirmware);
  10323. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10324. memset(path, 0, ARRAY_SIZE(path));
  10325. system("rm -f /mnt/*");
  10326. if(strncmp(locationstr,"http", 4) == 0)
  10327. {
  10328. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10329. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  10330. // protocol, user, password, host, path);
  10331. sprintf(ftppath,"/%s", path);
  10332. DEBUG_INFO("locationstr: %s\n", locationstr);
  10333. DEBUG_INFO("protocol: %s\n",protocol);
  10334. DEBUG_INFO("host: %s\n",host);
  10335. DEBUG_INFO("path: %s\n",path);
  10336. DEBUG_INFO("ftppath: %s\n",ftppath);
  10337. int ftppathlen=strlen(ftppath);
  10338. int i=1;
  10339. char filenametemp[50];
  10340. while(i < ftppathlen)
  10341. {
  10342. int len=ftppathlen-i;
  10343. if(ftppath[len]== 47) // '/' ascll code: 47
  10344. {
  10345. DEBUG_INFO("compare '/' all right\n");
  10346. break;
  10347. }
  10348. i=i+1;
  10349. }
  10350. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10351. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10352. filenametemp[i+1] = 0;
  10353. do
  10354. {
  10355. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  10356. sleep(3);
  10357. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  10358. if(!isSuccess)
  10359. {
  10360. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10361. sleep(retryIntervalInt);
  10362. }
  10363. else
  10364. {
  10365. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10366. }
  10367. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  10368. }
  10369. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  10370. {
  10371. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  10372. memset(temp, 0, ARRAY_SIZE(temp));
  10373. //DEBUG_INFO("locationstr=%s\n",locationstr);
  10374. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  10375. int ftppathlen=strlen(ftpbuf);
  10376. int i=1;
  10377. char filenametemp[50];
  10378. while(i < ftppathlen)
  10379. {
  10380. int len=ftppathlen-i;
  10381. if(ftpbuf[len]== 47) // '/' ascll code: 47
  10382. {
  10383. DEBUG_INFO(" compare '/' all right\n");
  10384. break;
  10385. }
  10386. i=i+1;
  10387. }
  10388. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10389. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  10390. filenametemp[i+1] = 0;
  10391. strncpy(temp, ftpbuf, ftppathlen-i+1);
  10392. pch=strchr(temp,'@');
  10393. if(pch==NULL)
  10394. {
  10395. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10396. protocol, host, &port, path);
  10397. strcpy(user,"anonymous");
  10398. strcpy(password,"");
  10399. }
  10400. else
  10401. {
  10402. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10403. protocol, user, password, host, &port, path);
  10404. }
  10405. sscanf(host,"%[^/]%s",host1, path1);
  10406. sprintf(ftppath,"%s", path1);
  10407. //DEBUG_INFO("protocol =%s\n",protocol);
  10408. //DEBUG_INFO("user =%s\n",user);
  10409. //DEBUG_INFO("password =%s\n",password);
  10410. //DEBUG_INFO("host1 =%s\n",host1);
  10411. //DEBUG_INFO("port =%d\n",port);
  10412. //DEBUG_INFO("path1 =%s\n",path1);
  10413. //DEBUG_INFO("ftppath=%s\n",ftppath);
  10414. //ftpFile(host, user, password, port, ftppath, fname);
  10415. //download firmware pthred
  10416. if(port == 0)
  10417. {
  10418. port = 21;
  10419. }
  10420. do
  10421. {
  10422. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  10423. sleep(3);
  10424. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  10425. if(!isSuccess)
  10426. {
  10427. //BulldogUtil.sleepMs(interval*1000);
  10428. DEBUG_INFO("Update firmware request and download file fail.\n");
  10429. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10430. sleep(retryIntervalInt);
  10431. }
  10432. else
  10433. {
  10434. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10435. }
  10436. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  10437. }
  10438. else
  10439. {
  10440. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10441. }
  10442. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  10443. pthread_exit(NULL);
  10444. }
  10445. int handleCertificateSignedRequest(char *uuid, char *payload)
  10446. {
  10447. mtrace();
  10448. int result = PASS;
  10449. json_object *CertificateSigned;
  10450. DEBUG_INFO("handleCertificateSignedRequest...\n");
  10451. CertificateSigned = json_tokener_parse(payload);
  10452. if(!is_error(CertificateSigned))
  10453. {
  10454. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  10455. /*
  10456. * TODO: CertificateSigned process
  10457. */
  10458. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  10459. DEBUG_INFO("certificateChain: %s\n", ShmOCPP16Data->CertificateSigned.certificateChain);
  10460. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Rejected");
  10461. sendCertificateSignedConfirmation(uuid);
  10462. }
  10463. json_object_put(CertificateSigned);
  10464. return result;
  10465. }
  10466. int handleDeleteCertificateRequest(char *uuid, char *payload)
  10467. {
  10468. mtrace();
  10469. int result = PASS;
  10470. json_object *DeleteCertificate;
  10471. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  10472. DeleteCertificate = json_tokener_parse(payload);
  10473. if(!is_error(DeleteCertificate))
  10474. {
  10475. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  10476. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  10477. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  10478. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  10479. /*
  10480. * TODO: Delete certificateSigned process
  10481. */
  10482. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  10483. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  10484. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  10485. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  10486. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  10487. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  10488. sendDeleteCertificateConfirmation(uuid);
  10489. }
  10490. json_object_put(DeleteCertificate);
  10491. return result;
  10492. }
  10493. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  10494. {
  10495. mtrace();
  10496. int result = PASS;
  10497. json_object *ExtendedTriggerMessage;
  10498. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  10499. ExtendedTriggerMessage = json_tokener_parse(payload);
  10500. if(!is_error(ExtendedTriggerMessage))
  10501. {
  10502. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  10503. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  10504. {
  10505. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  10506. }
  10507. else
  10508. {
  10509. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  10510. }
  10511. /*
  10512. * TODO: Trigger message process
  10513. */
  10514. ShmOCPP16Data->MsMsg.bits.ExtendedTriggerMessageReq = 1;
  10515. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  10516. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  10517. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "NotImplemented");
  10518. sendExtendedTriggerMessageConfirmation(uuid);
  10519. }
  10520. json_object_put(ExtendedTriggerMessage);
  10521. return result;
  10522. }
  10523. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  10524. {
  10525. mtrace();
  10526. int result = PASS;
  10527. json_object *GetInstalledCertificateIds;
  10528. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  10529. GetInstalledCertificateIds = json_tokener_parse(payload);
  10530. if(!is_error(GetInstalledCertificateIds))
  10531. {
  10532. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  10533. /*
  10534. * TODO: Return installed certificate process
  10535. */
  10536. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  10537. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  10538. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  10539. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  10540. sendGetInstalledCertificateIdsConfirmation(uuid);
  10541. }
  10542. json_object_put(GetInstalledCertificateIds);
  10543. return result;
  10544. }
  10545. int handleGetLogRequest(char *uuid, char *payload)
  10546. {
  10547. mtrace();
  10548. int result = PASS;
  10549. json_object *GetLog;
  10550. DEBUG_INFO("handleGetLogRequest...\n");
  10551. GetLog = json_tokener_parse(payload);
  10552. if(!is_error(GetLog))
  10553. {
  10554. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  10555. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  10556. if(json_object_object_get(GetLog, "retries") != NULL)
  10557. {
  10558. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  10559. }
  10560. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  10561. {
  10562. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  10563. }
  10564. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  10565. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  10566. {
  10567. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  10568. }
  10569. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  10570. {
  10571. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  10572. }
  10573. /*
  10574. * TODO: Upload log process
  10575. */
  10576. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  10577. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  10578. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  10579. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  10580. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  10581. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  10582. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  10583. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  10584. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  10585. sendGetLogConfirmation(uuid);
  10586. }
  10587. json_object_put(GetLog);
  10588. return result;
  10589. }
  10590. int handleInstallCertificateRequest(char *uuid, char *payload)
  10591. {
  10592. mtrace();
  10593. int result = PASS;
  10594. json_object *InstallCertificate;
  10595. DEBUG_INFO("handleInstallCertificateRequest...\n");
  10596. InstallCertificate = json_tokener_parse(payload);
  10597. if(!is_error(InstallCertificate))
  10598. {
  10599. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  10600. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  10601. /*
  10602. * TODO: Install certificate process
  10603. */
  10604. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  10605. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  10606. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  10607. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  10608. sendInstallCertificateConfirmation(uuid);
  10609. }
  10610. json_object_put(InstallCertificate);
  10611. return result;
  10612. }
  10613. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  10614. {
  10615. mtrace();
  10616. int result = PASS;
  10617. json_object *SignedUpdateFirmware;
  10618. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  10619. SignedUpdateFirmware = json_tokener_parse(payload);
  10620. if(!is_error(SignedUpdateFirmware))
  10621. {
  10622. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  10623. {
  10624. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  10625. }
  10626. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  10627. {
  10628. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  10629. }
  10630. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  10631. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  10632. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  10633. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  10634. {
  10635. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  10636. }
  10637. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  10638. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  10639. /*
  10640. * TODO: Upgrade firmware process
  10641. */
  10642. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  10643. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  10644. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  10645. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  10646. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  10647. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  10648. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  10649. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  10650. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  10651. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  10652. sendInstallCertificateConfirmation(uuid);
  10653. }
  10654. json_object_put(SignedUpdateFirmware);
  10655. return result;
  10656. }
  10657. int handleUnknownRequest(char *uuid, char *payload)
  10658. {
  10659. mtrace();
  10660. int result = PASS;
  10661. DEBUG_INFO("handleUnknownRequest...\n");
  10662. sendUnknownConfirmation(uuid);
  10663. result = PASS;
  10664. return result;
  10665. }
  10666. //==========================================
  10667. // Handle server response routine
  10668. //==========================================
  10669. void handleAuthorizeResponse(char *payload, int gun_index)
  10670. {
  10671. mtrace();
  10672. char expiryDatestr[30]={0};
  10673. char parentIdTagstr[20]={0};
  10674. char statusstr[20]={0};
  10675. int expiryDateISNULL=FALSE;
  10676. int parentIdTagISNULL=FALSE;
  10677. DEBUG_INFO("handleAuthorizeResponse...\n");
  10678. json_object *Authorize;
  10679. Authorize = json_tokener_parse(payload);
  10680. if(!is_error(Authorize))
  10681. {
  10682. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  10683. {
  10684. // Required data
  10685. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  10686. // Optional data
  10687. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  10688. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  10689. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  10690. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  10691. }
  10692. }
  10693. json_object_put(Authorize);
  10694. if(expiryDateISNULL == FALSE)
  10695. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  10696. if(parentIdTagISNULL == FALSE)
  10697. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  10698. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  10699. //Update idTag information to authorization cache if supproted
  10700. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  10701. {
  10702. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  10703. }
  10704. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  10705. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  10706. authorizeRetryTimes = 0;
  10707. }
  10708. void handleBootNotificationResponse(char *payload, int gun_index)
  10709. {
  10710. mtrace();
  10711. char statusStr[12]={0};
  10712. char currentTimeStr[30]={0};
  10713. int intervalInt = 0;
  10714. DEBUG_INFO("handleBootNotificationResponse...\n");
  10715. json_object *BootNotification;
  10716. BootNotification = json_tokener_parse(payload);
  10717. if(!is_error(BootNotification))
  10718. {
  10719. // Required data
  10720. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  10721. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  10722. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  10723. }
  10724. json_object_put(BootNotification);
  10725. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10726. BootNotificationInterval = intervalInt;
  10727. HeartBeatWaitTime = intervalInt;
  10728. //write back to ShmOCPP16Data->BootNotification
  10729. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  10730. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10731. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  10732. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  10733. {
  10734. server_sign = TRUE;
  10735. server_pending =FALSE;
  10736. }
  10737. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  10738. {
  10739. server_pending = TRUE;
  10740. }
  10741. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  10742. srand(time(NULL));
  10743. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  10744. SetOcppConnStatus(TRUE);
  10745. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  10746. }
  10747. void handleDataTransferResponse(char *payload, int gun_index)
  10748. {
  10749. char sstr[160]={0};//sstr[200]={ 0 };
  10750. int c = 0;
  10751. char *loc;
  10752. DEBUG_INFO("handleDataTransferResponse ...\n");
  10753. loc = strstr(payload, "status");
  10754. printf("loc=%s\n",loc);
  10755. c = 0;
  10756. while (loc[3+strlen("status")+c] != '\"')
  10757. {
  10758. sstr[c] = loc[3+strlen("status")+c];
  10759. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10760. c++;
  10761. }
  10762. sstr[c] = '\0';
  10763. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  10764. }
  10765. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  10766. {
  10767. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  10768. //struct json_object *obj;
  10769. // obj = json_tokener_parse(payload);
  10770. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  10771. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  10772. //No fields are defined.
  10773. }
  10774. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  10775. {
  10776. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  10777. //struct json_object *obj;
  10778. // obj = json_tokener_parse(payload);
  10779. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  10780. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  10781. //No fields are defined.
  10782. }
  10783. void handleHeartbeatResponse(char *payload, int gun_index)
  10784. {
  10785. mtrace();
  10786. DEBUG_INFO("handleHeartbeatResponse...\n");
  10787. json_object *Heartbeat;
  10788. Heartbeat = json_tokener_parse(payload);
  10789. if(!is_error(Heartbeat))
  10790. {
  10791. // Required data
  10792. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  10793. }
  10794. json_object_put(Heartbeat);
  10795. if(FirstHeartBeat == 0)
  10796. {
  10797. FirstHeartBeat = 1;
  10798. DEBUG_INFO("FirstHeartBeat \n");
  10799. }
  10800. HeartBeatWithNOResponse = 0;
  10801. clientTime.Heartbeat=time((time_t*)NULL);
  10802. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  10803. }
  10804. void handleMeterValuesResponse(char *payload, int gun_index)
  10805. {
  10806. mtrace();
  10807. DEBUG_INFO("handleMeterValuesResponse...\n");
  10808. }
  10809. void handleStartTransactionResponse(char *payload, int gun_index)
  10810. {
  10811. mtrace();
  10812. //int transactionIdInt = 0;
  10813. FILE *outfile;
  10814. char data[100]={0};
  10815. DEBUG_INFO("handleStartTransactionResponse...\n");
  10816. json_object *StartTransaction;
  10817. StartTransaction = json_tokener_parse(payload);
  10818. if(!is_error(StartTransaction))
  10819. {
  10820. // Required data
  10821. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  10822. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  10823. // Optional data
  10824. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  10825. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  10826. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  10827. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  10828. }
  10829. json_object_put(StartTransaction);
  10830. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  10831. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  10832. //-----------Start : write to the Queue TransactionId file -----------------//
  10833. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  10834. {}
  10835. else
  10836. {
  10837. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  10838. if(log == NULL)
  10839. {
  10840. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  10841. return ;
  10842. }
  10843. else
  10844. {
  10845. fclose(log);
  10846. }
  10847. }
  10848. // open file for writing
  10849. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  10850. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  10851. {
  10852. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  10853. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  10854. fputs(data, outfile);
  10855. fclose (outfile);
  10856. }
  10857. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10858. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10859. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  10860. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  10861. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10862. }
  10863. void handleStatusNotificationResponse(char *payload, int gun_index)
  10864. {
  10865. mtrace();
  10866. DEBUG_INFO("handleStatusNotificationResponse...\n");
  10867. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  10868. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  10869. }
  10870. void handleStopTransactionnResponse(char *payload, int gun_index)
  10871. {
  10872. mtrace();
  10873. DEBUG_INFO("handleStopTransactionnResponse...\n");
  10874. json_object *StopTransaction;
  10875. StopTransaction = json_tokener_parse(payload);
  10876. if(!is_error(StopTransaction))
  10877. {
  10878. // Optional data
  10879. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  10880. {
  10881. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  10882. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  10883. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  10884. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  10885. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  10886. }
  10887. }
  10888. json_object_put(StopTransaction);
  10889. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  10890. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  10891. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10892. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10893. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  10894. }
  10895. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  10896. {
  10897. mtrace();
  10898. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  10899. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  10900. }
  10901. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  10902. {
  10903. mtrace();
  10904. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  10905. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  10906. }
  10907. void handleSignCertificateResponse(char *payload, int gun_index)
  10908. {
  10909. mtrace();
  10910. DEBUG_INFO("handleSignCertificateResponse...\n");
  10911. json_object *SignCertificate;
  10912. SignCertificate = json_tokener_parse(payload);
  10913. if(!is_error(SignCertificate))
  10914. {
  10915. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  10916. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  10917. }
  10918. json_object_put(SignCertificate);
  10919. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  10920. }
  10921. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  10922. {
  10923. mtrace();
  10924. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  10925. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  10926. }
  10927. //==========================================
  10928. // Handle Error routine
  10929. //==========================================
  10930. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  10931. {
  10932. mtrace();
  10933. #ifdef SystemLogMessage
  10934. DEBUG_INFO("errorCode: %s\n", errorCode);
  10935. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  10936. DEBUG_INFO("errorDetails: %s\n", payload);
  10937. #endif
  10938. }
  10939. //===============================================
  10940. // Common routine
  10941. //===============================================
  10942. int initialConfigurationTable(void)
  10943. {
  10944. //clock_t start_t, end_t, total_t;
  10945. FILE *fp;
  10946. FILE *outfile;
  10947. char str[512]={0};
  10948. char sstr[256]={0};
  10949. int c = 0;
  10950. char *loc;
  10951. int confVersion = 1;
  10952. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  10953. //start_t = clock();
  10954. //printf("Starting of the program, start_t = %ld\n", start_t);
  10955. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  10956. // Check configuration file size is correct
  10957. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  10958. {
  10959. struct stat st;
  10960. stat("/Storage/OCPP/OCPPConfiguration", &st);
  10961. if(st.st_size < 3100)
  10962. {
  10963. system("rm -f /Storage/OCPP/OCPPConfiguration");
  10964. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  10965. }
  10966. }
  10967. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  10968. {
  10969. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10970. if(outfile == NULL)
  10971. {
  10972. DEBUG_INFO("Error opening file\n");
  10973. return FALSE;
  10974. }
  10975. /*Core Profile*/
  10976. //AllowOfflineTxForUnknownId
  10977. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10978. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10979. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  10980. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10981. //AuthorizationCacheEnabled
  10982. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10983. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10984. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10985. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10986. //AuthorizeRemoteTxRequests
  10987. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10988. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10989. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  10990. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10991. //BlinkRepeat
  10992. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10993. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10994. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10995. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10996. //ClockAlignedDataInterval
  10997. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10998. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10999. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11000. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11001. //ConnectionTimeOut
  11002. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11003. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11004. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11005. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11006. //GetConfigurationMaxKeys
  11007. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11008. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11009. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  11010. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11011. // HeartbeatInterval
  11012. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11013. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11014. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  11015. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11016. // LightIntensity
  11017. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11018. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11019. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11020. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11021. // LocalAuthorizeOffline
  11022. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  11023. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  11024. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  11025. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11026. // LocalPreAuthorize
  11027. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  11028. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  11029. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  11030. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  11031. // MaxEnergyOnInvalidId
  11032. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  11033. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  11034. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  11035. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  11036. // MeterValuesAlignedData
  11037. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  11038. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  11039. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11040. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11041. else
  11042. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11043. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  11044. // MeterValuesAlignedDataMaxLength
  11045. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  11046. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  11047. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11048. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  11049. else
  11050. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "9" );
  11051. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  11052. // MeterValuesSampledData
  11053. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  11054. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  11055. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11056. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11057. else
  11058. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11059. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  11060. // MeterValuesSampledDataMaxLength
  11061. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  11062. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  11063. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11064. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  11065. else
  11066. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "9" );
  11067. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  11068. // MeterValueSampleInterval
  11069. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  11070. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  11071. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  11072. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  11073. // MinimumStatusDuration
  11074. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  11075. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  11076. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  11077. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  11078. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  11079. // NumberOfConnectors
  11080. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  11081. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  11082. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11083. {
  11084. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  11085. }
  11086. else
  11087. {
  11088. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  11089. }
  11090. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  11091. // ResetRetries
  11092. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  11093. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  11094. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  11095. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  11096. // ConnectorPhaseRotation
  11097. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  11098. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  11099. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  11100. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  11101. // ConnectorPhaseRotationMaxLength
  11102. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  11103. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  11104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  11105. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  11106. // StopTransactionOnEVSideDisconnect
  11107. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  11108. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  11109. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  11110. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  11111. // StopTransactionOnInvalidId
  11112. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  11113. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  11114. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  11115. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  11116. // StopTxnAlignedData
  11117. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  11118. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  11119. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  11120. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  11121. // StopTxnAlignedDataMaxLength
  11122. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  11123. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  11124. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  11125. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  11126. // StopTxnSampledData
  11127. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  11128. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  11129. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11130. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11131. else
  11132. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11133. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  11134. // StopTxnSampledDataMaxLength
  11135. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  11136. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  11137. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11138. {
  11139. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  11140. }
  11141. else
  11142. {
  11143. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  11144. }
  11145. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  11146. // SupportedFeatureProfiles
  11147. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  11148. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  11149. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  11150. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  11151. // SupportedFeatureProfilesMaxLength
  11152. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  11153. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  11154. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  11155. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  11156. // TransactionMessageAttempts
  11157. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  11158. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  11159. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  11160. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11161. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11162. // TransactionMessageRetryInterval
  11163. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  11164. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  11165. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  11166. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11167. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11168. // UnlockConnectorOnEVSideDisconnect
  11169. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  11170. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  11171. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  11172. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  11173. // WebSocketPingInterval
  11174. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  11175. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  11176. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  11177. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  11178. // QueueOffLineStartTransactionMessage
  11179. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  11180. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  11181. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  11182. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  11183. // AuthorizationKey
  11184. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  11185. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  11186. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "" );
  11187. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  11188. // SecurityProfile
  11189. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  11190. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  11191. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "0" );
  11192. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  11193. // DefaultPrice
  11194. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  11195. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  11196. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  11197. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  11198. // CustomDisplayCostAndPrice
  11199. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  11200. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  11201. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  11202. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  11203. // CustomIdleFeeAfterStop
  11204. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  11205. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  11206. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  11207. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  11208. // Configuration Version
  11209. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  11210. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  11211. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  11212. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  11213. //* Local Auth List Management Profile*/
  11214. #if 0
  11215. //For OCTT Test Case
  11216. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11217. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  11218. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11219. #endif
  11220. #if 1
  11221. //LocalAuthListEnabled
  11222. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11223. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  11224. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11225. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11226. #endif
  11227. //LocalAuthListMaxLength
  11228. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  11229. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  11230. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  11231. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  11232. //SendLocalListMaxLength
  11233. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  11234. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  11235. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  11236. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  11237. //ReserveConnectorZeroSupported
  11238. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  11239. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  11240. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  11241. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11242. //* Smart Charging Profile */
  11243. //ChargeProfileMaxStackLevel
  11244. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  11245. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  11246. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  11247. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11248. // ChargingScheduleAllowedChargingRateUnit
  11249. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  11250. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  11251. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  11252. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11253. // ChargingScheduleMaxPeriods
  11254. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  11255. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  11256. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  11257. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11258. // ConnectorSwitch3to1PhaseSupported
  11259. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11260. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11261. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  11262. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11263. // MaxChargingProfilesInstalled
  11264. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11265. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11266. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  11267. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11268. fclose(outfile);
  11269. }
  11270. else
  11271. {
  11272. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  11273. char keystr[60]={0};
  11274. char readonlystr[10]={0};
  11275. char valuestr[256]={0};
  11276. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  11277. if(fp == NULL) {
  11278. DEBUG_INFO("Error opening file");
  11279. return FALSE;
  11280. }
  11281. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  11282. {
  11283. //DEBUG_INFO("Get Configuration \n");
  11284. if(strlen(str) > 0)
  11285. {
  11286. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  11287. //*************************key*********************************/
  11288. if(strstr(str, "key") != NULL)
  11289. {
  11290. loc = strstr(str, "key");
  11291. c = 0;
  11292. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11293. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  11294. {
  11295. sstr[c] = loc[strlen("key")+3+c];
  11296. c++;
  11297. }
  11298. sstr[c] = '\0';
  11299. strcpy(keystr,sstr);
  11300. }
  11301. //*************************readonly*********************************/
  11302. if(strstr(str, "readonly") != NULL)
  11303. {
  11304. loc = strstr(str, "readonly");
  11305. c = 0;
  11306. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11307. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  11308. {
  11309. sstr[c] = loc[strlen("readonly")+2+c];
  11310. c++;
  11311. }
  11312. sstr[c] = '\0';
  11313. strcpy(readonlystr,sstr);
  11314. }
  11315. //*************************value*********************************/
  11316. if(strstr(str, "value") != NULL)
  11317. {
  11318. loc = strstr(str, "value");
  11319. c = 0;
  11320. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11321. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  11322. {
  11323. sstr[c] = loc[strlen("value")+3+c];
  11324. c++;
  11325. }
  11326. sstr[c] = '\0';
  11327. strcpy(valuestr,sstr);
  11328. }
  11329. // DEBUG_INFO("keystr=%s\n",keystr);
  11330. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  11331. // DEBUG_INFO("valuestr=%s\n",valuestr);
  11332. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  11333. {
  11334. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11335. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11336. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  11337. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  11338. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  11339. }
  11340. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  11341. {
  11342. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11343. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11344. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  11345. }
  11346. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  11347. {
  11348. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11349. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  11350. }
  11351. if(strcmp(keystr, "BlinkRepeat") == 0)
  11352. {
  11353. //Charger.BlinkRepeat = Integer.parseInt(value);
  11354. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11355. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  11356. }
  11357. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  11358. {
  11359. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11360. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  11361. }
  11362. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  11363. {
  11364. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11365. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  11366. }
  11367. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  11368. {
  11369. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11370. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  11371. }
  11372. if(strcmp(keystr, "HeartbeatInterval") == 0)
  11373. {
  11374. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11375. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  11376. HeartBeatWaitTime = atoi(valuestr);
  11377. }
  11378. if(strcmp(keystr, "LightIntensity") == 0)
  11379. {
  11380. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11381. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  11382. }
  11383. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  11384. {
  11385. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11386. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  11387. }
  11388. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  11389. {
  11390. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11391. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  11392. }
  11393. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  11394. {
  11395. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11396. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  11397. }
  11398. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  11399. {
  11400. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11401. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  11402. }
  11403. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  11404. {
  11405. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11406. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  11407. }
  11408. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  11409. {
  11410. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11411. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  11412. }
  11413. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  11414. {
  11415. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11416. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  11417. }
  11418. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  11419. {
  11420. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11421. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  11422. }
  11423. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  11424. {
  11425. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11426. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  11427. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  11428. }
  11429. if(strcmp(keystr, "NumberOfConnectors") == 0)
  11430. {
  11431. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11432. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  11433. }
  11434. if(strcmp(keystr, "ResetRetries") == 0)
  11435. {
  11436. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11437. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  11438. }
  11439. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  11440. {
  11441. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11442. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  11443. }
  11444. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  11445. {
  11446. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11447. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  11448. }
  11449. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  11450. {
  11451. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11452. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  11453. }
  11454. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  11455. {
  11456. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11457. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  11458. }
  11459. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  11460. {
  11461. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11462. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  11463. }
  11464. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  11465. {
  11466. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11467. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  11468. }
  11469. if(strcmp(keystr, "StopTxnSampledData") == 0)
  11470. {
  11471. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11472. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  11473. }
  11474. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  11475. {
  11476. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11477. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  11478. }
  11479. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  11480. {
  11481. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11482. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  11483. }
  11484. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  11485. {
  11486. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11487. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  11488. }
  11489. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  11490. {
  11491. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11492. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  11493. TransactionMessageAttemptsValue = atoi(valuestr);
  11494. }
  11495. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  11496. {
  11497. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11498. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  11499. TransactionMessageRetryIntervalValue = atoi(valuestr);
  11500. }
  11501. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  11502. {
  11503. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11504. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  11505. }
  11506. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  11507. {
  11508. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11509. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  11510. }
  11511. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  11512. {
  11513. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11514. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  11515. }
  11516. if(strcmp(keystr, "AuthorizationKey") == 0)
  11517. {
  11518. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11519. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  11520. }
  11521. if(strcmp(keystr, "SecurityProfile") == 0)
  11522. {
  11523. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11524. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  11525. }
  11526. if(strcmp(keystr, "DefaultPrice") == 0)
  11527. {
  11528. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11529. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  11530. }
  11531. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  11532. {
  11533. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11534. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  11535. }
  11536. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  11537. {
  11538. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11539. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  11540. }
  11541. if(strcmp(keystr, "ConfigurationVersion") == 0)
  11542. {
  11543. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11544. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  11545. }
  11546. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  11547. {
  11548. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11549. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  11550. }
  11551. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  11552. {
  11553. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11554. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  11555. }
  11556. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  11557. {
  11558. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11559. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  11560. }
  11561. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  11562. {
  11563. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11564. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  11565. }
  11566. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  11567. {
  11568. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11569. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  11570. }
  11571. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  11572. {
  11573. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11574. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  11575. }
  11576. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  11577. {
  11578. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11579. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  11580. }
  11581. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  11582. {
  11583. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11584. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  11585. }
  11586. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  11587. {
  11588. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11589. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  11590. }
  11591. }
  11592. }
  11593. fclose(fp);
  11594. }
  11595. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  11596. {
  11597. return PASS;
  11598. }
  11599. else
  11600. {
  11601. return FAIL;
  11602. }
  11603. }
  11604. void StoreConfigurationTable(void)
  11605. {
  11606. FILE *outfile;
  11607. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  11608. if(outfile == NULL)
  11609. {
  11610. DEBUG_INFO("Error opening file");
  11611. return ;
  11612. }
  11613. /*Core Profile*/
  11614. //AllowOfflineTxForUnknownId
  11615. /*
  11616. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11617. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  11618. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11619. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  11620. */
  11621. //DEBUG_INFO("data=%s\n",data);
  11622. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11623. //AuthorizationCacheEnabled
  11624. /*
  11625. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11626. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11627. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11628. */
  11629. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11630. //AuthorizeRemoteTxRequests
  11631. /*
  11632. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11633. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11634. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  11635. */
  11636. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11637. //BlinkRepeat
  11638. /*
  11639. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11640. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11641. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11642. */
  11643. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11644. //ClockAlignedDataInterval
  11645. /*
  11646. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11647. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11648. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11649. */
  11650. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11651. //ConnectionTimeOut
  11652. /*
  11653. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11654. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11655. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11656. */
  11657. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11658. //GetConfigurationMaxKeys
  11659. /*
  11660. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11661. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11662. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  11663. */
  11664. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11665. // HeartbeatInterval
  11666. /*
  11667. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11668. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11669. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  11670. */
  11671. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11672. // LightIntensity
  11673. /*
  11674. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11675. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11676. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11677. */
  11678. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11679. // LocalAuthorizeOffline
  11680. /*
  11681. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  11682. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  11683. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  11684. */
  11685. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11686. // LocalPreAuthorize
  11687. /*
  11688. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  11689. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  11690. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  11691. */
  11692. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  11693. // MaxEnergyOnInvalidId
  11694. /*
  11695. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  11696. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  11697. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  11698. */
  11699. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  11700. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  11701. // MeterValuesAlignedData
  11702. /*
  11703. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  11704. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  11705. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  11706. */
  11707. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  11708. // MeterValuesAlignedDataMaxLength
  11709. /*
  11710. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  11711. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  11712. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  11713. */
  11714. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  11715. // MeterValuesSampledData
  11716. /*
  11717. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  11718. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  11719. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  11720. */
  11721. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  11722. // MeterValuesSampledDataMaxLength
  11723. /*
  11724. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  11725. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  11726. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  11727. */
  11728. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  11729. // MeterValueSampleInterval
  11730. /*
  11731. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  11732. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  11733. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  11734. */
  11735. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  11736. // MinimumStatusDuration
  11737. /*
  11738. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  11739. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  11740. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  11741. */
  11742. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  11743. // NumberOfConnectors
  11744. /*
  11745. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  11746. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  11747. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11748. {
  11749. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  11750. }
  11751. else
  11752. {
  11753. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  11754. }
  11755. */
  11756. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  11757. // ResetRetries
  11758. /*
  11759. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  11760. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  11761. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  11762. */
  11763. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  11764. // ConnectorPhaseRotation
  11765. /*
  11766. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  11767. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  11768. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  11769. */
  11770. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  11771. // ConnectorPhaseRotationMaxLength
  11772. /*
  11773. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  11774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  11775. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  11776. */
  11777. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  11778. // StopTransactionOnEVSideDisconnect
  11779. /*
  11780. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  11781. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  11782. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  11783. */
  11784. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  11785. // StopTransactionOnInvalidId
  11786. /*
  11787. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  11788. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  11789. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  11790. */
  11791. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  11792. // StopTxnAlignedData
  11793. /*
  11794. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  11795. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  11796. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  11797. */
  11798. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  11799. // StopTxnAlignedDataMaxLength
  11800. /*
  11801. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  11802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  11803. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  11804. */
  11805. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  11806. // StopTxnSampledData
  11807. /*
  11808. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  11809. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  11810. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  11811. */
  11812. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  11813. // StopTxnSampledDataMaxLength
  11814. /*
  11815. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  11816. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  11817. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  11818. */
  11819. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  11820. // SupportedFeatureProfiles
  11821. /*
  11822. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  11823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  11824. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  11825. */
  11826. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  11827. // SupportedFeatureProfilesMaxLength
  11828. /*
  11829. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  11830. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  11831. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  11832. */
  11833. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  11834. // TransactionMessageAttempts
  11835. /*
  11836. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  11837. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  11838. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  11839. */
  11840. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11841. // TransactionMessageRetryInterval
  11842. /*
  11843. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  11844. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  11845. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  11846. */
  11847. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11848. // UnlockConnectorOnEVSideDisconnect
  11849. /*
  11850. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  11851. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  11852. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  11853. */
  11854. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  11855. // WebSocketPingInterval
  11856. /*
  11857. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  11858. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  11859. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  11860. */
  11861. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  11862. // QueueOffLineStartTransactionMessage
  11863. /*
  11864. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  11865. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  11866. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  11867. */
  11868. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  11869. // AuthorizationKey
  11870. /*
  11871. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  11872. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  11873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  11874. */
  11875. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  11876. // SecurityProfile
  11877. /*
  11878. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  11879. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  11880. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  11881. */
  11882. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  11883. // DefaultPrice
  11884. /*
  11885. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  11886. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  11887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  11888. */
  11889. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  11890. // CustomDisplayCostAndPrice
  11891. /*
  11892. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  11893. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  11894. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  11895. */
  11896. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  11897. // CustomIdleFeeAfterStop
  11898. /*
  11899. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  11900. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  11901. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  11902. */
  11903. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  11904. // ConfigurationVersion
  11905. /*
  11906. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  11907. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  11908. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  11909. */
  11910. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  11911. //* Local Auth List Management Profile*/
  11912. //LocalAuthListEnabled
  11913. /*
  11914. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11915. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  11916. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11917. */
  11918. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11919. //LocalAuthListMaxLength
  11920. /*
  11921. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  11922. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  11923. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  11924. */
  11925. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  11926. //SendLocalListMaxLength
  11927. /*
  11928. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  11929. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  11930. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  11931. */
  11932. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  11933. //ReserveConnectorZeroSupported
  11934. /*
  11935. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  11936. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  11937. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  11938. */
  11939. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11940. //* Smart Charging Profile */
  11941. //ChargeProfileMaxStackLevel
  11942. /*
  11943. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  11944. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  11945. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  11946. */
  11947. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11948. // ChargingScheduleAllowedChargingRateUnit
  11949. /*
  11950. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  11951. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  11952. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  11953. */
  11954. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11955. // ChargingScheduleMaxPeriods
  11956. /*
  11957. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  11958. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  11959. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  11960. */
  11961. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11962. // ConnectorSwitch3to1PhaseSupported
  11963. /*
  11964. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11965. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11966. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  11967. */
  11968. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11969. // MaxChargingProfilesInstalled
  11970. /*
  11971. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11972. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11973. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  11974. */
  11975. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11976. fclose(outfile);
  11977. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11978. }
  11979. void getKeyValue(char *keyReq)
  11980. {
  11981. int isEmpty = FALSE;
  11982. int isKnowKey = FALSE;
  11983. DEBUG_INFO("keyReq = %s\n", keyReq);
  11984. if((keyReq == NULL) || (strlen(keyReq) == 0))
  11985. isEmpty = TRUE;
  11986. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  11987. {
  11988. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  11989. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  11990. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11991. {
  11992. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  11993. }
  11994. else
  11995. {
  11996. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  11997. }
  11998. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  11999. isKnowKey = TRUE;
  12000. }
  12001. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  12002. {
  12003. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  12004. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  12005. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  12006. {
  12007. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  12008. }
  12009. else
  12010. {
  12011. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  12012. }
  12013. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  12014. isKnowKey = TRUE;
  12015. }
  12016. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  12017. {
  12018. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  12019. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  12020. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  12021. {
  12022. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  12023. }
  12024. else
  12025. {
  12026. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  12027. }
  12028. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  12029. isKnowKey = TRUE;
  12030. }
  12031. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  12032. {
  12033. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  12034. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  12035. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  12036. {
  12037. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  12038. }
  12039. else
  12040. {
  12041. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  12042. }
  12043. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  12044. isKnowKey = TRUE;
  12045. }
  12046. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  12047. {
  12048. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  12049. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  12050. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  12051. {
  12052. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  12053. }
  12054. else
  12055. {
  12056. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  12057. }
  12058. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  12059. isKnowKey = TRUE;
  12060. }
  12061. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  12062. {
  12063. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  12064. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  12065. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  12066. {
  12067. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  12068. }
  12069. else
  12070. {
  12071. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  12072. }
  12073. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  12074. isKnowKey = TRUE;
  12075. }
  12076. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  12077. {
  12078. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  12079. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  12080. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  12081. {
  12082. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  12083. }
  12084. else
  12085. {
  12086. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  12087. }
  12088. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  12089. isKnowKey = TRUE;
  12090. }
  12091. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  12092. {
  12093. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  12094. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  12095. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  12096. {
  12097. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  12098. }
  12099. else
  12100. {
  12101. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  12102. }
  12103. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  12104. isKnowKey = TRUE;
  12105. }
  12106. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  12107. {
  12108. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  12109. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  12110. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  12111. {
  12112. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  12113. }
  12114. else
  12115. {
  12116. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  12117. }
  12118. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  12119. isKnowKey = TRUE;
  12120. }
  12121. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  12122. {
  12123. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  12124. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  12125. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  12126. {
  12127. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  12128. }
  12129. else
  12130. {
  12131. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  12132. }
  12133. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  12134. isKnowKey = TRUE;
  12135. }
  12136. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  12137. {
  12138. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  12139. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  12140. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  12141. {
  12142. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  12143. }
  12144. else
  12145. {
  12146. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  12147. }
  12148. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  12149. isKnowKey = TRUE;
  12150. }
  12151. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  12152. {
  12153. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  12154. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  12155. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  12156. {
  12157. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  12158. }
  12159. else
  12160. {
  12161. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  12162. }
  12163. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  12164. isKnowKey = TRUE;
  12165. }
  12166. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  12167. {
  12168. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  12169. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  12170. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  12171. {
  12172. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  12173. }
  12174. else
  12175. {
  12176. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  12177. }
  12178. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  12179. isKnowKey = TRUE;
  12180. }
  12181. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  12182. {
  12183. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  12184. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  12185. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  12186. {
  12187. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12188. }
  12189. else
  12190. {
  12191. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12192. }
  12193. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  12194. isKnowKey = TRUE;
  12195. }
  12196. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  12197. {
  12198. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  12199. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  12200. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  12201. {
  12202. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  12203. }
  12204. else
  12205. {
  12206. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  12207. }
  12208. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  12209. isKnowKey = TRUE;
  12210. }
  12211. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  12212. {
  12213. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  12214. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  12215. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  12216. {
  12217. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12218. }
  12219. else
  12220. {
  12221. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12222. }
  12223. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  12224. isKnowKey = TRUE;
  12225. }
  12226. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  12227. {
  12228. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  12229. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  12230. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12231. {
  12232. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  12233. }
  12234. else
  12235. {
  12236. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  12237. }
  12238. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  12239. isKnowKey = TRUE;
  12240. }
  12241. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  12242. {
  12243. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  12244. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  12245. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12246. {
  12247. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  12248. }
  12249. else
  12250. {
  12251. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  12252. }
  12253. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  12254. isKnowKey = TRUE;
  12255. }
  12256. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  12257. {
  12258. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  12259. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  12260. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12261. {
  12262. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  12263. }
  12264. else
  12265. {
  12266. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  12267. }
  12268. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  12269. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  12270. isKnowKey = TRUE;
  12271. }
  12272. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  12273. {
  12274. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  12275. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  12276. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12277. {
  12278. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  12279. }
  12280. else
  12281. {
  12282. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  12283. }
  12284. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  12285. isKnowKey = TRUE;
  12286. }
  12287. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  12288. {
  12289. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  12290. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  12291. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12292. {
  12293. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  12294. }
  12295. else
  12296. {
  12297. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  12298. }
  12299. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  12300. isKnowKey = TRUE;
  12301. }
  12302. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  12303. {
  12304. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  12305. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  12306. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12307. {
  12308. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12309. }
  12310. else
  12311. {
  12312. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12313. }
  12314. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  12315. isKnowKey = TRUE;
  12316. }
  12317. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  12318. {
  12319. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  12320. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  12321. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12322. {
  12323. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  12324. }
  12325. else
  12326. {
  12327. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  12328. }
  12329. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  12330. isKnowKey = TRUE;
  12331. }
  12332. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  12333. {
  12334. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  12335. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  12336. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12337. {
  12338. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  12339. }
  12340. else
  12341. {
  12342. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  12343. }
  12344. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  12345. isKnowKey = TRUE;
  12346. }
  12347. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  12348. {
  12349. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  12350. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  12351. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12352. {
  12353. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  12354. }
  12355. else
  12356. {
  12357. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  12358. }
  12359. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  12360. isKnowKey = TRUE;
  12361. }
  12362. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  12363. {
  12364. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  12365. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  12366. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12367. {
  12368. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12369. }
  12370. else
  12371. {
  12372. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12373. }
  12374. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  12375. isKnowKey = TRUE;
  12376. }
  12377. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  12378. {
  12379. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  12380. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  12381. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12382. {
  12383. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  12384. }
  12385. else
  12386. {
  12387. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  12388. }
  12389. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  12390. isKnowKey = TRUE;
  12391. }
  12392. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  12393. {
  12394. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  12395. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  12396. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12397. {
  12398. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12399. }
  12400. else
  12401. {
  12402. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12403. }
  12404. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  12405. isKnowKey = TRUE;
  12406. }
  12407. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  12408. {
  12409. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  12410. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  12411. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12412. {
  12413. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  12414. }
  12415. else
  12416. {
  12417. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  12418. }
  12419. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  12420. isKnowKey = TRUE;
  12421. }
  12422. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  12423. {
  12424. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  12425. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  12426. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12427. {
  12428. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12429. }
  12430. else
  12431. {
  12432. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12433. }
  12434. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  12435. isKnowKey = TRUE;
  12436. }
  12437. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  12438. {
  12439. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  12440. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  12441. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12442. {
  12443. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  12444. }
  12445. else
  12446. {
  12447. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  12448. }
  12449. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  12450. isKnowKey = TRUE;
  12451. }
  12452. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  12453. {
  12454. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  12455. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  12456. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12457. {
  12458. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  12459. }
  12460. else
  12461. {
  12462. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  12463. }
  12464. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  12465. isKnowKey = TRUE;
  12466. }
  12467. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  12468. {
  12469. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  12470. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  12471. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12472. {
  12473. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  12474. }
  12475. else
  12476. {
  12477. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  12478. }
  12479. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  12480. isKnowKey = TRUE;
  12481. }
  12482. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  12483. {
  12484. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  12485. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  12486. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12487. {
  12488. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  12489. }
  12490. else
  12491. {
  12492. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  12493. }
  12494. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  12495. isKnowKey = TRUE;
  12496. }
  12497. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  12498. {
  12499. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  12500. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  12501. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12502. {
  12503. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  12504. }
  12505. else
  12506. {
  12507. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  12508. }
  12509. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  12510. isKnowKey = TRUE;
  12511. }
  12512. /*
  12513. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  12514. {
  12515. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  12516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  12517. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  12518. {
  12519. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  12520. }
  12521. else
  12522. {
  12523. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  12524. }
  12525. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  12526. isKnowKey = TRUE;
  12527. }*/
  12528. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  12529. {
  12530. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  12531. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  12532. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  12533. {
  12534. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  12535. }
  12536. else
  12537. {
  12538. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  12539. }
  12540. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  12541. isKnowKey = TRUE;
  12542. }
  12543. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  12544. {
  12545. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  12546. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  12547. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  12548. {
  12549. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  12550. }
  12551. else
  12552. {
  12553. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  12554. }
  12555. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  12556. isKnowKey = TRUE;
  12557. }
  12558. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  12559. {
  12560. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  12561. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  12562. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  12563. {
  12564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  12565. }
  12566. else
  12567. {
  12568. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  12569. }
  12570. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  12571. isKnowKey = TRUE;
  12572. }
  12573. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  12574. {
  12575. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  12576. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  12577. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  12578. {
  12579. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  12580. }
  12581. else
  12582. {
  12583. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  12584. }
  12585. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  12586. isKnowKey = TRUE;
  12587. }
  12588. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  12589. {
  12590. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  12591. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  12592. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  12593. {
  12594. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  12595. }
  12596. else
  12597. {
  12598. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  12599. }
  12600. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  12601. isKnowKey = TRUE;
  12602. }
  12603. #if 1
  12604. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  12605. {
  12606. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  12607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  12608. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12609. {
  12610. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  12611. }
  12612. else
  12613. {
  12614. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  12615. }
  12616. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  12617. isKnowKey = TRUE;
  12618. }
  12619. #endif
  12620. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  12621. {
  12622. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  12623. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  12624. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12625. {
  12626. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12627. }
  12628. else
  12629. {
  12630. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12631. }
  12632. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  12633. isKnowKey = TRUE;
  12634. }
  12635. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  12636. {
  12637. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  12638. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  12639. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12640. {
  12641. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12642. }
  12643. else
  12644. {
  12645. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12646. }
  12647. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  12648. isKnowKey = TRUE;
  12649. }
  12650. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  12651. {
  12652. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  12653. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  12654. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12655. {
  12656. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  12657. }
  12658. else
  12659. {
  12660. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  12661. }
  12662. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12663. isKnowKey = TRUE;
  12664. }
  12665. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  12666. {
  12667. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  12668. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  12669. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12670. {
  12671. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  12672. }
  12673. else
  12674. {
  12675. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  12676. }
  12677. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12678. isKnowKey = TRUE;
  12679. }
  12680. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  12681. {
  12682. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  12683. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  12684. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12685. {
  12686. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  12687. }
  12688. else
  12689. {
  12690. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  12691. }
  12692. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12693. isKnowKey = TRUE;
  12694. }
  12695. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  12696. {
  12697. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  12698. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  12699. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12700. {
  12701. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  12702. }
  12703. else
  12704. {
  12705. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  12706. }
  12707. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12708. isKnowKey = TRUE;
  12709. }
  12710. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  12711. {
  12712. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  12713. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  12714. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12715. {
  12716. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  12717. }
  12718. else
  12719. {
  12720. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  12721. }
  12722. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12723. isKnowKey = TRUE;
  12724. }
  12725. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  12726. {
  12727. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  12728. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  12729. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12730. {
  12731. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  12732. }
  12733. else
  12734. {
  12735. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  12736. }
  12737. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12738. isKnowKey = TRUE;
  12739. }
  12740. //=========================================================
  12741. if(!isEmpty && !isKnowKey)
  12742. {
  12743. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  12744. strcpy(unknownkey[UnknownKeynum], keyReq);
  12745. UnknownKeynum = UnknownKeynum + 1;
  12746. }
  12747. }
  12748. void processUnkownKey(void)
  12749. {
  12750. DEBUG_INFO("processUnkownKey...\n");
  12751. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  12752. for(int index=0; index < UnknownKeynum; index++)
  12753. {
  12754. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  12755. {
  12756. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  12757. }
  12758. }
  12759. }
  12760. int setKeyValue(char *key, char *value)
  12761. {
  12762. int isSuccess = NotSupported;
  12763. int check_ascii=0;
  12764. char str[256]={0};
  12765. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  12766. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  12767. {
  12768. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  12769. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  12770. {
  12771. strcpy(str, (const char*)value);
  12772. for(int i = 0; str[i]; i++){
  12773. str[i] = tolower(str[i]);
  12774. }
  12775. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12776. isSuccess = ConfigurationStatus_Accepted;
  12777. }
  12778. else
  12779. {
  12780. isSuccess = ConfigurationStatus_Rejected;
  12781. }
  12782. }
  12783. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  12784. {
  12785. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  12786. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  12787. {
  12788. strcpy(str, (const char*)value);
  12789. for(int i = 0; str[i]; i++){
  12790. str[i] = tolower(str[i]);
  12791. }
  12792. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12793. isSuccess = ConfigurationStatus_Accepted;
  12794. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  12795. }
  12796. else
  12797. {
  12798. isSuccess = ConfigurationStatus_Rejected;
  12799. }
  12800. }
  12801. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  12802. {
  12803. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  12804. {
  12805. strcpy(str, (const char*)value);
  12806. for(int i = 0; str[i]; i++)
  12807. {
  12808. str[i] = tolower(str[i]);
  12809. }
  12810. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  12811. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12812. isSuccess = ConfigurationStatus_Accepted;
  12813. }
  12814. else
  12815. {
  12816. isSuccess = ConfigurationStatus_Rejected;
  12817. }
  12818. }
  12819. if(strcmp(key, "BlinkRepeat") == 0)
  12820. {
  12821. //Charger.BlinkRepeat = Integer.parseInt(value);
  12822. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  12823. {
  12824. check_ascii = value[0];
  12825. if( (check_ascii < 48) || (check_ascii > 57) )
  12826. {
  12827. isSuccess = ConfigurationStatus_Rejected;
  12828. }
  12829. else
  12830. {
  12831. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  12832. isSuccess = ConfigurationStatus_Accepted;
  12833. }
  12834. }
  12835. else
  12836. {
  12837. isSuccess = ConfigurationStatus_Rejected;
  12838. }
  12839. }
  12840. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  12841. {
  12842. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  12843. {
  12844. check_ascii = value[0];
  12845. if( (check_ascii < 48) || (check_ascii > 57) )
  12846. {
  12847. isSuccess = ConfigurationStatus_Rejected;
  12848. }
  12849. else
  12850. {
  12851. if((atoi(value) == 0) || (atoi(value) >= 10))
  12852. {
  12853. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  12854. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  12855. isSuccess = ConfigurationStatus_Accepted;
  12856. }
  12857. else
  12858. isSuccess = ConfigurationStatus_Rejected;
  12859. }
  12860. }
  12861. else
  12862. {
  12863. isSuccess = ConfigurationStatus_Rejected;
  12864. }
  12865. }
  12866. if(strcmp(key, "ConnectionTimeOut") == 0 )
  12867. {
  12868. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  12869. {
  12870. check_ascii = value[0];
  12871. if( (check_ascii < 48) || (check_ascii > 57) )
  12872. {
  12873. isSuccess = ConfigurationStatus_Rejected;
  12874. }
  12875. else
  12876. {
  12877. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  12878. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  12879. isSuccess = ConfigurationStatus_Accepted;
  12880. }
  12881. }
  12882. else
  12883. {
  12884. isSuccess = ConfigurationStatus_Rejected;
  12885. }
  12886. }
  12887. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  12888. {
  12889. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  12890. {
  12891. check_ascii = value[0];
  12892. if( (check_ascii < 48) || (check_ascii > 57) )
  12893. {
  12894. isSuccess = ConfigurationStatus_Rejected;
  12895. }
  12896. else
  12897. {
  12898. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  12899. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  12900. isSuccess = ConfigurationStatus_Accepted;
  12901. }
  12902. }
  12903. else
  12904. {
  12905. isSuccess = ConfigurationStatus_Rejected;
  12906. }
  12907. }
  12908. if(strcmp(key, "HeartbeatInterval") == 0)
  12909. {
  12910. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  12911. {
  12912. check_ascii = value[0];
  12913. if( (check_ascii < 48) || (check_ascii > 57) )
  12914. {
  12915. isSuccess = ConfigurationStatus_Rejected;
  12916. }
  12917. else
  12918. {
  12919. if((atoi(value) == 0) || (atoi(value) >= 10))
  12920. {
  12921. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  12922. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  12923. HeartBeatWaitTime = atoi(value);
  12924. isSuccess = ConfigurationStatus_Accepted;
  12925. }
  12926. else
  12927. {
  12928. isSuccess = ConfigurationStatus_Rejected;
  12929. }
  12930. }
  12931. }
  12932. else
  12933. {
  12934. isSuccess = ConfigurationStatus_Rejected;
  12935. }
  12936. }
  12937. if(strcmp(key, "LightIntensity") == 0)
  12938. {
  12939. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  12940. {
  12941. check_ascii = value[0];
  12942. if( (check_ascii < 48) || (check_ascii > 57) )
  12943. {
  12944. isSuccess = ConfigurationStatus_Rejected;
  12945. }
  12946. else
  12947. {
  12948. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  12949. isSuccess = ConfigurationStatus_Accepted;
  12950. }
  12951. }
  12952. else
  12953. {
  12954. isSuccess = ConfigurationStatus_Rejected;
  12955. }
  12956. }
  12957. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  12958. {
  12959. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  12960. {
  12961. strcpy(str, (const char*)value);
  12962. for(int i = 0; str[i]; i++)
  12963. {
  12964. str[i] = tolower(str[i]);
  12965. }
  12966. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12967. isSuccess = ConfigurationStatus_Accepted;
  12968. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12969. }
  12970. else
  12971. {
  12972. isSuccess = ConfigurationStatus_Rejected;
  12973. }
  12974. }
  12975. if(strcmp(key, "LocalPreAuthorize") == 0)
  12976. {
  12977. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  12978. {
  12979. strcpy(str, (const char*)value);
  12980. for(int i = 0; str[i]; i++)
  12981. {
  12982. str[i] = tolower(str[i]);
  12983. }
  12984. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12985. isSuccess = ConfigurationStatus_Accepted;
  12986. }
  12987. else
  12988. {
  12989. isSuccess = ConfigurationStatus_Rejected;
  12990. }
  12991. }
  12992. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  12993. {
  12994. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  12995. {
  12996. check_ascii = value[0];
  12997. if( (check_ascii < 48) || (check_ascii > 57) )
  12998. {
  12999. isSuccess = ConfigurationStatus_Rejected;
  13000. }
  13001. else
  13002. {
  13003. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  13004. isSuccess = ConfigurationStatus_Accepted;
  13005. }
  13006. }
  13007. else
  13008. {
  13009. isSuccess = ConfigurationStatus_Rejected;
  13010. }
  13011. }
  13012. if(strcmp(key, "MeterValuesAlignedData") == 0)
  13013. {
  13014. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13015. {
  13016. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  13017. isSuccess = ConfigurationStatus_Accepted;
  13018. }
  13019. else
  13020. {
  13021. isSuccess = ConfigurationStatus_Rejected;
  13022. }
  13023. }
  13024. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  13025. {
  13026. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13027. {
  13028. check_ascii = value[0];
  13029. if( (check_ascii < 48) || (check_ascii > 57) )
  13030. {
  13031. isSuccess = ConfigurationStatus_Rejected;
  13032. }
  13033. else
  13034. {
  13035. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13036. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  13037. isSuccess = ConfigurationStatus_Accepted;
  13038. }
  13039. }
  13040. else
  13041. {
  13042. isSuccess = ConfigurationStatus_Rejected;
  13043. }
  13044. }
  13045. if(strcmp(key, "MeterValuesSampledData") == 0 )
  13046. {
  13047. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  13048. {
  13049. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  13050. isSuccess = ConfigurationStatus_Accepted;
  13051. }
  13052. else
  13053. {
  13054. isSuccess = ConfigurationStatus_Rejected;
  13055. }
  13056. }
  13057. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  13058. {
  13059. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  13060. {
  13061. check_ascii = value[0];
  13062. if( (check_ascii < 48) || (check_ascii > 57) )
  13063. {
  13064. isSuccess = ConfigurationStatus_Rejected;
  13065. }
  13066. else
  13067. {
  13068. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13069. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  13070. isSuccess = ConfigurationStatus_Accepted;
  13071. }
  13072. }
  13073. else
  13074. {
  13075. isSuccess = ConfigurationStatus_Rejected;
  13076. }
  13077. }
  13078. if(strcmp(key, "MeterValueSampleInterval") == 0)
  13079. {
  13080. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  13081. {
  13082. check_ascii = value[0];
  13083. if( (check_ascii < 48) || (check_ascii > 57) )
  13084. {
  13085. isSuccess = ConfigurationStatus_Rejected;
  13086. }
  13087. else
  13088. {
  13089. if((atoi(value) == 0) || (atoi(value) >= 10))
  13090. {
  13091. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13092. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  13093. isSuccess = ConfigurationStatus_Accepted;
  13094. }
  13095. else
  13096. {
  13097. isSuccess = ConfigurationStatus_Rejected;
  13098. }
  13099. }
  13100. }
  13101. else
  13102. {
  13103. isSuccess = ConfigurationStatus_Rejected;
  13104. }
  13105. }
  13106. if(strcmp(key, "MinimumStatusDuration") == 0)
  13107. {
  13108. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  13109. {
  13110. check_ascii = value[0];
  13111. if( (check_ascii < 48) || (check_ascii > 57) )
  13112. {
  13113. isSuccess = ConfigurationStatus_Rejected;
  13114. }
  13115. else
  13116. {
  13117. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  13118. {
  13119. isSuccess = ConfigurationStatus_Rejected;
  13120. }
  13121. else
  13122. {
  13123. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  13124. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  13125. server_cycle_Status = atoi(value); //StatusNotification Cycle
  13126. isSuccess = ConfigurationStatus_Accepted;
  13127. }
  13128. }
  13129. }
  13130. else
  13131. {
  13132. isSuccess = ConfigurationStatus_Rejected;
  13133. }
  13134. }
  13135. if(strcmp(key, "NumberOfConnectors") == 0)
  13136. {
  13137. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  13138. {
  13139. check_ascii = value[0];
  13140. if( (check_ascii < 48) || (check_ascii > 57) )
  13141. {
  13142. isSuccess = ConfigurationStatus_Rejected;
  13143. }
  13144. else
  13145. {
  13146. //Charger.ResetRetries = Integer.parseInt(value);
  13147. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  13148. isSuccess = ConfigurationStatus_Accepted;
  13149. }
  13150. }
  13151. else
  13152. {
  13153. isSuccess = ConfigurationStatus_Rejected;
  13154. }
  13155. }
  13156. if(strcmp(key, "ResetRetries") == 0)
  13157. {
  13158. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  13159. {
  13160. check_ascii = value[0];
  13161. if( (check_ascii < 48) || (check_ascii > 57) )
  13162. {
  13163. isSuccess = ConfigurationStatus_Rejected;
  13164. }
  13165. else
  13166. {
  13167. //Charger.ResetRetries = Integer.parseInt(value);
  13168. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  13169. isSuccess = ConfigurationStatus_Accepted;
  13170. }
  13171. }
  13172. else
  13173. {
  13174. isSuccess = ConfigurationStatus_Rejected;
  13175. }
  13176. }
  13177. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  13178. {
  13179. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  13180. {
  13181. strcpy(str, (const char*)value);
  13182. for(int i = 0; str[i]; i++)
  13183. {
  13184. str[i] = tolower(str[i]);
  13185. }
  13186. if(strcmp(str, "notapplicable")== 0)
  13187. {
  13188. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  13189. isSuccess = ConfigurationStatus_Accepted;
  13190. }
  13191. else if(strcmp(str, "unknown")== 0)
  13192. {
  13193. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  13194. isSuccess = ConfigurationStatus_Accepted;
  13195. }
  13196. else if(strcmp(str, "rst")== 0)
  13197. {
  13198. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  13199. isSuccess = ConfigurationStatus_Accepted;
  13200. }
  13201. else if(strcmp(str, "rts")== 0)
  13202. {
  13203. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  13204. isSuccess = ConfigurationStatus_Accepted;
  13205. }
  13206. else if(strcmp(str, "srt")== 0)
  13207. {
  13208. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  13209. isSuccess = ConfigurationStatus_Accepted;
  13210. }
  13211. else if(strcmp(str, "str")== 0)
  13212. {
  13213. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  13214. isSuccess = ConfigurationStatus_Accepted;
  13215. }
  13216. else if(strcmp(str, "trs")== 0)
  13217. {
  13218. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  13219. isSuccess = ConfigurationStatus_Accepted;
  13220. }
  13221. else if(strcmp(str, "tsr")== 0)
  13222. {
  13223. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  13224. isSuccess = ConfigurationStatus_Accepted;
  13225. }
  13226. else
  13227. {
  13228. isSuccess = ConfigurationStatus_Rejected;
  13229. }
  13230. }
  13231. else
  13232. {
  13233. isSuccess = ConfigurationStatus_Rejected;
  13234. }
  13235. }
  13236. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  13237. {
  13238. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  13239. {
  13240. check_ascii = value[0];
  13241. if( (check_ascii < 48) || (check_ascii > 57) )
  13242. {
  13243. isSuccess = ConfigurationStatus_Rejected;
  13244. }
  13245. else
  13246. {
  13247. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  13248. isSuccess = ConfigurationStatus_Accepted;
  13249. }
  13250. }
  13251. else
  13252. {
  13253. isSuccess = ConfigurationStatus_Rejected;
  13254. }
  13255. }
  13256. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  13257. {
  13258. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  13259. {
  13260. strcpy(str, (const char*)value);
  13261. for(int i = 0; str[i]; i++)
  13262. {
  13263. str[i] = tolower(str[i]);
  13264. }
  13265. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  13266. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13267. isSuccess = ConfigurationStatus_Accepted;
  13268. }
  13269. else
  13270. {
  13271. isSuccess = ConfigurationStatus_Rejected;
  13272. }
  13273. }
  13274. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  13275. {
  13276. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  13277. {
  13278. strcpy(str, (const char*)value);
  13279. for(int i = 0; str[i]; i++)
  13280. {
  13281. str[i] = tolower(str[i]);
  13282. }
  13283. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  13284. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13285. isSuccess = ConfigurationStatus_Accepted;
  13286. }
  13287. else
  13288. {
  13289. isSuccess = ConfigurationStatus_Rejected;
  13290. }
  13291. }
  13292. if(strcmp(key, "StopTxnAlignedData") == 0)
  13293. {
  13294. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  13295. {
  13296. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  13297. isSuccess = ConfigurationStatus_Accepted;
  13298. }
  13299. else
  13300. {
  13301. isSuccess = ConfigurationStatus_Rejected;
  13302. }
  13303. }
  13304. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  13305. {
  13306. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  13307. {
  13308. check_ascii = value[0];
  13309. if( (check_ascii < 48) || (check_ascii > 57) )
  13310. {
  13311. isSuccess = ConfigurationStatus_Rejected;
  13312. }
  13313. else
  13314. {
  13315. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  13316. isSuccess = ConfigurationStatus_Accepted;
  13317. }
  13318. }
  13319. else
  13320. {
  13321. isSuccess = ConfigurationStatus_Rejected;
  13322. }
  13323. }
  13324. if(strcmp(key, "StopTxnSampledData") == 0)
  13325. {
  13326. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  13327. {
  13328. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  13329. isSuccess = ConfigurationStatus_Accepted;
  13330. }
  13331. else
  13332. {
  13333. isSuccess = ConfigurationStatus_Rejected;
  13334. }
  13335. }
  13336. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  13337. {
  13338. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  13339. {
  13340. check_ascii = value[0];
  13341. if( (check_ascii < 48) || (check_ascii > 57) )
  13342. {
  13343. isSuccess = ConfigurationStatus_Rejected;
  13344. }
  13345. else
  13346. {
  13347. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  13348. isSuccess = ConfigurationStatus_Accepted;
  13349. }
  13350. }
  13351. else
  13352. {
  13353. isSuccess = ConfigurationStatus_Rejected;
  13354. }
  13355. }
  13356. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  13357. {
  13358. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  13359. {
  13360. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  13361. isSuccess = ConfigurationStatus_Accepted;
  13362. }
  13363. else
  13364. {
  13365. isSuccess = ConfigurationStatus_Rejected;
  13366. }
  13367. }
  13368. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  13369. {
  13370. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  13371. {
  13372. check_ascii = value[0];
  13373. if( (check_ascii < 48) || (check_ascii > 57) )
  13374. {
  13375. isSuccess = ConfigurationStatus_Rejected;
  13376. }
  13377. else
  13378. {
  13379. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  13380. isSuccess = ConfigurationStatus_Accepted;
  13381. }
  13382. }
  13383. else
  13384. {
  13385. isSuccess = ConfigurationStatus_Rejected;
  13386. }
  13387. }
  13388. if(strcmp(key, "TransactionMessageAttempts") == 0)
  13389. {
  13390. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  13391. {
  13392. check_ascii = value[0];
  13393. if( (check_ascii < 48) || (check_ascii > 57) )
  13394. {
  13395. isSuccess = ConfigurationStatus_Rejected;
  13396. }
  13397. else
  13398. {
  13399. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  13400. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  13401. TransactionMessageAttemptsValue = atoi(value);
  13402. isSuccess = ConfigurationStatus_Accepted;
  13403. }
  13404. }
  13405. else
  13406. {
  13407. isSuccess = ConfigurationStatus_Rejected;
  13408. }
  13409. }
  13410. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  13411. {
  13412. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  13413. {
  13414. check_ascii = value[0];
  13415. if( (check_ascii < 48) || (check_ascii > 57) )
  13416. {
  13417. isSuccess = ConfigurationStatus_Rejected;
  13418. }
  13419. else
  13420. {
  13421. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  13422. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  13423. TransactionMessageRetryIntervalValue = atoi(value);
  13424. isSuccess = ConfigurationStatus_Accepted;
  13425. }
  13426. }
  13427. else
  13428. {
  13429. isSuccess = ConfigurationStatus_Rejected;
  13430. }
  13431. }
  13432. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  13433. {
  13434. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  13435. {
  13436. strcpy(str, (const char*)value);
  13437. for(int i = 0; str[i]; i++)
  13438. {
  13439. str[i] = tolower(str[i]);
  13440. }
  13441. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  13442. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13443. isSuccess = ConfigurationStatus_Accepted;
  13444. }
  13445. else
  13446. {
  13447. isSuccess = ConfigurationStatus_Rejected;
  13448. }
  13449. }
  13450. if(strcmp(key, "WebSocketPingInterval") == 0)
  13451. {
  13452. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  13453. {
  13454. check_ascii = value[0];
  13455. if( (check_ascii < 48) || (check_ascii > 57) )
  13456. {
  13457. isSuccess = ConfigurationStatus_Rejected;
  13458. }
  13459. else
  13460. {
  13461. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  13462. isSuccess = ConfigurationStatus_Accepted;
  13463. }
  13464. }
  13465. else
  13466. {
  13467. isSuccess = ConfigurationStatus_Rejected;
  13468. }
  13469. }
  13470. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  13471. {
  13472. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  13473. {
  13474. strcpy(str, (const char*)value);
  13475. for(int i = 0; str[i]; i++)
  13476. {
  13477. str[i] = tolower(str[i]);
  13478. }
  13479. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13480. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13481. isSuccess = ConfigurationStatus_Accepted;
  13482. }
  13483. else
  13484. {
  13485. isSuccess = ConfigurationStatus_Rejected;
  13486. }
  13487. }
  13488. if(strcmp(key, "AuthorizationKey") == 0)
  13489. {
  13490. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  13491. {
  13492. strcpy(str, (const char*)value);
  13493. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  13494. isSuccess = ConfigurationStatus_Accepted;
  13495. }
  13496. else
  13497. {
  13498. isSuccess = ConfigurationStatus_Rejected;
  13499. }
  13500. }
  13501. if(strcmp(key, "SecurityProfile") == 0)
  13502. {
  13503. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  13504. {
  13505. check_ascii = value[0];
  13506. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  13507. {
  13508. isSuccess = ConfigurationStatus_Rejected;
  13509. }
  13510. else if(check_ascii == 0x33)
  13511. {
  13512. isSuccess = NotSupported;
  13513. }
  13514. else
  13515. {
  13516. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  13517. {
  13518. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  13519. isSuccess = ConfigurationStatus_Accepted;
  13520. }
  13521. else
  13522. isSuccess = ConfigurationStatus_Rejected;
  13523. }
  13524. }
  13525. else
  13526. {
  13527. isSuccess = ConfigurationStatus_Rejected;
  13528. }
  13529. }
  13530. if(strcmp(key, "DefaultPrice") == 0)
  13531. {
  13532. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  13533. {
  13534. strcpy(str, (const char*)value);
  13535. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  13536. isSuccess = ConfigurationStatus_Accepted;
  13537. }
  13538. else
  13539. {
  13540. isSuccess = ConfigurationStatus_Rejected;
  13541. }
  13542. }
  13543. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  13544. {
  13545. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  13546. {
  13547. strcpy(str, (const char*)value);
  13548. for(int i = 0; str[i]; i++)
  13549. {
  13550. str[i] = tolower(str[i]);
  13551. }
  13552. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13553. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13554. isSuccess = ConfigurationStatus_Accepted;
  13555. }
  13556. else
  13557. {
  13558. isSuccess = ConfigurationStatus_Rejected;
  13559. }
  13560. }
  13561. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  13562. {
  13563. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  13564. {
  13565. strcpy(str, (const char*)value);
  13566. for(int i = 0; str[i]; i++)
  13567. {
  13568. str[i] = tolower(str[i]);
  13569. }
  13570. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13571. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13572. isSuccess = ConfigurationStatus_Accepted;
  13573. }
  13574. else
  13575. {
  13576. isSuccess = ConfigurationStatus_Rejected;
  13577. }
  13578. }
  13579. #if 0
  13580. //For OCPP Test Case
  13581. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  13582. {
  13583. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13584. {
  13585. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  13586. isSuccess = ConfigurationStatus_Accepted;
  13587. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13588. }
  13589. else
  13590. {
  13591. isSuccess = ConfigurationStatus_Rejected;
  13592. }
  13593. }
  13594. #endif
  13595. #if 1
  13596. if(strcmp(key, "LocalAuthListEnabled") == 0)
  13597. {
  13598. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13599. {
  13600. strcpy(str, (const char*)value);
  13601. for(int i = 0; str[i]; i++)
  13602. {
  13603. str[i] = tolower(str[i]);
  13604. }
  13605. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13606. isSuccess = ConfigurationStatus_Accepted;
  13607. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13608. }
  13609. else
  13610. {
  13611. isSuccess = ConfigurationStatus_Rejected;
  13612. }
  13613. }
  13614. #endif
  13615. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  13616. {
  13617. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  13618. {
  13619. check_ascii = value[0];
  13620. if( (check_ascii < 48) || (check_ascii > 57) )
  13621. {
  13622. isSuccess = ConfigurationStatus_Rejected;
  13623. }
  13624. else
  13625. {
  13626. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  13627. isSuccess = ConfigurationStatus_Accepted;
  13628. }
  13629. }
  13630. else
  13631. {
  13632. isSuccess = ConfigurationStatus_Rejected;
  13633. }
  13634. }
  13635. if(strcmp(key, "SendLocalListMaxLength") == 0)
  13636. {
  13637. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  13638. {
  13639. check_ascii = value[0];
  13640. if( (check_ascii < 48) || (check_ascii > 57) )
  13641. {
  13642. isSuccess = ConfigurationStatus_Rejected;
  13643. }
  13644. else
  13645. {
  13646. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  13647. isSuccess = ConfigurationStatus_Accepted;
  13648. }
  13649. }
  13650. else
  13651. {
  13652. isSuccess = ConfigurationStatus_Rejected;
  13653. }
  13654. }
  13655. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  13656. {
  13657. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  13658. {
  13659. strcpy(str, (const char*)value);
  13660. for(int i = 0; str[i]; i++)
  13661. {
  13662. str[i] = tolower(str[i]);
  13663. }
  13664. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13665. isSuccess = ConfigurationStatus_Accepted;
  13666. }
  13667. else
  13668. {
  13669. isSuccess = ConfigurationStatus_Rejected;
  13670. }
  13671. }
  13672. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  13673. {
  13674. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  13675. {
  13676. check_ascii = value[0];
  13677. if( (check_ascii < 48) || (check_ascii > 57) )
  13678. {
  13679. isSuccess = ConfigurationStatus_Rejected;
  13680. }
  13681. else
  13682. {
  13683. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  13684. isSuccess = ConfigurationStatus_Accepted;
  13685. }
  13686. }
  13687. else
  13688. {
  13689. isSuccess = ConfigurationStatus_Rejected;
  13690. }
  13691. }
  13692. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  13693. {
  13694. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  13695. {
  13696. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  13697. isSuccess = ConfigurationStatus_Accepted;
  13698. }
  13699. else
  13700. {
  13701. isSuccess = ConfigurationStatus_Rejected;
  13702. }
  13703. }
  13704. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  13705. {
  13706. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  13707. {
  13708. check_ascii = value[0];
  13709. if( (check_ascii < 48) || (check_ascii > 57) )
  13710. {
  13711. isSuccess = ConfigurationStatus_Rejected;
  13712. }
  13713. else
  13714. {
  13715. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  13716. isSuccess = ConfigurationStatus_Accepted;
  13717. }
  13718. }
  13719. else
  13720. {
  13721. isSuccess = ConfigurationStatus_Rejected;
  13722. }
  13723. }
  13724. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  13725. {
  13726. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  13727. {
  13728. strcpy(str, (const char*)value);
  13729. for(int i = 0; str[i]; i++)
  13730. {
  13731. str[i] = tolower(str[i]);
  13732. }
  13733. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13734. isSuccess = ConfigurationStatus_Accepted;
  13735. }
  13736. else
  13737. {
  13738. isSuccess = ConfigurationStatus_Rejected;
  13739. }
  13740. }
  13741. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  13742. {
  13743. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  13744. {
  13745. check_ascii = value[0];
  13746. if( (check_ascii < 48) || (check_ascii > 57) )
  13747. {
  13748. isSuccess = ConfigurationStatus_Rejected;
  13749. }
  13750. else
  13751. {
  13752. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  13753. isSuccess = ConfigurationStatus_Accepted;
  13754. }
  13755. }
  13756. else
  13757. {
  13758. isSuccess = ConfigurationStatus_Rejected;
  13759. }
  13760. }
  13761. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13762. return isSuccess;
  13763. }
  13764. int TransactionMessageAttemptsGet(void)
  13765. {
  13766. return TransactionMessageAttemptsValue;
  13767. }
  13768. int FirstHeartBeatResponse(void)
  13769. {
  13770. return FirstHeartBeat;
  13771. }
  13772. int TransactionMessageRetryIntervalGet(void)
  13773. {
  13774. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13775. }
  13776. int ReadHttpStatus(int sock)
  13777. {
  13778. //char c;
  13779. char buff[1024]="",*ptr=buff+1;
  13780. int bytes_received, status;
  13781. DEBUG_INFO("Begin Response ..\n");
  13782. while((bytes_received = recv(sock, ptr, 1, 0))){
  13783. if(bytes_received==-1){
  13784. perror("ReadHttpStatus");
  13785. exit(1);
  13786. }
  13787. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  13788. ptr++;
  13789. }
  13790. *ptr=0;
  13791. ptr=buff+1;
  13792. sscanf(ptr,"%*s %d ", &status);
  13793. DEBUG_INFO("%s\n",ptr);
  13794. DEBUG_INFO("status=%d\n",status);
  13795. DEBUG_INFO("End Response ..\n");
  13796. return (bytes_received>0)?status:0;
  13797. }
  13798. //the only filed that it parsed is 'Content-Length'
  13799. int ParseHeader(int sock)
  13800. {
  13801. //char c;
  13802. char buff[1024]="",*ptr=buff+4;
  13803. int bytes_received;
  13804. DEBUG_INFO("Begin HEADER ..\n");
  13805. while((bytes_received = recv(sock, ptr, 1, 0))){
  13806. if(bytes_received==-1){
  13807. perror("Parse Header");
  13808. exit(1);
  13809. }
  13810. if(
  13811. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  13812. (ptr[-1]=='\r') && (*ptr=='\n' )
  13813. ) break;
  13814. ptr++;
  13815. }
  13816. *ptr=0;
  13817. ptr=buff+4;
  13818. //printf("%s",ptr);
  13819. if(bytes_received){
  13820. ptr=strstr(ptr,"Content-Length:");
  13821. if(ptr){
  13822. sscanf(ptr,"%*s %d",&bytes_received);
  13823. }else
  13824. bytes_received=-1; //unknown size
  13825. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  13826. }
  13827. DEBUG_INFO("End HEADER ..\n");
  13828. return bytes_received ;
  13829. }
  13830. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  13831. {
  13832. int result = TRUE;
  13833. char rmFileCmd[100]={0};
  13834. char FilePath[100]={0};
  13835. char ftpbuf[200];
  13836. int systemresult;
  13837. //DEBUG_INFO("filename=%s\n",filename);
  13838. //DEBUG_INFO("url=%s\n",url);
  13839. sprintf(FilePath,"/mnt/%s",filename);
  13840. system("ping 8.8.8.8 &");
  13841. if((access(FilePath,F_OK))!=-1)
  13842. {
  13843. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13844. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13845. system(rmFileCmd);
  13846. }
  13847. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13848. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  13849. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13850. systemresult = system(ftpbuf);
  13851. //DEBUG_INFO("systemresult=%d\n",systemresult);
  13852. if(systemresult != 0)
  13853. {
  13854. DEBUG_INFO("http DownLoad error!\n");
  13855. result = FALSE;
  13856. }
  13857. system("pkill ping");
  13858. return result;
  13859. }
  13860. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  13861. {
  13862. int result = TRUE;
  13863. char rmFileCmd[100]={0};
  13864. char FilePath[100]={0};
  13865. char ftpbuf[200];
  13866. int systemresult;
  13867. //char temp[100];
  13868. sprintf(FilePath,"/mnt/%s",filename);
  13869. system("ping 8.8.8.8 &");
  13870. if((access(FilePath,F_OK))!=-1)
  13871. {
  13872. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13873. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13874. system(rmFileCmd);
  13875. }
  13876. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13877. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  13878. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  13879. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  13880. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13881. systemresult = system(ftpbuf);
  13882. //DEBUG_INFO("systemresult=%d\n",systemresult);
  13883. if(systemresult != 0)
  13884. {
  13885. printf("wget error!\n");
  13886. result = FALSE;
  13887. }
  13888. system("pkill ping");
  13889. return result;
  13890. }
  13891. int httpUploadFile(char *location, char *path, char *filename,char *url)
  13892. {
  13893. char rmFileCmd[100]={0};
  13894. char FilePath[100]={0};
  13895. char buf[512];
  13896. int systemresult = 0;
  13897. //DEBUG_INFO("filename=%s\n",filename);
  13898. //DEBUG_INFO("url=%s\n",url);
  13899. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  13900. if((access(FilePath,F_OK))!=-1)
  13901. {
  13902. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13903. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13904. system(rmFileCmd);
  13905. }
  13906. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  13907. if(fp == NULL)
  13908. {
  13909. DEBUG_INFO("log is NULL\n");
  13910. return FALSE;
  13911. }
  13912. else
  13913. {
  13914. fprintf(fp, "%s\n", url);
  13915. fprintf(fp, "%s\n", filename);
  13916. fclose(fp);
  13917. }
  13918. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  13919. if(phpFP == NULL)
  13920. {
  13921. DEBUG_INFO("PHP upload fail.\n");
  13922. return FALSE;
  13923. }
  13924. else
  13925. {
  13926. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  13927. {
  13928. if(strstr(buf, "result") != NULL)
  13929. {
  13930. sscanf(buf, "result: %d", &systemresult);
  13931. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  13932. }
  13933. }
  13934. pclose(phpFP);
  13935. }
  13936. if(systemresult != 1)
  13937. {
  13938. DEBUG_INFO("HTTP upload error!\n");
  13939. return FALSE;
  13940. }
  13941. return TRUE;
  13942. }
  13943. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  13944. {
  13945. struct hostent* server;
  13946. char *IPbuffer;
  13947. char ftpbuf[200];
  13948. int systemresult;
  13949. // To retrieve host information
  13950. server = gethostbyname(location);
  13951. // To convert an Internet network
  13952. // address into ASCII string
  13953. IPbuffer = inet_ntoa(*((struct in_addr*)
  13954. server->h_addr_list[0]));
  13955. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13956. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  13957. /* format : ftpput -u username -p passwd IP target source*/
  13958. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  13959. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  13960. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13961. systemresult = system(ftpbuf);
  13962. DEBUG_INFO("systemresult=%d\n",systemresult);
  13963. if(systemresult != 0)
  13964. {
  13965. DEBUG_INFO("ftpput error!\n");
  13966. return FALSE;
  13967. }
  13968. return TRUE;
  13969. }
  13970. int GetOcppServerURL()
  13971. {
  13972. int result = FALSE;
  13973. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  13974. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  13975. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  13976. struct yuarel url;
  13977. char urlStr[512];
  13978. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  13979. {
  13980. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  13981. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13982. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  13983. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  13984. if(yuarel_parse(&url, urlStr) != -1)
  13985. {
  13986. sprintf(OcppProtocol, "%s", url.scheme);
  13987. sprintf(OcppHost, "%s", url.host);
  13988. if(url.path == NULL)
  13989. OcppTempPath[0] = '\0';
  13990. else
  13991. {
  13992. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  13993. {
  13994. sprintf(OcppTempPath, "%s/", url.path);
  13995. }
  13996. else
  13997. {
  13998. sprintf(OcppTempPath, "%s", url.path);
  13999. }
  14000. }
  14001. if(url.port == 0)
  14002. {
  14003. if(strcmp(OcppProtocol, "wss") == 0)
  14004. OcppPort = 443;
  14005. else
  14006. OcppPort = 80;
  14007. }
  14008. else
  14009. OcppPort = url.port;
  14010. result = TRUE;
  14011. }
  14012. }
  14013. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  14014. {
  14015. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  14016. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14017. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  14018. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  14019. if(yuarel_parse(&url, urlStr) != -1)
  14020. {
  14021. sprintf(OcppProtocol, "%s", url.scheme);
  14022. sprintf(OcppHost, "%s", url.host);
  14023. if(url.path == NULL)
  14024. OcppTempPath[0] = '\0';
  14025. else
  14026. sprintf(OcppTempPath, "%s", url.path);
  14027. if(url.port == 0)
  14028. {
  14029. if(strcmp(OcppProtocol, "wss") == 0)
  14030. OcppPort = 443;
  14031. else
  14032. OcppPort = 80;
  14033. }
  14034. else
  14035. OcppPort = url.port;
  14036. result = TRUE;
  14037. }
  14038. }
  14039. else
  14040. {
  14041. strcpy(OcppHost,"");
  14042. }
  14043. return result;
  14044. }
  14045. int GetOcppPath()
  14046. {
  14047. int result = FALSE;
  14048. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  14049. {
  14050. if(OcppTempPath == NULL)
  14051. {
  14052. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  14053. }
  14054. else
  14055. {
  14056. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  14057. }
  14058. result = TRUE;
  14059. goto End;
  14060. }
  14061. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  14062. {
  14063. if(OcppTempPath == NULL)
  14064. {
  14065. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  14066. }
  14067. else
  14068. {
  14069. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  14070. }
  14071. result = TRUE;
  14072. goto End;
  14073. }
  14074. else
  14075. {
  14076. strcpy(OcppPath,"");
  14077. }
  14078. End:
  14079. return result;
  14080. }
  14081. int GetOcppPort()
  14082. {
  14083. return OcppPort;
  14084. }
  14085. int GetOcppConnStatus(void)
  14086. {
  14087. return ShmOCPP16Data->OcppConnStatus;
  14088. }
  14089. void SetOcppConnStatus(uint8_t status)
  14090. {
  14091. ShmOCPP16Data->OcppConnStatus = status;
  14092. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  14093. }
  14094. int GetHeartBeatWithNOResponse(void)
  14095. {
  14096. return HeartBeatWithNOResponse;
  14097. }
  14098. void SetHeartBeatWithNOResponse(void)
  14099. {
  14100. HeartBeatWithNOResponse = 0;
  14101. }
  14102. void GetStartTransactionIdTag(int gun_index)
  14103. {
  14104. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  14105. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  14106. }
  14107. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  14108. {
  14109. char ch;
  14110. FILE *fptr1;
  14111. int temptransactionId;
  14112. char str[100]={0};
  14113. temptransactionId = 0;
  14114. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  14115. {
  14116. DEBUG_INFO("IdTag is empty.\n");
  14117. return temptransactionId;
  14118. }
  14119. /*------ Read the file ----------------*/
  14120. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  14121. if (!fptr1)
  14122. {
  14123. DEBUG_INFO("QueueTransactionId file open error.\n");
  14124. //printf(" File not found or unable to open the input file!!\n");
  14125. return temptransactionId;
  14126. }
  14127. ch=fgetc(fptr1);
  14128. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  14129. rewind(fptr1);
  14130. if(ch!=EOF)
  14131. {
  14132. // printf("%c",ch);
  14133. while (fgets(str, 100, fptr1) != NULL)
  14134. {
  14135. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14136. if(str[0]=='\0')
  14137. {
  14138. break;
  14139. }
  14140. char *revbuf[8] = {0}; // Variable store string split
  14141. int num = 0;// Quantity after string split
  14142. DEBUG_INFO("Transaction queue data= %s\n", str);
  14143. splitstring(str,",",revbuf,&num); // String split
  14144. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  14145. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  14146. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  14147. DEBUG_INFO("------------------------------\n");
  14148. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  14149. {
  14150. if(isStopTransaction)
  14151. {
  14152. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  14153. {
  14154. temptransactionId = atoi(revbuf[2]);
  14155. //break;
  14156. }
  14157. }
  14158. else
  14159. {
  14160. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  14161. {
  14162. temptransactionId = atoi(revbuf[2]);
  14163. //break;
  14164. }
  14165. }
  14166. }
  14167. }
  14168. }
  14169. else
  14170. DEBUG_INFO("EOF\n");
  14171. fclose(fptr1);
  14172. /*------- End of reading ---------------*/
  14173. return temptransactionId;
  14174. }
  14175. void SetTransactionIdZero(int transactionId)
  14176. {
  14177. char ch;
  14178. FILE *fptr1, *fptr2;
  14179. int temptransactionId = 0;
  14180. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  14181. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  14182. if (!fptr1)
  14183. {
  14184. //printf(" File not found or unable to open the input file!!\n");
  14185. return ;
  14186. }
  14187. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  14188. if (!fptr2)
  14189. {
  14190. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  14191. fclose(fptr1);
  14192. return ;
  14193. }
  14194. ch=fgetc(fptr1);
  14195. rewind(fptr1);
  14196. if(ch!=EOF)
  14197. {
  14198. // copy all contents to the temporary file except the specific line
  14199. while (fgets(str, 100, fptr1) != NULL)
  14200. {
  14201. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14202. if(str[0]=='\0')
  14203. {
  14204. break;
  14205. }
  14206. char *revbuf[8] = {0};
  14207. int num = 0;
  14208. strcpy(strtemp, str);
  14209. splitstring(str,",",revbuf,&num);
  14210. if(revbuf[2][0] != '\0')
  14211. {
  14212. temptransactionId = atoi(revbuf[2]);
  14213. if(transactionId != temptransactionId)
  14214. {
  14215. fprintf(fptr2, "%s\n", strtemp);
  14216. }
  14217. }
  14218. }
  14219. }
  14220. fclose(fptr1);
  14221. fclose(fptr2);
  14222. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  14223. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  14224. /*------ Read the file ----------------*/
  14225. }
  14226. int InternetDisconnect(void)
  14227. {
  14228. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  14229. }
  14230. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  14231. void storeTempStopTransaction(int gun_index)
  14232. {
  14233. char guid[37]={0};
  14234. int tempIndex = 0;
  14235. char TempStopTransaction[256];
  14236. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  14237. DEBUG_INFO("storeTempStopTransaction...\n");
  14238. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  14239. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  14240. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  14241. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14242. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14243. {
  14244. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14245. {
  14246. tempIndex = ((gun_index==2) ? 1: 0);
  14247. }
  14248. else
  14249. {
  14250. tempIndex = gun_index;
  14251. }
  14252. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14253. {
  14254. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14255. {
  14256. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  14257. }
  14258. }// END OF CHAdeMO_QUANTITY
  14259. }
  14260. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14261. {
  14262. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14263. {
  14264. tempIndex = ((gun_index==2) ? 1: 0);
  14265. }
  14266. else
  14267. {
  14268. tempIndex = gun_index;
  14269. }
  14270. for (int index = 0; index < CCS_QUANTITY; index++)
  14271. {
  14272. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14273. {
  14274. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  14275. }
  14276. }// END OF CCS_QUANTITY
  14277. }
  14278. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14279. {
  14280. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14281. {
  14282. tempIndex = ((gun_index==2) ? 1: 0);
  14283. }
  14284. else
  14285. {
  14286. tempIndex = gun_index;
  14287. }
  14288. for (int index = 0; index < GB_QUANTITY; index++)
  14289. {
  14290. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14291. {
  14292. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  14293. }
  14294. }// END OF GB_QUANTITY
  14295. }
  14296. else if(gunType[gun_index] == GUN_TYPE_DO)
  14297. {
  14298. tempIndex = gun_index;
  14299. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14300. {
  14301. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14302. {
  14303. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  14304. }
  14305. }
  14306. }
  14307. else
  14308. {
  14309. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14310. {
  14311. tempIndex = 2;
  14312. }
  14313. else
  14314. {
  14315. tempIndex = gun_index;
  14316. }
  14317. for (int index = 0; index < AC_QUANTITY; index++)
  14318. {
  14319. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14320. {
  14321. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  14322. }
  14323. }// END OF AC_QUANTITY
  14324. }
  14325. //Stop Transaction Time
  14326. struct timeval tmnow;
  14327. struct tm *tm;
  14328. char buf[28];//, usec_buf[6];
  14329. gettimeofday(&tmnow, NULL);
  14330. time_t t;
  14331. t = time(NULL);
  14332. /*UTC time and date*/
  14333. tm = gmtime(&t);
  14334. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  14335. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  14336. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  14337. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  14338. random_uuid(guid);
  14339. /***********************************transactionData******************************************************/
  14340. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  14341. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  14342. //=================================
  14343. //1. Transaction_Begin
  14344. //=================================
  14345. //============================== Energy.Active.Import.Interval ===========================================
  14346. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  14347. {
  14348. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  14349. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  14350. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  14351. 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*/]);
  14352. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14353. 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))
  14354. {
  14355. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  14356. }
  14357. else
  14358. {
  14359. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  14360. }
  14361. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  14362. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  14363. }
  14364. //=================================
  14365. //2. Transaction_End
  14366. //=================================
  14367. //2.1====================================== Current.Import L1 ==============================================
  14368. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  14369. {
  14370. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  14371. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14372. {
  14373. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14374. {
  14375. tempIndex = ((gun_index==2) ? 1: 0);
  14376. }
  14377. else
  14378. {
  14379. tempIndex = gun_index;
  14380. }
  14381. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14382. {
  14383. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14384. {
  14385. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14386. }
  14387. }// End of for CHAdeMO_QUANTITY
  14388. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14389. }
  14390. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14391. {
  14392. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14393. {
  14394. tempIndex = ((gun_index==2) ? 1: 0);
  14395. }
  14396. else
  14397. {
  14398. tempIndex = gun_index;
  14399. }
  14400. for (int index = 0; index < CCS_QUANTITY; index++)
  14401. {
  14402. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14403. {
  14404. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14405. }
  14406. }// End of for CCS_QUANTITY
  14407. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14408. }
  14409. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14410. {
  14411. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14412. {
  14413. tempIndex = ((gun_index==2) ? 1: 0);
  14414. }
  14415. else
  14416. {
  14417. tempIndex = gun_index;
  14418. }
  14419. for (int index = 0; index < GB_QUANTITY; index++)
  14420. {
  14421. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14422. {
  14423. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14424. }
  14425. }// End of for GB_QUANTITY
  14426. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14427. }
  14428. else if(gunType[gun_index] == GUN_TYPE_DO)
  14429. {
  14430. tempIndex = gun_index;
  14431. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14432. {
  14433. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14434. {
  14435. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14436. }
  14437. }
  14438. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14439. }
  14440. else
  14441. {
  14442. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14443. {
  14444. tempIndex = 2;
  14445. }
  14446. else
  14447. {
  14448. tempIndex = gun_index;
  14449. }
  14450. for (int index = 0; index < AC_QUANTITY; index++)
  14451. {
  14452. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14453. {
  14454. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  14455. }
  14456. }// End of for AC_QUANTITY
  14457. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  14458. }
  14459. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14460. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  14461. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  14462. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  14463. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  14464. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14465. }
  14466. //2.2===================================== Energy.Active.Import.Interval ==========================================
  14467. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  14468. {
  14469. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14470. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14471. {
  14472. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14473. {
  14474. tempIndex = ((gun_index==2) ? 1: 0);
  14475. }
  14476. else
  14477. {
  14478. tempIndex = gun_index;
  14479. }
  14480. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14481. {
  14482. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14483. {
  14484. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14485. }
  14486. }// END OF CHAdeMO_QUANTITY
  14487. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14488. }
  14489. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14490. {
  14491. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14492. {
  14493. tempIndex = ((gun_index==2) ? 1: 0);
  14494. }
  14495. else
  14496. {
  14497. tempIndex = gun_index;
  14498. }
  14499. for (int index = 0; index < CCS_QUANTITY; index++)
  14500. {
  14501. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14502. {
  14503. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14504. }
  14505. }// END OF CCS_QUANTITY
  14506. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14507. }
  14508. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14509. {
  14510. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14511. {
  14512. tempIndex = ((gun_index==2) ? 1: 0);
  14513. }
  14514. else
  14515. {
  14516. tempIndex = gun_index;
  14517. }
  14518. for (int index = 0; index < GB_QUANTITY; index++)
  14519. {
  14520. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14521. {
  14522. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14523. }
  14524. }// END OF GB_QUANTITY
  14525. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14526. }
  14527. else if(gunType[gun_index] == GUN_TYPE_DO)
  14528. {
  14529. tempIndex = gun_index;
  14530. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14531. {
  14532. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14533. {
  14534. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14535. }
  14536. }
  14537. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14538. }
  14539. else
  14540. {
  14541. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14542. {
  14543. tempIndex = 2;
  14544. }
  14545. else
  14546. {
  14547. tempIndex = gun_index;
  14548. }
  14549. for (int index = 0; index < AC_QUANTITY; index++)
  14550. {
  14551. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14552. {
  14553. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14554. }
  14555. }// END OF AC_QUANTITY
  14556. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  14557. }
  14558. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14559. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  14560. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  14561. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  14562. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  14563. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  14564. }
  14565. //2.3====================================== Power.Active.Import =========================================
  14566. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  14567. {
  14568. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14569. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14570. {
  14571. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14572. {
  14573. tempIndex = ((gun_index==2) ? 1: 0);
  14574. }
  14575. else
  14576. {
  14577. tempIndex = gun_index;
  14578. }
  14579. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14580. {
  14581. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14582. {
  14583. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14584. }
  14585. } // End for CHAdeMO_QUANTITY
  14586. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14587. }
  14588. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14589. {
  14590. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14591. {
  14592. tempIndex = ((gun_index==2) ? 1: 0);
  14593. }
  14594. else
  14595. {
  14596. tempIndex = gun_index;
  14597. }
  14598. for (int index = 0; index < CCS_QUANTITY; index++)
  14599. {
  14600. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14601. {
  14602. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14603. }
  14604. } // END for CCS_QUANTITY
  14605. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14606. }
  14607. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14608. {
  14609. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14610. {
  14611. tempIndex = ((gun_index==2) ? 1: 0);
  14612. }
  14613. else
  14614. {
  14615. tempIndex = gun_index;
  14616. }
  14617. for (int index = 0; index < GB_QUANTITY; index++)
  14618. {
  14619. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14620. {
  14621. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14622. }
  14623. }// END for GB_QUANTITY
  14624. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14625. }
  14626. else if(gunType[gun_index] == GUN_TYPE_DO)
  14627. {
  14628. tempIndex = gun_index;
  14629. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14630. {
  14631. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14632. {
  14633. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14634. }
  14635. }
  14636. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14637. }
  14638. else
  14639. {
  14640. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14641. {
  14642. tempIndex = 2;
  14643. }
  14644. else
  14645. {
  14646. tempIndex = gun_index;
  14647. }
  14648. for (int index = 0; index < AC_QUANTITY; index++)
  14649. {
  14650. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14651. {
  14652. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14653. }
  14654. } // END for AC_QUANTITY
  14655. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  14656. }
  14657. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14658. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  14659. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  14660. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  14661. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  14662. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  14663. }
  14664. //2.4====================================== Voltage L1 ====================================================
  14665. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  14666. {
  14667. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14668. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14669. {
  14670. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14671. {
  14672. tempIndex = ((gun_index==2) ? 1: 0);
  14673. }
  14674. else
  14675. {
  14676. tempIndex = gun_index;
  14677. }
  14678. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14679. {
  14680. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14681. {
  14682. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14683. }
  14684. } // END OF FOR CHAdeMO_QUANTITY
  14685. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14686. }
  14687. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14688. {
  14689. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14690. {
  14691. tempIndex = ((gun_index==2) ? 1: 0);
  14692. }
  14693. else
  14694. {
  14695. tempIndex = gun_index;
  14696. }
  14697. for (int index = 0; index < CCS_QUANTITY; index++)
  14698. {
  14699. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14700. {
  14701. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14702. }
  14703. } // END OF FOR CCS_QUANTITY
  14704. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14705. }
  14706. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14707. {
  14708. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14709. {
  14710. tempIndex = ((gun_index==2) ? 1: 0);
  14711. }
  14712. else
  14713. {
  14714. tempIndex = gun_index;
  14715. }
  14716. for (int index = 0; index < GB_QUANTITY; index++)
  14717. {
  14718. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14719. {
  14720. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14721. }
  14722. } // END OF FOR GB_QUANTITY
  14723. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14724. }
  14725. else if(gunType[gun_index] == GUN_TYPE_DO)
  14726. {
  14727. tempIndex = gun_index;
  14728. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14729. {
  14730. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14731. {
  14732. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14733. }
  14734. }
  14735. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14736. }
  14737. else
  14738. {
  14739. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14740. {
  14741. tempIndex = 2;
  14742. }
  14743. else
  14744. {
  14745. tempIndex = gun_index;
  14746. }
  14747. for (int index = 0; index < AC_QUANTITY; index++)
  14748. {
  14749. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14750. {
  14751. 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
  14752. }
  14753. } // END OF FOR AC_QUANTITY
  14754. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  14755. }
  14756. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14757. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  14758. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  14759. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  14760. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  14761. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  14762. }
  14763. //2.5============================================== End SoC =========================================================
  14764. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  14765. {
  14766. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14767. 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))
  14768. {
  14769. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  14770. {
  14771. tempIndex = ((gun_index==2) ? 1: 0);
  14772. }
  14773. else
  14774. {
  14775. tempIndex = gun_index;
  14776. }
  14777. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14778. {
  14779. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14780. {
  14781. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14782. {
  14783. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  14784. }
  14785. }
  14786. }
  14787. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14788. {
  14789. for (int index = 0; index < CCS_QUANTITY; index++)
  14790. {
  14791. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14792. {
  14793. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  14794. }
  14795. }
  14796. }
  14797. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14798. {
  14799. for (int index = 0; index < GB_QUANTITY; index++)
  14800. {
  14801. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14802. {
  14803. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  14804. }
  14805. }
  14806. }
  14807. else if(gunType[gun_index] == GUN_TYPE_DO)
  14808. {
  14809. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14810. {
  14811. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14812. {
  14813. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  14814. }
  14815. }
  14816. }
  14817. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14818. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  14819. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  14820. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  14821. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  14822. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  14823. } // END FOR DC CASE
  14824. }
  14825. //2.6====================================== Current.Import L2 ==============================================
  14826. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  14827. {
  14828. // AC 3 phase L2 current
  14829. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  14830. {
  14831. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14832. {
  14833. tempIndex = 2;
  14834. }
  14835. else
  14836. {
  14837. tempIndex = gun_index;
  14838. }
  14839. for (int index = 0; index < AC_QUANTITY; index++)
  14840. {
  14841. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14842. {
  14843. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  14844. }
  14845. }// End of for AC_QUANTITY
  14846. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  14847. }
  14848. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14849. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  14850. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  14851. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  14852. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14853. }
  14854. //2.7====================================== Current.Import L3 ==============================================
  14855. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  14856. {
  14857. // AC 3 phase L3 current
  14858. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  14859. {
  14860. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14861. {
  14862. tempIndex = 2;
  14863. }
  14864. else
  14865. {
  14866. tempIndex = gun_index;
  14867. }
  14868. for (int index = 0; index < AC_QUANTITY; index++)
  14869. {
  14870. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14871. {
  14872. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  14873. }
  14874. }// End of for AC_QUANTITY
  14875. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  14876. }
  14877. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14878. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  14879. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  14880. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  14881. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14882. }
  14883. //2.9====================================== Voltage L2 ====================================================
  14884. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  14885. {
  14886. // AC 3 phase L2 volatge
  14887. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  14888. {
  14889. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14890. {
  14891. tempIndex = 2;
  14892. }
  14893. else
  14894. {
  14895. tempIndex = gun_index;
  14896. }
  14897. for (int index = 0; index < AC_QUANTITY; index++)
  14898. {
  14899. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14900. {
  14901. 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
  14902. }
  14903. } // END OF FOR AC_QUANTITY
  14904. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  14905. }
  14906. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14907. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  14908. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  14909. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  14910. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  14911. }
  14912. //2.10====================================== Voltage L3 ====================================================
  14913. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  14914. {
  14915. // AC 3 phase L3 volatge
  14916. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  14917. {
  14918. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14919. {
  14920. tempIndex = 2;
  14921. }
  14922. else
  14923. {
  14924. tempIndex = gun_index;
  14925. }
  14926. for (int index = 0; index < AC_QUANTITY; index++)
  14927. {
  14928. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14929. {
  14930. 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
  14931. }
  14932. } // END OF FOR AC_QUANTITY
  14933. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  14934. }
  14935. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14936. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  14937. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  14938. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  14939. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  14940. }
  14941. //====================== Start SoC ================================
  14942. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  14943. {
  14944. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14945. 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))
  14946. {
  14947. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  14948. {
  14949. tempIndex = ((gun_index==2) ? 1: 0);
  14950. }
  14951. else
  14952. {
  14953. tempIndex = gun_index;
  14954. }
  14955. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14956. {
  14957. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14958. {
  14959. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14960. {
  14961. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  14962. }
  14963. }
  14964. }
  14965. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14966. {
  14967. for (int index = 0; index < CCS_QUANTITY; index++)
  14968. {
  14969. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14970. {
  14971. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  14972. }
  14973. }
  14974. }
  14975. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14976. {
  14977. for (int index = 0; index < GB_QUANTITY; index++)
  14978. {
  14979. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14980. {
  14981. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  14982. }
  14983. }
  14984. }
  14985. else if(gunType[gun_index] == GUN_TYPE_DO)
  14986. {
  14987. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14988. {
  14989. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14990. {
  14991. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  14992. }
  14993. }
  14994. }
  14995. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  14996. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  14997. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  14998. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  14999. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  15000. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15001. } // END FOR DC CASE
  15002. }
  15003. //======================================== Message create ==============================================
  15004. json_object *StopTransaction = json_object_new_object();
  15005. json_object *transactionDatas = json_object_new_array();
  15006. json_object *sampledValues = json_object_new_array();
  15007. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  15008. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  15009. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  15010. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  15011. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  15012. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  15013. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  15014. {
  15015. json_object *transactionData = json_object_new_object();
  15016. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  15017. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  15018. {
  15019. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  15020. {
  15021. json_object *sampledValue = json_object_new_object();
  15022. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  15023. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  15024. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  15025. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  15026. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  15027. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  15028. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  15029. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  15030. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  15031. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  15032. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  15033. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  15034. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  15035. json_object_array_add(sampledValues, sampledValue);
  15036. }
  15037. }
  15038. json_object_object_add(transactionData, "sampledValue", sampledValues);
  15039. json_object_array_add(transactionDatas, transactionData);
  15040. }
  15041. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  15042. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  15043. ,MESSAGE_TYPE_CALL
  15044. ,guid
  15045. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  15046. json_object_put(StopTransaction);
  15047. // Check File "TempStopTransaction" Exist
  15048. if((access(TempStopTransaction,F_OK))!=-1)
  15049. {
  15050. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  15051. fclose(fopen(TempStopTransaction, "w"));
  15052. }
  15053. else
  15054. {
  15055. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  15056. FILE *log = fopen(TempStopTransaction, "w+");
  15057. if(log == NULL)
  15058. {
  15059. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  15060. return ;
  15061. }
  15062. else
  15063. {
  15064. fclose(log);
  15065. }
  15066. }
  15067. //Add TempStopTransaction | Update TempStopTransaction
  15068. // open file for writing
  15069. FILE *outfile;
  15070. outfile = fopen (TempStopTransaction, "a");
  15071. //DEBUG_INFO("data = %s\n", queuedata);
  15072. fputs(queuedata, outfile);
  15073. fputs("\n", outfile);
  15074. fclose (outfile);
  15075. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15076. }
  15077. void checkTempStopTransaction(int gun_index)
  15078. {
  15079. FILE *fptr1;
  15080. char ch;
  15081. char str[QUEUE_MESSAGE_LENGTH]={0};
  15082. char guid[37]={0};
  15083. char tempdata[65]={0};
  15084. char connectorStr[2]={0};
  15085. char TempStopTransaction[256];
  15086. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  15087. fptr1 = fopen(TempStopTransaction, "r");
  15088. //TempStopTransaction格式: 槍號,StopTransaction封包
  15089. if (!fptr1)
  15090. {
  15091. //printf(" File not found or unable to open the input file!!\n");
  15092. return ;
  15093. }
  15094. ch=fgetc(fptr1);
  15095. //printf(" Now the content of the file %s is : \n",fname);
  15096. rewind(fptr1);
  15097. if(ch!=EOF)
  15098. {
  15099. // copy all contents to the temporary file except the specific line
  15100. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  15101. {
  15102. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15103. if(str[0]=='\0')
  15104. {
  15105. break;
  15106. }
  15107. //TempStopTransaction格式: 槍號,StopTransaction封包
  15108. strncpy(connectorStr, str, 1);
  15109. if(atoi(connectorStr) != (gun_index+1))
  15110. {
  15111. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  15112. fclose(fptr1);
  15113. return ;
  15114. }
  15115. //random_uuid(guid);
  15116. strncpy(guid, str+6, 36); //copy guid
  15117. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  15118. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  15119. {
  15120. //DEBUG_INFO("StopTransaction mapitem pass\n");
  15121. }
  15122. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  15123. OCPP_insert_transaction_msg(NO, str);
  15124. memset(str,0,ARRAY_SIZE(str));
  15125. }
  15126. }
  15127. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  15128. fclose(fptr1);
  15129. remove(TempStopTransaction); // remove the original file
  15130. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15131. }
  15132. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  15133. {
  15134. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  15135. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  15136. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  15137. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  15138. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  15139. }
  15140. int GetWebSocketPingInterval(void)
  15141. {
  15142. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15143. }
  15144. int GetServerSign(void)
  15145. {
  15146. return server_sign;
  15147. }
  15148. uint8_t GetOcppSecurityProfile()
  15149. {
  15150. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15151. }
  15152. void GetOcppChargerBoxId(uint8_t *data)
  15153. {
  15154. sprintf((char*)data, "%s", ShmOCPP16Data->ChargeBoxId);
  15155. }
  15156. void GetOcppSecurityPassword(uint8_t *data)
  15157. {
  15158. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15159. }
  15160. void SetOcppVersion(uint8_t *version)
  15161. {
  15162. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  15163. DEBUG_INFO("ocpp version: %s\n", version);
  15164. if(strstr((char*)version, "ocpp1.6") != NULL)
  15165. {
  15166. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  15167. }
  15168. else if(strstr((char*)version, "ocpp2.0") != NULL)
  15169. {
  15170. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  15171. system("pkill OcppBackend");
  15172. }
  15173. }
  15174. void SetServerSign(int value)
  15175. {
  15176. server_sign = value;
  15177. }
  15178. int GetBootNotificationInterval(void)
  15179. {
  15180. return BootNotificationInterval;
  15181. }
  15182. int GetInternetConn(void)
  15183. {
  15184. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  15185. }
  15186. int isConnectorInitMode(int gun_index)
  15187. {
  15188. int tempIndex = 0;
  15189. int result = TRUE;
  15190. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15191. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15192. {
  15193. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15194. {
  15195. tempIndex = ((gun_index==2) ? 1: 0);
  15196. }
  15197. else
  15198. {
  15199. tempIndex = gun_index;
  15200. }
  15201. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15202. {
  15203. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  15204. {
  15205. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15206. } //end of the same index
  15207. }//end of for CHAdeMO_QUANTITY
  15208. }
  15209. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15210. {
  15211. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15212. {
  15213. tempIndex = ((gun_index==2) ? 1: 0);
  15214. }
  15215. else
  15216. {
  15217. tempIndex = gun_index;
  15218. }
  15219. for (int index = 0; index < CCS_QUANTITY; index++)
  15220. {
  15221. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15222. {
  15223. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15224. } //end of the same index
  15225. } // end of for CCS_QUANTITY
  15226. }
  15227. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15228. {
  15229. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15230. {
  15231. tempIndex = ((gun_index==2) ? 1: 0);
  15232. }
  15233. else
  15234. {
  15235. tempIndex = gun_index;
  15236. }
  15237. for (int index = 0; index < GB_QUANTITY; index++)
  15238. {
  15239. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15240. {
  15241. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15242. } //end of the same index
  15243. } // end of for GB_QUANTITY
  15244. }
  15245. else if(gunType[gun_index] == GUN_TYPE_DO)
  15246. {
  15247. tempIndex = gun_index;
  15248. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15249. {
  15250. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15251. {
  15252. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15253. } //end of the same index
  15254. }
  15255. }
  15256. else
  15257. {
  15258. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15259. {
  15260. tempIndex = 2;
  15261. }
  15262. else
  15263. {
  15264. tempIndex = gun_index;
  15265. }
  15266. for (int index = 0; index < AC_QUANTITY; index++)
  15267. {
  15268. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15269. {
  15270. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15271. }//end of the same index
  15272. }//end of for AC_QUANTITY
  15273. }
  15274. return result;
  15275. }
  15276. void refreshProcDogTimer()
  15277. {
  15278. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  15279. }
  15280. void InitialSystemValue(void)
  15281. {
  15282. int connectorIndex = 0;
  15283. //int valueASCII = 0;
  15284. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  15285. gunTotalNumber=0;
  15286. SystemInitial = 0;
  15287. localversion=0;
  15288. BootNotificationInterval = 0;
  15289. authorizeRetryTimes = 0;
  15290. GunStatusInterval = 10;
  15291. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15292. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15293. //Hear Beat
  15294. HeartBeatWithNOResponse = 0;
  15295. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  15296. FirstHeartBeat = 0;
  15297. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  15298. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  15299. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  15300. memset(statusModeChage, 0, ARRAY_SIZE(statusModeChage));
  15301. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  15302. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  15303. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  15304. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  15305. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  15306. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  15307. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  15308. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  15309. memset(gunType, 0, ARRAY_SIZE(gunType));
  15310. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  15311. {
  15312. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O')
  15313. {
  15314. // DO series
  15315. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  15316. {
  15317. SystemInitial = SystemInitial + 1;
  15318. gunTotalNumber = gunTotalNumber + 1;
  15319. gunType[connectorIndex] = GUN_TYPE_DO;
  15320. connectorIndex = connectorIndex + 1;
  15321. }
  15322. }
  15323. else
  15324. {
  15325. // DM, DW, DS series
  15326. //check connector / socket type (index: 8, 9, 10)
  15327. for(int index=7; index <10 ; index++)
  15328. {
  15329. if(index != 8)
  15330. {
  15331. // DC Connector
  15332. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  15333. {
  15334. SystemInitial = SystemInitial + 1;
  15335. gunTotalNumber = gunTotalNumber + 1;
  15336. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  15337. connectorIndex = connectorIndex + 1;
  15338. }
  15339. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  15340. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  15341. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  15342. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  15343. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  15344. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  15345. {
  15346. SystemInitial = SystemInitial + 1;
  15347. gunTotalNumber = gunTotalNumber + 1;
  15348. gunType[connectorIndex] = GUN_TYPE_CCS;
  15349. connectorIndex = connectorIndex + 1;
  15350. }
  15351. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  15352. {
  15353. SystemInitial = SystemInitial + 1;
  15354. gunTotalNumber = gunTotalNumber + 1;
  15355. gunType[connectorIndex] = GUN_TYPE_GBT;
  15356. connectorIndex = connectorIndex + 1;
  15357. }
  15358. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  15359. {
  15360. SystemInitial = SystemInitial + 1;
  15361. gunTotalNumber = gunTotalNumber + 1;
  15362. gunType[connectorIndex] = GUN_TYPE_DO;
  15363. connectorIndex = connectorIndex + 1;
  15364. }
  15365. }
  15366. else
  15367. {
  15368. // AC Connector
  15369. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  15370. {
  15371. SystemInitial = SystemInitial + 1;
  15372. gunTotalNumber = gunTotalNumber + 1;
  15373. gunType[connectorIndex] = GUN_TYPE_AC;
  15374. connectorIndex = connectorIndex + 1;
  15375. }
  15376. }
  15377. }
  15378. }
  15379. //DEBUG_INFO("DC ...\n");
  15380. }
  15381. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  15382. {
  15383. //check connector / socket type (index: 8, 9, 10)
  15384. for(int index=7; index <10 ; index++)
  15385. {
  15386. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  15387. {
  15388. SystemInitial = SystemInitial + 1;
  15389. gunTotalNumber = gunTotalNumber + 1;
  15390. gunType[connectorIndex] = GUN_TYPE_AC;
  15391. connectorIndex = connectorIndex + 1;
  15392. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  15393. }
  15394. }
  15395. }
  15396. //Status && ConnectorPlugIn Setting
  15397. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15398. {
  15399. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  15400. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  15401. }
  15402. for (int index = 0; index < CCS_QUANTITY; index++)
  15403. {
  15404. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  15405. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  15406. }
  15407. for (int index = 0; index < GB_QUANTITY; index++)
  15408. {
  15409. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  15410. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  15411. }
  15412. for (int index = 0; index < AC_QUANTITY; index++)
  15413. {
  15414. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  15415. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  15416. }
  15417. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15418. {
  15419. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  15420. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  15421. }
  15422. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  15423. {
  15424. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  15425. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  15426. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  15427. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  15428. }
  15429. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  15430. clientTime.Heartbeat=time((time_t*)NULL);
  15431. sleep(1);
  15432. }
  15433. void LWS_Send(char * str)
  15434. {
  15435. //=====================================================
  15436. // Check InternetConn 0: disconnected, 1: connected
  15437. //====================================================
  15438. if(GetOcppConnStatus() == 0)
  15439. {
  15440. DEBUG_INFO("offline now !!!\n");
  15441. return;
  15442. }
  15443. pthread_mutex_lock(&lock_send);
  15444. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  15445. sprintf((char *)SendBuffer, "%s", str);
  15446. SendBufLen = strlen(str);
  15447. pthread_mutex_unlock(&lock_send);
  15448. lws_callback_on_writable(wsi_client);
  15449. //lws_service(context, 0);
  15450. //sleep(1);
  15451. }
  15452. void LWS_SendNow(char * str)
  15453. {
  15454. //=====================================================
  15455. // Check InternetConn 0: disconnected, 1: connected
  15456. //====================================================
  15457. if(GetOcppConnStatus() == 0)
  15458. {
  15459. DEBUG_INFO("offline now !!!\n");
  15460. return;
  15461. }
  15462. pthread_mutex_lock(&lock_send);
  15463. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  15464. sprintf((char *)SendBuffer, "%s", str);
  15465. SendBufLen = strlen(str);
  15466. pthread_mutex_unlock(&lock_send);
  15467. lws_callback_on_writable(wsi_client);
  15468. lws_service(context, 0);
  15469. //sleep(1);
  15470. }