MessageHandler.c 767 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. //ConfigurationMaxKeys
  12. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  13. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  14. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  15. //=================================
  16. // StatusNotification cycle
  17. //=================================
  18. static int server_cycle_Status = 120;
  19. //===============================
  20. // Configuration: unknownkey
  21. //===============================
  22. static char unknownkey[10][20] = {0};
  23. static int UnknownKeynum = 0;
  24. //===============================
  25. // Gun Total Numbers
  26. //===============================
  27. static int gunTotalNumber = 0;
  28. static uint8_t gunType[4] = {0};
  29. //===============================
  30. // Local List Version
  31. //===============================
  32. static int localversion=0;
  33. static char idTagAuthorization[32] = {0};
  34. //===============================
  35. // OCPP sign variable
  36. //===============================
  37. static int server_sign = FALSE;
  38. int server_pending = FALSE;
  39. static int BootNotificationInterval = 0;
  40. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  41. //===============================
  42. // OCPP auth variable
  43. //===============================
  44. static int authorizeRetryTimes = 0; //number of Retry times
  45. //===============================
  46. // OCPP other variables
  47. //===============================
  48. static int HeartBeatWaitTime = 10;
  49. static int FirstHeartBeat = 0;
  50. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  51. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  52. static char CurrentChargingProfileScheduleStr[30] = {0};
  53. //========================================
  54. // OCPP status/previous related variables
  55. //========================================
  56. static int GunStatusInterval = 10;
  57. static uint8_t statusModeChage[CONNECTOR_QUANTITY] = {FALSE};
  58. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  59. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  60. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  61. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  62. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  63. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  64. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  65. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  66. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  67. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  68. static int TransactionMessageAttemptsValue = 0;
  69. static int TransactionMessageRetryIntervalValue = 0;
  70. static int TempMeterValueInterval = 0;
  71. static struct OCPPAuthLocalElemet
  72. {
  73. int listVersionInt;
  74. char idTagstr[21];
  75. char parentIdTag[21];
  76. char expiryDate[36];
  77. char idTagstatus[16];
  78. }idTagQuery;
  79. //=============================================
  80. // OCPP HeartBeat Response Not Receive Counts
  81. //============================================
  82. static int HeartBeatWithNOResponse = 0;
  83. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  84. extern sqlite3 *db;
  85. int TransactionMessageAttemptsGet(void);
  86. int TransactionMessageRetryIntervalGet(void);
  87. int GetOcppConnStatus(void);
  88. void SetOcppConnStatus(uint8_t status);
  89. int setKeyValue(char *key, char *value);
  90. void OCPP_get_TableAuthlocalAllData(void);
  91. void processUnkownKey(void);
  92. struct StructOCPPMeterValue
  93. {
  94. unsigned char TimeStamp[28];
  95. struct StructSampledValue SampledValue[10];
  96. };
  97. struct ClientTime
  98. {
  99. unsigned int Heartbeat;
  100. unsigned int StatusNotification[CONNECTOR_QUANTITY];
  101. unsigned int StartTransaction;
  102. unsigned int StopTransaction;
  103. unsigned int MeterValues[CONNECTOR_QUANTITY];
  104. }clientTime;
  105. typedef union
  106. {
  107. //Operations Initiated by Central System
  108. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  109. struct
  110. {
  111. //CsMsgValue[0]
  112. unsigned char StatusNotificationReq:1; //bit 0,
  113. unsigned char StatusNotificationConf:1; //bit 1,
  114. unsigned char TriggerMeterValue:1; //bit 2,
  115. unsigned char :5; //bit 5~7
  116. }bits[CONNECTOR_QUANTITY];
  117. }CpinitiateMsg;
  118. CpinitiateMsg cpinitateMsg;
  119. //GetConfiguration Array
  120. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  121. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  122. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  123. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  124. #if 0
  125. static char *ChargePointErrorCodeStr[] = {
  126. MACROSTR(ConnectorLockFailure),
  127. MACROSTR(EVCommunicationError),
  128. MACROSTR(GroundFailure),
  129. MACROSTR(HighTemperature),
  130. MACROSTR(InternalError),
  131. MACROSTR(LocalListConflict),
  132. MACROSTR(NoError),
  133. MACROSTR(OtherError),
  134. MACROSTR(OverCurrentFailure),
  135. MACROSTR(OverVoltage),
  136. MACROSTR(PowerMeterFailure),
  137. MACROSTR(PowerSwitchFailure),
  138. MACROSTR(ReaderFailure),
  139. MACROSTR(ResetFailure),
  140. MACROSTR(UnderVoltage),
  141. MACROSTR(WeakSignal)
  142. };
  143. #endif
  144. static char * ChargePointStatusStr[] = {
  145. MACROSTR(Available),
  146. MACROSTR(Preparing),
  147. MACROSTR(Charging),
  148. MACROSTR(SuspendedEVSE),
  149. MACROSTR(SuspendedEV),
  150. MACROSTR(Finishing),
  151. MACROSTR(Reserved),
  152. MACROSTR(Unavailable),
  153. MACROSTR(Faulted)
  154. };
  155. static char *RegistrationStatusStr[] = {
  156. MACROSTR(Accepted),
  157. MACROSTR(Pending),
  158. MACROSTR(Rejected)
  159. };
  160. static char *AvailabilityTypeStr[] = {
  161. MACROSTR(Inoperative),
  162. MACROSTR(Operative)
  163. };
  164. static char *AvailabilityStatusStr[] = {
  165. MACROSTR(Accepted),
  166. MACROSTR(Rejected),
  167. MACROSTR(Scheduled)
  168. };
  169. static char *ConfigurationStatusStr[] = {
  170. MACROSTR(Accepted),
  171. MACROSTR(Rejected),
  172. MACROSTR(RebootRequired),
  173. MACROSTR(NotSupported)
  174. };
  175. static char *ClearCacheStatusStr[] = {
  176. MACROSTR(Accepted),
  177. MACROSTR(Rejected)
  178. };
  179. static char *ChargingProfilePurposeTypeStr[] = {
  180. MACROSTR(ChargePointMaxProfile),
  181. MACROSTR(TxDefaultProfile),
  182. MACROSTR(TxProfile)
  183. };
  184. static char *ChargingProfileStatusStr[] = {
  185. MACROSTR(Accepted),
  186. MACROSTR(Rejected),
  187. MACROSTR(NotSupported)
  188. };
  189. static char *ClearChargingProfileStatusStr[] = {
  190. MACROSTR(Accepted),
  191. MACROSTR(Unknown)
  192. };
  193. static char *GetCompositeScheduleStatusStr[] = {
  194. MACROSTR(Accepted),
  195. MACROSTR(Rejected)
  196. };
  197. static char *UpdateTypeStr[] = {
  198. MACROSTR(Differential),
  199. MACROSTR(Full)
  200. };
  201. static char *UpdateStatusStr[] = {
  202. MACROSTR(Accepted),
  203. MACROSTR(Failed),
  204. MACROSTR(NotSupported),
  205. MACROSTR(VersionMismatch)
  206. };
  207. static char *RemoteStartStopStatusStr[] = {
  208. MACROSTR(Accepted),
  209. MACROSTR(Rejected)
  210. };
  211. static char *ReservationStatusStr[] = {
  212. MACROSTR(Accepted),
  213. MACROSTR(Faulted),
  214. MACROSTR(Occupied),
  215. MACROSTR(Rejected),
  216. MACROSTR(Unavailable)
  217. };
  218. static char *ResetTypeStr[] = {
  219. MACROSTR(Hard),
  220. MACROSTR(Soft)
  221. };
  222. static char *ResetStatusStr[] = {
  223. MACROSTR(Accepted),
  224. MACROSTR(Rejected)
  225. };
  226. static char * DiagnosticsStatusStr[] = {
  227. MACROSTR(Idle),
  228. MACROSTR(Uploaded),
  229. MACROSTR(UploadFailed),
  230. MACROSTR(Uploading)
  231. };
  232. static char * FirmwareStatusStr[] = {
  233. MACROSTR(Downloaded),
  234. MACROSTR(DownloadFailed),
  235. MACROSTR(Downloading),
  236. MACROSTR(Idle),
  237. MACROSTR(InstallationFailed),
  238. MACROSTR(Installing),
  239. MACROSTR(Installed)
  240. };
  241. static char * MessageTriggerStr[] = {
  242. MACROSTR(BootNotification),
  243. MACROSTR(DiagnosticsStatusNotification),
  244. MACROSTR(FirmwareStatusNotification),
  245. MACROSTR(Heartbeat),
  246. MACROSTR(MeterValues),
  247. MACROSTR(StatusNotification)
  248. };
  249. static char * TriggerMessageStatusStr[] = {
  250. MACROSTR(Accepted),
  251. MACROSTR(Rejected),
  252. MACROSTR(NotImplemented)
  253. };
  254. static char * UnlockStatusStr[] = {
  255. MACROSTR(Unlocked),
  256. MACROSTR(UnlockFailed),
  257. MACROSTR(NotSupported)
  258. };
  259. #if 0
  260. static char * StopTransactionReasonStr[] = {
  261. MACROSTR(EmergencyStop),
  262. MACROSTR(EVDisconnected),
  263. MACROSTR(HardReset),
  264. MACROSTR(Local),
  265. MACROSTR(Other),
  266. MACROSTR(PowerLoss),
  267. MACROSTR(Reboot),
  268. MACROSTR(Remote),
  269. MACROSTR(SoftReset),
  270. MACROSTR(UnlockCommand),
  271. MACROSTR(DeAuthorized)
  272. };
  273. #endif
  274. static char * CancelReservationStatusStr[] = {
  275. MACROSTR(Accepted),
  276. MACROSTR(Rejected)
  277. };
  278. static char * ReadingContextStr[] = {
  279. MACROSTR(Interruption.Begin),
  280. MACROSTR(Interruption.End),
  281. MACROSTR(Other),
  282. MACROSTR(Sample.Clock),
  283. MACROSTR(Sample.Periodic),
  284. MACROSTR(Transaction.Begin),
  285. MACROSTR(Transaction.End),
  286. MACROSTR(Trigger)
  287. };
  288. static char * ValueFormatStr[] = {
  289. MACROSTR(Raw),
  290. MACROSTR(SignedData)
  291. };
  292. static char * MeasurandStr[] = {
  293. MACROSTR(Current.Export),
  294. MACROSTR(Current.Import),
  295. MACROSTR(Current.Offered),
  296. MACROSTR(Energy.Active.Export.Register),
  297. MACROSTR(Energy.Active.Import.Register),
  298. MACROSTR(Energy.Reactive.Export.Register),
  299. MACROSTR(Energy.Reactive.Import.Register),
  300. MACROSTR(Energy.Active.Export.Interval),
  301. MACROSTR(Energy.Active.Import.Interval),
  302. MACROSTR(Energy.Reactive.Export.Interval),
  303. MACROSTR(Energy.Reactive.Import.Interval),
  304. MACROSTR(Frequency),
  305. MACROSTR(Power.Active.Export),
  306. MACROSTR(Power.Active.Import),
  307. MACROSTR(Power.Factor),
  308. MACROSTR(Power.Offered),
  309. MACROSTR(Power.Reactive.ExportMACROSTR),
  310. MACROSTR(Power.Reactive.Import),
  311. MACROSTR(RPM),
  312. MACROSTR(SoC),
  313. MACROSTR(Temperature),
  314. MACROSTR(Voltage)
  315. };
  316. static char * LocationStr[] = {
  317. MACROSTR(Body),
  318. MACROSTR(Cable),
  319. MACROSTR(EV),
  320. MACROSTR(Inlet),
  321. MACROSTR(Outlet)
  322. };
  323. static char * PhaseStr[] = {
  324. MACROSTR(L1),
  325. MACROSTR(L2),
  326. MACROSTR(L3),
  327. MACROSTR(N),
  328. MACROSTR(L1-N),
  329. MACROSTR(L2-N),
  330. MACROSTR(L3-N),
  331. MACROSTR(L1-L2),
  332. MACROSTR(L2-L3),
  333. MACROSTR(L3-L1)
  334. };
  335. static char * UnitOfMeasureStr[] = {
  336. MACROSTR(Wh),
  337. MACROSTR(kWh),
  338. MACROSTR(varh),
  339. MACROSTR(kvarh),
  340. MACROSTR(W),
  341. MACROSTR(kW),
  342. MACROSTR(VA),
  343. MACROSTR(kVA),
  344. MACROSTR(var),
  345. MACROSTR(kvar),
  346. MACROSTR(A),
  347. MACROSTR(V),
  348. MACROSTR(Celsius),
  349. MACROSTR(Fahrenheit),
  350. MACROSTR(K),
  351. MACROSTR(Percent)
  352. };
  353. //=========================================
  354. // Sqlite3 related function
  355. //=========================================
  356. static int selectSqlCount = 0;
  357. static int callback(void *data, int argc, char **argv, char **azColName){
  358. int i;
  359. //printf("%s: ", (const char*)data);
  360. selectSqlCount = argc;
  361. for(i = 0; i<argc; i++){
  362. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  363. }
  364. //printf("\n");
  365. return 0;
  366. }
  367. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  368. //int i;
  369. //printf("%s:\n", (const char*)data);
  370. localversion = argv[5] ? atoi(argv[5]) : 0;
  371. //printf("localversion=%d\n", localversion);
  372. return 0;
  373. }
  374. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  375. //printf("%s:\n", (const char*)data);
  376. //idTag
  377. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  378. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  379. //parentIdTag
  380. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  381. //expir_date
  382. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  383. //status
  384. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  385. //version
  386. if(columenCount > 5)
  387. idTagQuery.listVersionInt = atoi(columnValue[5]);
  388. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  389. return 0;
  390. }
  391. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  392. {
  393. // localversion = argv[5] ? atoi(argv[5]) : 0;
  394. // printf("localversion=%d\n", localversion);
  395. return 0;
  396. }
  397. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  398. {
  399. for (int i = 0; i < n_columns; i++)
  400. {
  401. DEBUG_INFO("%s\t", col_values[i]);
  402. }
  403. DEBUG_INFO("\n");
  404. return 0;
  405. }
  406. int OCPP_cleanLocalCache()
  407. {
  408. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  409. char *errMsg = 0;
  410. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  411. if (SQLITE_OK != rc)
  412. {
  413. DEBUG_INFO("SQL error: %s\n",errMsg);
  414. return FALSE;
  415. }
  416. return TRUE;
  417. }
  418. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  419. {
  420. int isSuccess = TRUE;
  421. int ret = 0;
  422. //const char* data = "Callback function called";
  423. char sql[300];
  424. char zErrMsg[200];
  425. memset(sql, 0, 300);
  426. memset(zErrMsg, 0, 200);
  427. sprintf(sql, "insert or replace into ocpp_auth_cache (idtag, parent_idtag, expir_date, status) " "VALUES ('%s', '%s', '%s', '%s'); ""SELECT * from ocpp_auth_cache", idTag, parentTage, expiryDate, status);
  428. //* Execute SQL statement */
  429. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  430. if( ret != SQLITE_OK )
  431. {
  432. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  433. isSuccess = FALSE;
  434. }
  435. return isSuccess;
  436. }
  437. void OCPP_getIdTagFromLocalCache(char idTag[])
  438. {
  439. int rc = 0;
  440. char sql[100];
  441. char zErrMsg[100];
  442. memset(sql, 0, 100);
  443. memset(zErrMsg, 0, 100);
  444. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  445. memset(&idTagQuery, 0, sizeof(idTagQuery));
  446. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  447. /* Execute SQL statement */
  448. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  449. if( rc != SQLITE_OK )
  450. {
  451. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  452. }
  453. }
  454. void OCPP_getListVerion()
  455. {
  456. int rc = 0;
  457. // const char* data = "Callback function called";
  458. char sql[100];
  459. char zErrMsg[100];
  460. memset(sql, 0, 100);
  461. memset(zErrMsg, 0, 100);
  462. strcpy(sql, "select * from ocpp_auth_local order by idx");
  463. /* Execute SQL statement */
  464. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  465. if( rc != SQLITE_OK )
  466. {
  467. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  468. }
  469. }
  470. void OCPP_get_TableAuthlocalAllData(void)
  471. {
  472. int rc = 0;
  473. char sql[100];
  474. char zErrMsg[100];
  475. memset(sql, 0, 100);
  476. memset(zErrMsg, 0, 100);
  477. sprintf(sql,"select * from ocpp_auth_local ");
  478. /* Execute SQL statement */
  479. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  480. if( rc != SQLITE_OK )
  481. {
  482. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  483. }
  484. //return ver;
  485. }
  486. int OCPP_cleanLocalList()
  487. {
  488. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  489. char *errMsg = 0;
  490. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  491. if (SQLITE_OK != rc)
  492. {
  493. DEBUG_INFO("%s\n",errMsg);
  494. return FALSE;
  495. }
  496. return TRUE;
  497. }
  498. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  499. {
  500. int isSuccess = FALSE;
  501. int ret = 0;
  502. //const char* data = "Callback function called";
  503. char sql[300];
  504. char zErrMsg[200];
  505. memset(sql, 0, 300);
  506. memset(zErrMsg, 0, 200);
  507. sprintf(sql,"insert or replace into ocpp_auth_local (idtag, parent_idtag, expir_date, status, version) " "VALUES ('%s', '%s', '%s', '%s', %d ); ""SELECT * from ocpp_auth_local", idTag, parentTage, expiryDate, status, version);
  508. //* Execute SQL statement */
  509. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  510. if( ret != SQLITE_OK )
  511. {
  512. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  513. return isSuccess;
  514. }
  515. memset(sql, 0, 300);
  516. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  517. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  518. if( ret != SQLITE_OK )
  519. {
  520. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  521. return isSuccess;
  522. }
  523. isSuccess = TRUE;
  524. return isSuccess;
  525. }
  526. void OCPP_getIdTagFromLocalList(char idTag[])
  527. {
  528. int rc = 0;
  529. // const char* data = "Callback function called";
  530. char sql[100];
  531. char zErrMsg[100];
  532. memset(sql, 0, 100);
  533. memset(zErrMsg, 0, 100);
  534. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  535. memset(&idTagQuery, 0, sizeof(idTagQuery));
  536. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  537. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  538. /* Execute SQL statement */
  539. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  540. if( rc != SQLITE_OK )
  541. {
  542. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  543. }
  544. //return ver;
  545. }
  546. void OCPP_deleteIdTagFromLocalList(char idTag[])
  547. {
  548. //int ver = 0;
  549. //int isSuccess = FALSE;
  550. int rc = 0;
  551. char sql[100];
  552. char zErrMsg[100];
  553. memset(sql, 0, 100);
  554. memset(zErrMsg, 0, 100);
  555. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  556. //* Execute SQL statement */
  557. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  558. if( rc != SQLITE_OK )
  559. {
  560. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  561. }
  562. }
  563. int getCurrentYear()
  564. {
  565. int result = 0;
  566. time_t CurrentTime;
  567. struct tm *tm;
  568. CurrentTime = time(NULL);
  569. tm=localtime(&CurrentTime);
  570. result = (tm->tm_year + 1900);
  571. return result;
  572. }
  573. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  574. {
  575. int result = PASS;
  576. char* errMsg = NULL;
  577. char sqlStr[8192];
  578. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  579. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  580. {
  581. result = FAIL;
  582. DEBUG_INFO( "Insert local transaction record error message: %s\n", errMsg);
  583. }
  584. sprintf(sqlStr, "delete from ocpp_transaction_record where (idx < (select idx from ocpp_transaction_record order by idx desc limit 1)-2000) and (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  585. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  586. {
  587. result = FAIL;
  588. DEBUG_INFO( "delete local transaction record error message: %s\n", errMsg);
  589. }
  590. return result;
  591. }
  592. //==========================================
  593. // Check time passed since today
  594. //==========================================
  595. long long DiffTimebWithNow(struct timeb ST)
  596. {
  597. //return milli-second
  598. struct timeb ET;
  599. long long StartTime,StopTime;
  600. ftime(&ET);
  601. StartTime=(long long)ST.time;
  602. StopTime=(long long)ET.time;
  603. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  604. }
  605. int getTimePassSinceToday()
  606. {
  607. int result = -1;
  608. static time_t lastTime;
  609. time_t t;
  610. struct tm *tmStartToday;
  611. struct timeb tbStartToday;
  612. t=time(NULL);
  613. if(difftime(t, lastTime)>0)
  614. {
  615. tmStartToday=localtime(&t);
  616. tmStartToday->tm_hour = 0;
  617. tmStartToday->tm_min = 0;
  618. tmStartToday->tm_sec = 0;
  619. tbStartToday.time = mktime(tmStartToday);
  620. tbStartToday.millitm = 0;
  621. result = DiffTimebWithNow(tbStartToday)/1000;
  622. lastTime = t;
  623. }
  624. return result;
  625. }
  626. void getNowDatetime(uint8_t *data)
  627. {
  628. time_t t = time(NULL);
  629. struct tm tm = *localtime(&t);
  630. sprintf((char*)data, "%04d-%02d-%02dT%02d:%02d:%02dZ", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
  631. }
  632. int syncDateTimeRTC(uint8_t *data)
  633. {
  634. struct ParsingResult
  635. {
  636. int result;
  637. int scanedElement;
  638. int year;
  639. int month;
  640. int mday;
  641. int hour;
  642. int min;
  643. int sec;
  644. int tz_hour;
  645. int tz_min;
  646. float minSec;
  647. }result;
  648. struct tm tmOrg;
  649. struct tm *tmTarget;
  650. struct timeb tbTarget;
  651. char buf[128];
  652. memset(&result, 0x00, sizeof(struct ParsingResult));
  653. result.result = PASS;
  654. if(strstr((char*)data, ".") != NULL)
  655. {
  656. // Original data with mini second
  657. if(strstr((char*)data, "Z") != NULL)
  658. {
  659. // Original data with Z
  660. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  661. &result.year,
  662. &result.month,
  663. &result.mday,
  664. &result.hour,
  665. &result.min,
  666. &result.sec,
  667. &result.minSec);
  668. }
  669. else
  670. {
  671. // Original data without Z
  672. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  673. &result.year,
  674. &result.month,
  675. &result.mday,
  676. &result.hour,
  677. &result.min,
  678. &result.sec,
  679. &result.minSec,
  680. &result.tz_hour,
  681. &result.tz_min);
  682. }
  683. }
  684. else
  685. {
  686. // Original data without mini second
  687. if(strstr((char*)data, "Z") != NULL)
  688. {
  689. // Original data with Z
  690. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  691. &result.year,
  692. &result.month,
  693. &result.mday,
  694. &result.hour,
  695. &result.min,
  696. &result.sec);
  697. }
  698. else
  699. {
  700. // Original data without Z
  701. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  702. &result.year,
  703. &result.month,
  704. &result.mday,
  705. &result.hour,
  706. &result.min,
  707. &result.sec,
  708. &result.tz_hour,
  709. &result.tz_min);
  710. }
  711. }
  712. tmOrg.tm_year = result.year - 1900;
  713. tmOrg.tm_mon = result.month - 1;
  714. tmOrg.tm_mday = result.mday;
  715. tmOrg.tm_hour = result.hour;
  716. tmOrg.tm_min = result.min;
  717. tmOrg.tm_sec = result.sec;
  718. tmOrg.tm_gmtoff = 0;
  719. tbTarget.time = mktime(&tmOrg);
  720. tbTarget.timezone = 0;
  721. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  722. tmTarget = gmtime(&tbTarget.time);
  723. sprintf(buf, "date -s '%04d-%02d-%02d %02d:%02d:%02d'", (tmTarget->tm_year+1900), (tmTarget->tm_mon+1), tmTarget->tm_mday, tmTarget->tm_hour, tmTarget->tm_min, tmTarget->tm_sec);
  724. //DEBUG_INFO(" org date time: %s\n", data);
  725. //DEBUG_INFO("parse date time: %s\n", buf);
  726. system(buf);
  727. system("/sbin/hwclock -w --systohc");
  728. if(result.scanedElement < 6)
  729. result.result = FAIL;
  730. return result.result;
  731. }
  732. //==========================================
  733. // GetCompositeSchedule logic related function
  734. //==========================================
  735. int DiffTimebSec(struct timeb ST, struct timeb ET)
  736. {
  737. //return milli-second
  738. unsigned int StartTime,StopTime;
  739. StartTime=(unsigned int)ST.time;
  740. StopTime=(unsigned int)ET.time;
  741. return (StopTime-StartTime);
  742. }
  743. int DiffTimebWithNowSec(struct timeb ST)
  744. {
  745. //return milli-second
  746. struct timeb ET;
  747. unsigned int StartTime,StopTime;
  748. ftime(&ET);
  749. StartTime=(unsigned int)ST.time;
  750. StopTime=(unsigned int)ET.time;
  751. return (StopTime-StartTime);
  752. }
  753. int getStartStop(uint8_t *start, uint8_t *stop)
  754. {
  755. int result = -1;
  756. struct tm tmStart;
  757. struct timeb tbStart;
  758. struct tm tmStop;
  759. struct timeb tbStop;
  760. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  761. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  762. {
  763. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  764. //DEBUG_INFO("Stop: %d-%d-%d %d:%d:%d\n", tmStop.tm_year, tmStop.tm_mon, tmStop.tm_mday, tmStop.tm_hour, tmStop.tm_min, tmStop.tm_sec);
  765. tmStart.tm_year -= 1900;
  766. tmStart.tm_mon -= 1;
  767. tbStart.time = mktime(&tmStart);
  768. tbStart.millitm = 0;
  769. tmStop.tm_year -= 1900;
  770. tmStop.tm_mon -= 1;
  771. tbStop.time = mktime(&tmStop);
  772. tbStop.millitm = 0;
  773. result = DiffTimebSec(tbStart, tbStop);
  774. //DEBUG_INFO("getStartStop(): %d\n", result);
  775. }
  776. else
  777. {
  778. DEBUG_WARN("Start or stop date parsing error.\r\n");
  779. }
  780. return result;
  781. }
  782. int isOvertNow(uint8_t *start)
  783. {
  784. int result = NO;
  785. struct tm tmStart;
  786. struct timeb tbStart;
  787. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6))
  788. {
  789. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  790. tmStart.tm_year -= 1900;
  791. tmStart.tm_mon -= 1;
  792. tbStart.time = mktime(&tmStart);
  793. tbStart.millitm = 0;
  794. if(DiffTimebWithNowSec(tbStart) <= 0)
  795. result = NO;
  796. else
  797. result = YES;
  798. }
  799. else
  800. {
  801. DEBUG_WARN("Start date parsing error.\n");
  802. }
  803. return result;
  804. }
  805. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  806. {
  807. int result = -1;
  808. struct tm tmStart;
  809. struct timeb tbStart;
  810. struct tm tmStop;
  811. struct timeb tbStop;
  812. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  813. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  814. {
  815. tmStart.tm_year -= 1900;
  816. tmStart.tm_mon -= 1;
  817. tbStart.time = mktime(&tmStart);
  818. tbStart.millitm = 0;
  819. tmStop.tm_year -= 1900;
  820. tmStop.tm_mon -= 1;
  821. tbStop.time = mktime(&tmStop);
  822. tbStop.millitm = 0;
  823. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  824. }
  825. return result;
  826. }
  827. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  828. {
  829. FILE *fp;
  830. char profileFileName[128];
  831. char *line = NULL;
  832. size_t len = 0;
  833. time_t CurrentTime;
  834. struct tm *tmComposite;
  835. struct StructChargingProfile maxProfile;
  836. struct StructChargingProfile defaultTxProfile;
  837. struct StructChargingProfile txProfile;
  838. struct StructChargingSchedulePeriod tmpPeriod;
  839. uint8_t limitMax=0;
  840. uint8_t limitDef=0;
  841. uint8_t limitTx=0;
  842. int compositePeriodIdx = 0;
  843. CurrentTime = time(NULL);
  844. tmComposite=localtime(&CurrentTime);
  845. sprintf((char*)compositeProfile->ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec);
  846. if(isUnitA)
  847. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  848. else
  849. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  850. compositeProfile->ChargingSchedule.Duration = durationReq;
  851. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  852. {
  853. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  854. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  855. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  856. }
  857. compositeProfile->ChargingProfileId = 0;
  858. compositeProfile->StackLevel = 99 ;
  859. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  860. maxProfile.ChargingProfileId = -1;
  861. defaultTxProfile.ChargingProfileId = -1;
  862. txProfile.ChargingProfileId = -1;
  863. maxProfile.ChargingSchedule.Duration = -1;
  864. defaultTxProfile.ChargingSchedule.Duration = -1;
  865. txProfile.ChargingSchedule.Duration = -1;
  866. system("rm -f /tmp/*.json");
  867. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  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. // Delete duplicate period
  2187. if(compositePeriodIdx > 1)
  2188. {
  2189. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2190. {
  2191. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2192. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2193. compositePeriodIdx -= 1;
  2194. }
  2195. }
  2196. }
  2197. else
  2198. break;
  2199. }
  2200. }
  2201. else
  2202. {
  2203. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2204. {
  2205. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2206. compositePeriodIdx++;
  2207. }
  2208. else
  2209. {
  2210. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2211. }
  2212. }
  2213. }
  2214. }
  2215. }
  2216. }
  2217. }
  2218. }
  2219. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  2220. else if(defaultTxProfile.ChargingProfileId != -1)
  2221. {
  2222. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2223. {
  2224. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  2225. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2226. (defaultTxProfile.ChargingSchedule.Duration > 0))
  2227. {
  2228. if(maxProfile.ChargingProfileId != -1)
  2229. {
  2230. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2231. {
  2232. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2233. {
  2234. if((maxProfile.ChargingSchedule.Duration > 0))
  2235. {
  2236. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2237. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2238. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  2239. }
  2240. else
  2241. {
  2242. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2243. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2244. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2245. }
  2246. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2247. {
  2248. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2249. {
  2250. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2251. compositePeriodIdx++;
  2252. }
  2253. else
  2254. {
  2255. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2256. }
  2257. }
  2258. // Delete duplicate period
  2259. if(compositePeriodIdx > 1)
  2260. {
  2261. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2262. {
  2263. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2264. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2265. compositePeriodIdx -= 1;
  2266. }
  2267. }
  2268. }
  2269. else
  2270. break;
  2271. }
  2272. }
  2273. else
  2274. {
  2275. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2276. {
  2277. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2278. compositePeriodIdx++;
  2279. }
  2280. else
  2281. {
  2282. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2283. }
  2284. }
  2285. }
  2286. }
  2287. }
  2288. // Fill other period by MaxProfile
  2289. if(maxProfile.ChargingProfileId != -1)
  2290. {
  2291. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2292. {
  2293. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2294. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2295. (maxProfile.ChargingSchedule.Duration > 0))
  2296. {
  2297. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  2298. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2299. {
  2300. tmpPeriod.StartPeriod = (compositePeriodIdx==0)?0:compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  2301. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  2302. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2303. }
  2304. if((compositePeriodIdx > 0 ) && (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2305. {
  2306. tmpPeriod.StartPeriod = (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod>compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod:compositeProfile->ChargingSchedule.Duration;
  2307. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  2308. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2309. }
  2310. if(tmpPeriod.Limit != -1)
  2311. {
  2312. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2313. {
  2314. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2315. {
  2316. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2317. compositePeriodIdx++;
  2318. }
  2319. else
  2320. {
  2321. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2322. }
  2323. }
  2324. // Delete duplicate period
  2325. if(compositePeriodIdx > 1)
  2326. {
  2327. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2328. {
  2329. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2330. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2331. compositePeriodIdx -= 1;
  2332. }
  2333. }
  2334. }
  2335. }
  2336. }
  2337. }
  2338. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  2339. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2340. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  2341. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  2342. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2343. {
  2344. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2345. {
  2346. compositeProfile->ChargingProfileId = 1;
  2347. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2348. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2349. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2350. }
  2351. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2352. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2353. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2354. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2355. }
  2356. if(line)
  2357. free(line);
  2358. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  2359. }
  2360. //==========================================
  2361. // Init all share memory
  2362. //==========================================
  2363. int InitShareMemory()
  2364. {
  2365. int result = PASS;
  2366. int MeterSMId;
  2367. //creat ShmSysConfigAndInfo
  2368. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  2369. {
  2370. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  2371. result = FAIL;
  2372. }
  2373. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2374. {
  2375. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  2376. result = FAIL;
  2377. }
  2378. else
  2379. {}
  2380. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  2381. {
  2382. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  2383. result = FAIL;
  2384. }
  2385. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2386. {
  2387. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  2388. result = FAIL;
  2389. }
  2390. else
  2391. {}
  2392. //creat ShmPsuData
  2393. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  2394. {
  2395. DEBUG_ERROR("shmget ShmPsuData NG\n");
  2396. result = FAIL;
  2397. }
  2398. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2399. {
  2400. DEBUG_ERROR("shmat ShmPsuData NG\n");
  2401. result = FAIL;
  2402. }
  2403. else
  2404. {}
  2405. //creat ShmOCPP16Data
  2406. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  2407. {
  2408. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  2409. result = FAIL;
  2410. }
  2411. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2412. {
  2413. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  2414. result = FAIL;
  2415. }
  2416. else
  2417. {}
  2418. /****************************** For Initial Settings************************************************/
  2419. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  2420. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  2421. // allocate Configuration memory address
  2422. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  2423. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  2424. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  2425. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  2426. //offline MeterValue Interval
  2427. TempMeterValueInterval = 0;
  2428. return result;
  2429. }
  2430. int ProcessShareMemory()
  2431. {
  2432. if(InitShareMemory() == FAIL)
  2433. {
  2434. DEBUG_ERROR("InitShareMemory NG\n");
  2435. if(ShmStatusCodeData!=NULL)
  2436. {
  2437. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  2438. }
  2439. sleep(5);
  2440. return FAIL;
  2441. }
  2442. return PASS;
  2443. }
  2444. void CheckSystemValue(void)
  2445. {
  2446. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  2447. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  2448. char filenmae[100]={0};
  2449. char str[100]={0};
  2450. int tempIndex = 0;
  2451. //===============================
  2452. // send Heartbeat
  2453. //===============================
  2454. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2455. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  2456. {
  2457. clientTime.Heartbeat=time((time_t*)NULL);
  2458. if(server_sign == TRUE)
  2459. {
  2460. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2461. }
  2462. else
  2463. {
  2464. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  2465. }
  2466. }
  2467. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  2468. {
  2469. //parameter for test
  2470. sendHeartbeatRequest(0);
  2471. //==============================================
  2472. // Reset Waiting Time
  2473. //==============================================
  2474. HeartBeatWithNOResponse += 1;
  2475. }
  2476. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  2477. {
  2478. //==========================================
  2479. // csu trigger DataTransferReq
  2480. //==========================================
  2481. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  2482. {
  2483. sendDataTransferRequest(gun_index);
  2484. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  2485. }
  2486. //===============================
  2487. // CSU Trigger Authorize Request
  2488. //===============================
  2489. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  2490. {
  2491. sendAuthorizeRequest(0);
  2492. authorizeRetryTimes = authorizeRetryTimes + 1;
  2493. if(authorizeRetryTimes < 3)
  2494. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2495. }
  2496. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  2497. {
  2498. authorizeRetryTimes = 0;
  2499. SetOcppConnStatus(FALSE);
  2500. server_sign = FALSE;
  2501. }
  2502. 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))
  2503. {
  2504. sendAuthorizeRequest(0);
  2505. }
  2506. //==============================================
  2507. // CSU Trigger Smart Charging Profilw
  2508. //==============================================
  2509. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  2510. {
  2511. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  2512. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  2513. }
  2514. //==============================================
  2515. // Charger start transaction
  2516. //==============================================
  2517. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2518. {
  2519. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  2520. sendStartTransactionRequest(gun_index);
  2521. clientTime.StartTransaction = time((time_t*)NULL);
  2522. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2523. storeTempStopTransaction(gun_index);
  2524. }
  2525. //==============================================
  2526. // Charger stop transaction
  2527. //==============================================
  2528. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2529. {
  2530. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2531. sendStopTransactionRequest(gun_index);
  2532. clientTime.StopTransaction = time((time_t*)NULL);
  2533. }
  2534. //==============================================
  2535. // Charger status report
  2536. //==============================================
  2537. //--- Check Mode Change ---//
  2538. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2539. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2540. {
  2541. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2542. {
  2543. tempIndex = ((gun_index==2) ? 1: 0);
  2544. }
  2545. else
  2546. {
  2547. tempIndex = gun_index;
  2548. }
  2549. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2550. {
  2551. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2552. {
  2553. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  2554. {
  2555. // Sent unplug message for California pricing logic
  2556. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  2557. {
  2558. uint8_t ts[20];
  2559. getNowDatetime(ts);
  2560. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2561. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2562. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2563. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2564. }
  2565. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2566. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2567. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2568. statusModeChage[gun_index] = TRUE;
  2569. }
  2570. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2571. {
  2572. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2573. if((access(filenmae,F_OK))!=-1)
  2574. {
  2575. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2576. sprintf(str,"rm -f %s",filenmae);
  2577. system(str);
  2578. }
  2579. }
  2580. #if 1 // for TempStopTransaction
  2581. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2582. {
  2583. checkTempStopTransaction(gun_index);
  2584. }
  2585. #endif
  2586. }
  2587. }
  2588. }
  2589. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2590. {
  2591. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2592. {
  2593. tempIndex = ((gun_index==2) ? 1: 0);
  2594. }
  2595. else
  2596. {
  2597. tempIndex = gun_index;
  2598. }
  2599. for (int index = 0; index < CCS_QUANTITY; index++)
  2600. {
  2601. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2602. {
  2603. 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]*/ )
  2604. {
  2605. // Sent unplug message for California pricing logic
  2606. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  2607. {
  2608. uint8_t ts[20];
  2609. getNowDatetime(ts);
  2610. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2611. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2612. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2613. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2614. }
  2615. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2616. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2617. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2618. statusModeChage[gun_index] = TRUE;
  2619. }
  2620. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2621. {
  2622. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2623. if((access(filenmae,F_OK))!=-1)
  2624. {
  2625. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2626. sprintf(str,"rm -f %s",filenmae);
  2627. system(str);
  2628. }
  2629. }
  2630. #if 1 // for TempStopTransaction
  2631. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2632. {
  2633. checkTempStopTransaction(gun_index);
  2634. }
  2635. #endif
  2636. }
  2637. }
  2638. }
  2639. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2640. {
  2641. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2642. {
  2643. tempIndex = ((gun_index==2) ? 1: 0);
  2644. }
  2645. else
  2646. {
  2647. tempIndex = gun_index;
  2648. }
  2649. for (int index = 0; index < GB_QUANTITY; index++)
  2650. {
  2651. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2652. {
  2653. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  2654. {
  2655. // Sent unplug message for California pricing logic
  2656. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  2657. {
  2658. uint8_t ts[20];
  2659. getNowDatetime(ts);
  2660. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2661. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2662. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2663. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2664. }
  2665. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2666. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2667. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2668. statusModeChage[gun_index] = TRUE;
  2669. }
  2670. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2671. {
  2672. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2673. if((access(filenmae,F_OK))!=-1)
  2674. {
  2675. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2676. sprintf(str,"rm -f %s",filenmae);
  2677. system(str);
  2678. }
  2679. }
  2680. #if 1 // for TempStopTransaction
  2681. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2682. {
  2683. checkTempStopTransaction(gun_index);
  2684. }
  2685. #endif
  2686. }
  2687. }
  2688. }
  2689. else if(gunType[gun_index] == GUN_TYPE_DO)
  2690. {
  2691. tempIndex = gun_index;
  2692. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2693. {
  2694. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2695. {
  2696. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  2697. {
  2698. // Sent unplug message for California pricing logic
  2699. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  2700. {
  2701. uint8_t ts[20];
  2702. getNowDatetime(ts);
  2703. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2704. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2705. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2706. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2707. }
  2708. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  2709. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  2710. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2711. statusModeChage[gun_index] = TRUE;
  2712. }
  2713. 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
  2714. {
  2715. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2716. if((access(filenmae,F_OK))!=-1)
  2717. {
  2718. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2719. sprintf(str,"rm -f %s",filenmae);
  2720. system(str);
  2721. }
  2722. }
  2723. #if 1 // for TempStopTransaction
  2724. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2725. {
  2726. checkTempStopTransaction(gun_index);
  2727. }
  2728. #endif
  2729. }
  2730. }
  2731. }
  2732. else
  2733. {
  2734. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2735. {
  2736. tempIndex = 2;
  2737. }
  2738. else
  2739. {
  2740. tempIndex = gun_index;
  2741. }
  2742. for (int index = 0; index < AC_QUANTITY; index++)
  2743. {
  2744. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2745. {
  2746. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  2747. {
  2748. // Sent unplug message for California pricing logic
  2749. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)
  2750. {
  2751. uint8_t ts[20];
  2752. getNowDatetime(ts);
  2753. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2754. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2755. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2756. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2757. }
  2758. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2759. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2760. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2761. statusModeChage[gun_index] = TRUE;
  2762. }
  2763. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2764. {
  2765. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2766. if((access(filenmae,F_OK))!=-1)
  2767. {
  2768. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2769. sprintf(str,"rm -f %s",filenmae);
  2770. system(str);
  2771. }
  2772. }
  2773. #if 1 // for TempStopTransaction
  2774. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2775. {
  2776. checkTempStopTransaction(gun_index);
  2777. }
  2778. #endif
  2779. }
  2780. }// END
  2781. }
  2782. if(isWebsocketSendable && (server_sign == TRUE) &&
  2783. (
  2784. (statusModeChage[gun_index] == TRUE) ||
  2785. //((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index))) ||
  2786. ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 5))
  2787. )
  2788. )
  2789. {
  2790. if(SystemInitial > 0)
  2791. SystemInitial -= 1;
  2792. sendStatusNotificationRequest(gun_index);
  2793. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2794. statusModeChage[gun_index] = FALSE;
  2795. }
  2796. //==============================================
  2797. // Meter report
  2798. //==============================================
  2799. // Trigger MeterValue
  2800. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  2801. {
  2802. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  2803. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  2804. }
  2805. // ClockAlign MeterValue
  2806. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  2807. {
  2808. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2809. {
  2810. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2811. {
  2812. tempIndex = ((gun_index==2) ? 1: 0);
  2813. }
  2814. else
  2815. {
  2816. tempIndex = gun_index;
  2817. }
  2818. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2819. {
  2820. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2821. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2822. {
  2823. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2824. {
  2825. reqClockAlignMeter[gun_index] = 1;
  2826. }
  2827. }
  2828. }// End for CHAdeMO
  2829. }
  2830. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2831. {
  2832. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2833. {
  2834. tempIndex = ((gun_index==2) ? 1: 0);
  2835. }
  2836. else
  2837. {
  2838. tempIndex = gun_index;
  2839. }
  2840. for (int index = 0; index < CCS_QUANTITY; index++)
  2841. {
  2842. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2843. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2844. {
  2845. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2846. {
  2847. reqClockAlignMeter[gun_index] = 1;
  2848. }
  2849. }
  2850. } // End for CCS
  2851. }
  2852. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2853. {
  2854. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2855. {
  2856. tempIndex = ((gun_index==2) ? 1: 0);
  2857. }
  2858. else
  2859. {
  2860. tempIndex = gun_index;
  2861. }
  2862. for (int index = 0; index < GB_QUANTITY; index++)
  2863. {
  2864. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2865. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2866. {
  2867. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2868. {
  2869. reqClockAlignMeter[gun_index] = 1;
  2870. }
  2871. }
  2872. }// End for GB
  2873. }
  2874. else if(gunType[gun_index] == GUN_TYPE_DO)
  2875. {
  2876. tempIndex = gun_index;
  2877. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2878. {
  2879. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2880. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2881. {
  2882. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_CHARGING)
  2883. {
  2884. reqClockAlignMeter[gun_index] = 1;
  2885. }
  2886. }
  2887. }
  2888. }
  2889. else
  2890. {
  2891. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2892. {
  2893. tempIndex = 2;
  2894. }
  2895. else
  2896. {
  2897. tempIndex = gun_index;
  2898. }
  2899. for (int index = 0; index < AC_QUANTITY; index++)
  2900. {
  2901. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2902. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2903. {
  2904. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2905. {
  2906. reqClockAlignMeter[gun_index] = 1;
  2907. }
  2908. }
  2909. }//End for AC
  2910. }
  2911. if(reqClockAlignMeter[gun_index] == 1)
  2912. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  2913. }
  2914. // Sample period MeterValue
  2915. if((((time((time_t*)NULL) - clientTime.MeterValues[gun_index]) > (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1))))
  2916. {
  2917. //check Transaction active
  2918. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2919. {
  2920. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2921. {
  2922. tempIndex = ((gun_index==2) ? 1: 0);
  2923. }
  2924. else
  2925. {
  2926. tempIndex = gun_index;
  2927. }
  2928. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2929. {
  2930. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2931. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2932. {
  2933. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2934. {
  2935. reqSampleMeter[gun_index] = 1;
  2936. }
  2937. }
  2938. }// End for CHAdeMO
  2939. }
  2940. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2941. {
  2942. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2943. {
  2944. tempIndex = ((gun_index==2) ? 1: 0);
  2945. }
  2946. else
  2947. {
  2948. tempIndex = gun_index;
  2949. }
  2950. for (int index = 0; index < CCS_QUANTITY; index++)
  2951. {
  2952. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2953. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2954. {
  2955. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2956. {
  2957. reqSampleMeter[gun_index] = 1;
  2958. }
  2959. }
  2960. } // End for CCS
  2961. }
  2962. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2963. {
  2964. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2965. {
  2966. tempIndex = ((gun_index==2) ? 1: 0);
  2967. }
  2968. else
  2969. {
  2970. tempIndex = gun_index;
  2971. }
  2972. for (int index = 0; index < GB_QUANTITY; index++)
  2973. {
  2974. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2975. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2976. {
  2977. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2978. {
  2979. reqSampleMeter[gun_index] = 1;
  2980. }
  2981. }
  2982. }// End for GB
  2983. }
  2984. else if(gunType[gun_index] == GUN_TYPE_DO)
  2985. {
  2986. tempIndex = gun_index;
  2987. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2988. {
  2989. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2990. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2991. {
  2992. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  2993. {
  2994. reqSampleMeter[gun_index] = 1;
  2995. }
  2996. }
  2997. }
  2998. }
  2999. else
  3000. {
  3001. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3002. {
  3003. tempIndex = 2;
  3004. }
  3005. else
  3006. {
  3007. tempIndex = gun_index;
  3008. }
  3009. for (int index = 0; index < AC_QUANTITY; index++)
  3010. {
  3011. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3012. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3013. {
  3014. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  3015. {
  3016. reqSampleMeter[gun_index] = 1;
  3017. }
  3018. }
  3019. }//End for AC
  3020. }
  3021. if(reqSampleMeter[gun_index] == 1)
  3022. {
  3023. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  3024. storeTempStopTransaction(gun_index);
  3025. }
  3026. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3027. }
  3028. //==============================================
  3029. // Check Connector reserved
  3030. //==============================================
  3031. //===============================
  3032. // Check if Reserve is expired
  3033. //===============================
  3034. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  3035. {
  3036. double diff_t;
  3037. struct tm tp;
  3038. // current time
  3039. time_t t = time(NULL);
  3040. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  3041. tp.tm_isdst = -1;
  3042. time_t utc = mktime(&tp);
  3043. diff_t = difftime(utc, t);
  3044. if(diff_t <= 0)
  3045. {
  3046. DEBUG_INFO("reserve expired.\n");
  3047. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  3048. }
  3049. }//END OF Check if Reserve is expired
  3050. //==========================================
  3051. // csu trigger FirmwareStatusNotificationReq
  3052. //==========================================
  3053. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  3054. {
  3055. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  3056. }
  3057. //==========================================
  3058. // csu trigger DiagnosticsStatusNotificationReq
  3059. //==========================================
  3060. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  3061. {
  3062. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  3063. }
  3064. //==========================================
  3065. // csu trigger CancelReservationConf
  3066. //==========================================
  3067. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  3068. {
  3069. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  3070. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  3071. }
  3072. //==========================================
  3073. // csu trigger ChangeAvailabilityConf
  3074. //==========================================
  3075. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  3076. {
  3077. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  3078. }
  3079. //==========================================
  3080. // csu trigger UnlockConnectorConf
  3081. //==========================================
  3082. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  3083. {
  3084. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  3085. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  3086. }
  3087. //==========================================
  3088. // csu trigger ReserveNowConf
  3089. //==========================================
  3090. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  3091. {
  3092. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  3093. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  3094. }
  3095. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  3096. {
  3097. sendSignCertificateRequest();
  3098. }
  3099. }
  3100. }
  3101. //==========================================
  3102. // send request routine
  3103. //==========================================
  3104. int sendAuthorizeRequest(int gun_index)
  3105. {
  3106. mtrace();
  3107. int result = FAIL;
  3108. char message[100]={0};
  3109. char guid[37];
  3110. char tempdata[65]={0};
  3111. DEBUG_INFO("sendAuthorizeRequest...\n");
  3112. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  3113. //Local Authorize
  3114. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  3115. {
  3116. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  3117. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  3118. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  3119. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  3120. result = PASS;
  3121. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3122. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3123. authorizeRetryTimes = 0;
  3124. return result;
  3125. }
  3126. 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))||
  3127. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  3128. {
  3129. // Query from cache
  3130. DEBUG_INFO("Authorize from cache.\n");
  3131. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3132. // Query from list
  3133. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3134. {
  3135. DEBUG_INFO("Authorize from list.\n");
  3136. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3137. }
  3138. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3139. {
  3140. if(strcmp(idTagQuery.idTagstr,"") == 0)
  3141. {
  3142. DEBUG_INFO("off-line Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  3143. }
  3144. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  3145. {
  3146. DEBUG_INFO("off-line Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  3147. }
  3148. DEBUG_INFO("off-line Local Authorization Fail !!!!\n");
  3149. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3150. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3151. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  3152. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  3153. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3154. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3155. authorizeRetryTimes = 0;
  3156. return result;
  3157. }
  3158. else
  3159. {
  3160. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  3161. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3162. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3163. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  3164. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  3165. else
  3166. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  3167. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  3168. result = PASS;
  3169. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3170. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3171. authorizeRetryTimes = 0;
  3172. return result;
  3173. }
  3174. }
  3175. //initialize struct Authorize
  3176. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  3177. //get data from shared memory
  3178. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3179. random_uuid(guid);
  3180. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  3181. LWS_Send(message);
  3182. sprintf(tempdata, "Authorize,%d", gun_index);
  3183. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3184. {
  3185. result = PASS;
  3186. DEBUG_INFO("Authorize mapItem pass\n");
  3187. }
  3188. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3189. return result;
  3190. }
  3191. int sendBootNotificationRequest(void)
  3192. {
  3193. mtrace();
  3194. int result = FAIL;
  3195. char message[500]={0}, payload[700]={0};
  3196. char guid[37]={0};
  3197. char tempdata[65]={0};
  3198. // Fill BootNotification fields
  3199. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  3200. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  3201. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  3202. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3203. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  3204. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  3205. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  3206. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  3207. ShmOCPP16Data->ChargeBoxId
  3208. ,ShmSysConfigAndInfo->SysConfig.ModelName
  3209. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  3210. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  3211. ,ShmOCPP16Data->BootNotification.CpFwVersion
  3212. ,ShmOCPP16Data->BootNotification.CpIccid
  3213. ,ShmOCPP16Data->BootNotification.CpImsi);
  3214. random_uuid(guid);
  3215. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  3216. LWS_Send(message);
  3217. sprintf(tempdata, "BootNotification,0");
  3218. 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*/)
  3219. {
  3220. result = PASS;
  3221. }
  3222. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3223. strcpy(queuedata,message);
  3224. return result;
  3225. }
  3226. int sendDataTransferRequest(int gun_index)
  3227. {
  3228. mtrace();
  3229. char message[1000]={0};
  3230. char guid[37]={0};
  3231. char tempdata[65]={0};
  3232. int result = FAIL;
  3233. random_uuid(guid);
  3234. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  3235. MESSAGE_TYPE_CALL,
  3236. guid,
  3237. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  3238. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  3239. ShmOCPP16Data->DataTransfer[gun_index].Data);
  3240. LWS_Send(message);
  3241. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  3242. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3243. {
  3244. result = PASS;
  3245. DEBUG_INFO("DataTransfer mapItem pass\n");
  3246. }
  3247. return result;
  3248. }
  3249. int sendDiagnosticsStatusNotificationRequest(char *status)
  3250. {
  3251. mtrace();
  3252. int result = FAIL;
  3253. char message[110]={0};
  3254. char guid[37]={0};
  3255. char tempdata[65]={0};
  3256. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  3257. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  3258. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  3259. random_uuid(guid);
  3260. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  3261. LWS_SendNow(message);
  3262. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  3263. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3264. {
  3265. result = PASS;
  3266. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  3267. }
  3268. //#ifdef SystemLogMessage
  3269. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  3270. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3271. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  3272. //#endif
  3273. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  3274. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  3275. //record status
  3276. if(strcmp(status,"Idle")==0)
  3277. {
  3278. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  3279. }
  3280. else if(strcmp(status,"Uploaded")==0)
  3281. {
  3282. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  3283. }
  3284. else if(strcmp(status,"UploadFailed")==0)
  3285. {
  3286. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  3287. }
  3288. else if(strcmp(status,"Uploading")==0)
  3289. {
  3290. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  3291. }
  3292. return result;
  3293. }
  3294. int sendFirmwareStatusNotificationRequest(char *status)
  3295. {
  3296. mtrace();
  3297. int result = FAIL;
  3298. char message[110]={0};
  3299. char guid[37]={0};
  3300. char tempdata[65]={0};
  3301. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  3302. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  3303. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  3304. random_uuid(guid);
  3305. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  3306. LWS_SendNow(message);
  3307. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  3308. 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*/)
  3309. {
  3310. result = PASS;
  3311. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  3312. }
  3313. //#ifdef SystemLogMessage
  3314. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  3315. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3316. //#endif
  3317. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  3318. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  3319. //record status
  3320. if(strcmp(status,"Downloaded")==0)
  3321. {
  3322. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  3323. }
  3324. else if(strcmp(status,"DownloadFailed")==0)
  3325. {
  3326. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  3327. }
  3328. else if(strcmp(status,"Downloading")==0)
  3329. {
  3330. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  3331. }
  3332. else if(strcmp(status,"Idle")==0)
  3333. {
  3334. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  3335. }
  3336. else if(strcmp(status,"InstallationFailed")==0)
  3337. {
  3338. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  3339. }
  3340. else if(strcmp(status,"Installing")==0)
  3341. {
  3342. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  3343. }
  3344. else if(strcmp(status,"Installed")==0)
  3345. {
  3346. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  3347. }
  3348. return result;
  3349. }
  3350. int sendHeartbeatRequest(int gun_index)
  3351. {
  3352. mtrace();
  3353. int result = FAIL;
  3354. char message[80]={0};
  3355. char guid[37]={0};
  3356. char tempdata[65]={0};
  3357. random_uuid(guid);
  3358. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  3359. , MESSAGE_TYPE_CALL
  3360. , guid );
  3361. LWS_Send(message);
  3362. sprintf(tempdata, "Heartbeat,%d", 0);
  3363. 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*/)
  3364. {
  3365. result = PASS;
  3366. }
  3367. return result;
  3368. }
  3369. int sendStartTransactionRequest(int gun_index)
  3370. {
  3371. mtrace();
  3372. int result = FAIL;
  3373. char message[250]={0};
  3374. char guid[37]={0};
  3375. struct timeval tmnow;
  3376. struct tm *tm;
  3377. char buf[28];//, usec_buf[6];
  3378. char tempdata[65]={0};
  3379. int tempIndex = 0;
  3380. DEBUG_INFO("sendStartTransactionRequest...\n");
  3381. gettimeofday(&tmnow, NULL);
  3382. time_t t;
  3383. t = time(NULL);
  3384. /*UTC time and date*/
  3385. tm = gmtime(&t);
  3386. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3387. #if 0 // remove temporally
  3388. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3389. strcat(buf,".");
  3390. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3391. strcat(buf,usec_buf);
  3392. #endif
  3393. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  3394. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  3395. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3396. // clear StartTransaction Response
  3397. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  3398. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  3399. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  3400. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  3401. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3402. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3403. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3404. {
  3405. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3406. {
  3407. tempIndex = ((gun_index==2) ? 1: 0);
  3408. }
  3409. else
  3410. {
  3411. tempIndex = gun_index;
  3412. }
  3413. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3414. {
  3415. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3416. {
  3417. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3418. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  3419. }
  3420. }
  3421. }
  3422. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3423. {
  3424. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3425. {
  3426. tempIndex = ((gun_index==2) ? 1: 0);
  3427. }
  3428. else
  3429. {
  3430. tempIndex = gun_index;
  3431. }
  3432. for (int index = 0; index < CCS_QUANTITY; index++)
  3433. {
  3434. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3435. {
  3436. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3437. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  3438. }
  3439. }
  3440. }
  3441. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3442. {
  3443. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3444. {
  3445. tempIndex = ((gun_index==2) ? 1: 0);
  3446. }
  3447. else
  3448. {
  3449. tempIndex = gun_index;
  3450. }
  3451. for (int index = 0; index < GB_QUANTITY; index++)
  3452. {
  3453. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3454. {
  3455. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3456. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  3457. }
  3458. }
  3459. }
  3460. else if(gunType[gun_index] == GUN_TYPE_DO)
  3461. {
  3462. tempIndex = gun_index;
  3463. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3464. {
  3465. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3466. {
  3467. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3468. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  3469. }
  3470. }
  3471. }
  3472. else
  3473. {
  3474. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3475. {
  3476. tempIndex = 2;
  3477. }
  3478. else
  3479. {
  3480. tempIndex = gun_index;
  3481. }
  3482. for (int index = 0; index < AC_QUANTITY; index++)
  3483. {
  3484. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3485. {
  3486. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3487. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  3488. }
  3489. }
  3490. }
  3491. random_uuid(guid);
  3492. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  3493. {
  3494. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  3495. , gun_index +1
  3496. , MESSAGE_TYPE_CALL
  3497. , guid
  3498. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3499. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3500. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3501. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3502. }
  3503. else
  3504. {
  3505. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  3506. , gun_index +1
  3507. , MESSAGE_TYPE_CALL
  3508. , guid
  3509. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3510. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3511. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3512. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  3513. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3514. }
  3515. #if 1
  3516. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  3517. 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*/)
  3518. {
  3519. result = PASS;
  3520. }
  3521. #endif
  3522. strcpy(queuedata, message);
  3523. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3524. OCPP_insert_transaction_msg(YES, queuedata);
  3525. return result;
  3526. }
  3527. int sendStatusNotificationRequest(int gun_index)
  3528. {
  3529. mtrace();
  3530. int result = FAIL;
  3531. char message[600]={0};
  3532. char guid[37];
  3533. int currentStatus = 0;
  3534. struct timeval tmnow;
  3535. struct tm *tm;
  3536. char buf[28];//, usec_buf[6];
  3537. char tempdata[65]={0};
  3538. int tempIndex = 0;
  3539. uint8_t isStateChanged = TRUE;
  3540. DEBUG_INFO("sendStatusNotificationRequest...\n");
  3541. gettimeofday(&tmnow, NULL);
  3542. time_t t;
  3543. t = time(NULL);
  3544. /*UTC time and date*/
  3545. tm = gmtime(&t);
  3546. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3547. #if 0 // remove temporally
  3548. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3549. strcat(buf,".");
  3550. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3551. strcat(buf,usec_buf);
  3552. #endif
  3553. printf("%s",buf);
  3554. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  3555. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  3556. // it's option
  3557. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  3558. /*
  3559. enum _SYSTEM_STATUS
  3560. {
  3561. S_BOOTING = 0,
  3562. S_IDLE, = 1
  3563. S_AUTHORIZING, =2
  3564. S_REASSIGN_CHECK, =3
  3565. S_REASSIGN, =4
  3566. S_PRECHARGE, =5
  3567. S_PREPARING_FOR_EV, =6
  3568. S_PREPARING_FOR_EVSE, =7
  3569. S_CHARGING, =8
  3570. S_TERMINATING, =9
  3571. S_COMPLETE, =10
  3572. S_ALARM, =11
  3573. S_FAULT =12
  3574. }
  3575. */
  3576. //check Transaction active
  3577. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3578. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3579. {
  3580. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3581. {
  3582. tempIndex = ((gun_index==2) ? 1: 0);
  3583. }
  3584. else
  3585. {
  3586. tempIndex = gun_index;
  3587. }
  3588. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3589. {
  3590. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  3591. {
  3592. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  3593. {
  3594. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3595. {
  3596. currentStatus = Preparing; //OCPP Status: Preparing
  3597. }
  3598. else
  3599. {
  3600. currentStatus = Available; //OCPP Status: Available
  3601. }
  3602. }
  3603. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3604. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3605. ) //S_PRECHARGE
  3606. {
  3607. currentStatus = Preparing; //OCPP Status: Preparing
  3608. }
  3609. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3610. {
  3611. currentStatus = Charging; //OCPP Status: Charging
  3612. }
  3613. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3614. {
  3615. currentStatus = Finishing; //OCPP Status: Finishing
  3616. }
  3617. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3618. {
  3619. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3620. }
  3621. 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
  3622. {
  3623. currentStatus = Unavailable; //OCPP Status: Unavailable
  3624. }
  3625. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3626. {
  3627. currentStatus = Faulted; //OCPP Status: Faulted
  3628. }
  3629. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3630. {
  3631. currentStatus = Reserved; //OCPP Status: Reserved
  3632. }
  3633. } //end of the same index
  3634. }//end of for CHAdeMO_QUANTITY
  3635. }
  3636. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3637. {
  3638. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3639. {
  3640. tempIndex = ((gun_index==2) ? 1: 0);
  3641. }
  3642. else
  3643. {
  3644. tempIndex = gun_index;
  3645. }
  3646. for (int index = 0; index < CCS_QUANTITY; index++)
  3647. {
  3648. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3649. {
  3650. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3651. {
  3652. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3653. {
  3654. currentStatus = Preparing; //OCPP Status: Preparing
  3655. }
  3656. else
  3657. {
  3658. currentStatus = Available; //OCPP Status: Available
  3659. }
  3660. }
  3661. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3662. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3663. ) //S_PRECHARGE
  3664. {
  3665. currentStatus = Preparing; //OCPP Status: Preparing
  3666. }
  3667. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3668. {
  3669. currentStatus = Charging; //OCPP Status: Charging
  3670. }
  3671. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3672. {
  3673. currentStatus = Finishing; //OCPP Status: Finishing
  3674. }
  3675. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3676. {
  3677. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3678. }
  3679. 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
  3680. {
  3681. currentStatus = Unavailable; //OCPP Status : Unavailable
  3682. }
  3683. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3684. {
  3685. currentStatus = Faulted; //OCPP Status: Faulted
  3686. }
  3687. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3688. {
  3689. currentStatus = Reserved; //OCPP Status: Reserved
  3690. }
  3691. } //end of the same index
  3692. } // end of for CCS_QUANTITY
  3693. }
  3694. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3695. {
  3696. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3697. {
  3698. tempIndex = ((gun_index==2) ? 1: 0);
  3699. }
  3700. else
  3701. {
  3702. tempIndex = gun_index;
  3703. }
  3704. for (int index = 0; index < GB_QUANTITY; index++)
  3705. {
  3706. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3707. {
  3708. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3709. {
  3710. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3711. {
  3712. currentStatus = Preparing; //OCPP Status: Preparing
  3713. }
  3714. else
  3715. {
  3716. currentStatus = Available; //OCPP Status: Available
  3717. }
  3718. }
  3719. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3720. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3721. ) //S_PRECHARGE
  3722. {
  3723. currentStatus = Preparing; //OCPP Status: Preparing
  3724. }
  3725. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3726. {
  3727. currentStatus = Charging; //OCPP Status: Charging
  3728. }
  3729. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3730. {
  3731. currentStatus = Finishing; //OCPP Status: Finishing
  3732. }
  3733. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3734. {
  3735. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3736. }
  3737. 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
  3738. {
  3739. currentStatus = Unavailable; //OCPP Status: Unavailable
  3740. }
  3741. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3742. {
  3743. currentStatus = Faulted; //OCPP Status: Faulted
  3744. }
  3745. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3746. {
  3747. currentStatus = Reserved; //OCPP Status: Reserved
  3748. }
  3749. } //end of the same index
  3750. } // end of for GB_QUANTITY
  3751. }
  3752. else if(gunType[gun_index] == GUN_TYPE_DO)
  3753. {
  3754. tempIndex = gun_index;
  3755. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3756. {
  3757. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3758. {
  3759. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3760. {
  3761. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3762. {
  3763. currentStatus = Preparing; //OCPP Status: Preparing
  3764. }
  3765. else
  3766. {
  3767. currentStatus = Available; //OCPP Status: Available
  3768. }
  3769. }
  3770. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3771. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3772. ) //S_PRECHARGE
  3773. {
  3774. currentStatus = Preparing; //OCPP Status: Preparing
  3775. }
  3776. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3777. {
  3778. currentStatus = Charging; //OCPP Status: Charging
  3779. }
  3780. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3781. {
  3782. currentStatus = Finishing; //OCPP Status: Finishing
  3783. }
  3784. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3785. {
  3786. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3787. }
  3788. 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
  3789. {
  3790. currentStatus = Unavailable; //OCPP Status: Unavailable
  3791. }
  3792. 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
  3793. {
  3794. currentStatus = Faulted; //OCPP Status: Faulted
  3795. }
  3796. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3797. {
  3798. currentStatus = Reserved; //OCPP Status: Reserved
  3799. }
  3800. } //end of the same index
  3801. }
  3802. }
  3803. else
  3804. {
  3805. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3806. {
  3807. tempIndex = 2;
  3808. }
  3809. else
  3810. {
  3811. tempIndex = gun_index;
  3812. }
  3813. for (int index = 0; index < AC_QUANTITY; index++)
  3814. {
  3815. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3816. {
  3817. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3818. {
  3819. 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))
  3820. {
  3821. currentStatus = Preparing; //OCPP Status: Preparing
  3822. }
  3823. else
  3824. {
  3825. currentStatus = Available; //OCPP Status: Available
  3826. }
  3827. }
  3828. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  3829. {
  3830. currentStatus = Preparing; //OCPP Status: Preparing
  3831. }
  3832. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3833. {
  3834. currentStatus = Charging; //OCPP Status: Charging
  3835. }
  3836. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3837. {
  3838. currentStatus = Finishing; //OCPP Status: Finishing
  3839. }
  3840. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3841. {
  3842. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  3843. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3844. else
  3845. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  3846. }
  3847. 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
  3848. {
  3849. currentStatus = Unavailable; //OCPP Status: Unavailable
  3850. }
  3851. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3852. {
  3853. currentStatus = Faulted; //OCPP Status: Faulted
  3854. }
  3855. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3856. {
  3857. currentStatus = Reserved; //OCPP Status: Reserved
  3858. }
  3859. }//end of the same index
  3860. }//end of for AC_QUANTITY
  3861. }
  3862. //it's option
  3863. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  3864. !ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq)
  3865. {
  3866. isStateChanged = FALSE;
  3867. }
  3868. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  3869. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3870. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3871. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3872. random_uuid(guid);
  3873. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3874. , MESSAGE_TYPE_CALL
  3875. , guid
  3876. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3877. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3878. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3879. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3880. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3881. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3882. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3883. if((server_sign == TRUE) && isStateChanged)
  3884. {
  3885. LWS_Send(message);
  3886. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3887. 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*/)
  3888. {
  3889. //DEBUG_ERROR("statusNotification mapitem pass");
  3890. result = PASS;
  3891. }
  3892. }
  3893. else
  3894. {
  3895. result = PASS;
  3896. }
  3897. return result;
  3898. }
  3899. int sendStopTransactionRequest(int gun_index)
  3900. {
  3901. mtrace();
  3902. int result = FAIL;
  3903. //char message[1500]={0};
  3904. char guid[37]={0};
  3905. char tempdata[65]={0};
  3906. int tempIndex = 0;
  3907. char TempStopTransaction[256];
  3908. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  3909. //int idx_sample=0;
  3910. DEBUG_INFO("sendStopTransactionRequest \n");
  3911. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3912. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  3913. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  3914. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3915. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3916. {
  3917. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3918. {
  3919. tempIndex = ((gun_index==2) ? 1: 0);
  3920. }
  3921. else
  3922. {
  3923. tempIndex = gun_index;
  3924. }
  3925. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3926. {
  3927. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3928. {
  3929. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3930. }
  3931. }// END OF CHAdeMO_QUANTITY
  3932. }
  3933. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3934. {
  3935. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3936. {
  3937. tempIndex = ((gun_index==2) ? 1: 0);
  3938. }
  3939. else
  3940. {
  3941. tempIndex = gun_index;
  3942. }
  3943. for (int index = 0; index < CCS_QUANTITY; index++)
  3944. {
  3945. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3946. {
  3947. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3948. }
  3949. }// END OF CCS_QUANTITY
  3950. }
  3951. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3952. {
  3953. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3954. {
  3955. tempIndex = ((gun_index==2) ? 1: 0);
  3956. }
  3957. else
  3958. {
  3959. tempIndex = gun_index;
  3960. }
  3961. for (int index = 0; index < GB_QUANTITY; index++)
  3962. {
  3963. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3964. {
  3965. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3966. }
  3967. }// END OF GB_QUANTITY
  3968. }
  3969. else if(gunType[gun_index] == GUN_TYPE_DO)
  3970. {
  3971. tempIndex = gun_index;
  3972. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3973. {
  3974. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3975. {
  3976. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3977. }
  3978. }// END OF GB_QUANTITY
  3979. }
  3980. else
  3981. {
  3982. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3983. {
  3984. tempIndex = 2;
  3985. }
  3986. else
  3987. {
  3988. tempIndex = gun_index;
  3989. }
  3990. for (int index = 0; index < AC_QUANTITY; index++)
  3991. {
  3992. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3993. {
  3994. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3995. }
  3996. }// END OF AC_QUANTITY
  3997. }
  3998. //====================================== Stop Transaction Time =====================================================
  3999. struct timeval tmnow;
  4000. struct tm *tm;
  4001. char buf[28];//, usec_buf[6];
  4002. gettimeofday(&tmnow, NULL);
  4003. time_t t;
  4004. t = time(NULL);
  4005. /*UTC time and date*/
  4006. tm = gmtime(&t);
  4007. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4008. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  4009. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  4010. random_uuid(guid);
  4011. /***********************************transactionData******************************************************/
  4012. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  4013. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  4014. //=================================
  4015. // Transaction_Begin
  4016. //=================================
  4017. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4018. {
  4019. //============================================ Energy.Active.Import.Interval ================================
  4020. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  4021. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4022. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  4023. 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*/]);
  4024. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4025. 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))
  4026. {
  4027. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  4028. }
  4029. else
  4030. {
  4031. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  4032. }
  4033. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  4034. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4035. }
  4036. //=================================
  4037. // Transaction_End
  4038. //=================================
  4039. // ================================= Current.Import L1 ===============================================
  4040. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4041. {
  4042. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  4043. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4044. {
  4045. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4046. {
  4047. tempIndex = ((gun_index==2) ? 1: 0);
  4048. }
  4049. else
  4050. {
  4051. tempIndex = gun_index;
  4052. }
  4053. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4054. {
  4055. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4056. {
  4057. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4058. }
  4059. }// End of for CHAdeMO_QUANTITY
  4060. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4061. }
  4062. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4063. {
  4064. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4065. {
  4066. tempIndex = ((gun_index==2) ? 1: 0);
  4067. }
  4068. else
  4069. {
  4070. tempIndex = gun_index;
  4071. }
  4072. for (int index = 0; index < CCS_QUANTITY; index++)
  4073. {
  4074. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4075. {
  4076. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4077. }
  4078. }// End of for CCS_QUANTITY
  4079. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4080. }
  4081. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4082. {
  4083. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4084. {
  4085. tempIndex = ((gun_index==2) ? 1: 0);
  4086. }
  4087. else
  4088. {
  4089. tempIndex = gun_index;
  4090. }
  4091. for (int index = 0; index < GB_QUANTITY; index++)
  4092. {
  4093. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4094. {
  4095. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4096. }
  4097. }// End of for GB_QUANTITY
  4098. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4099. }
  4100. else if(gunType[gun_index] == GUN_TYPE_DO)
  4101. {
  4102. tempIndex = gun_index;
  4103. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4104. {
  4105. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4106. {
  4107. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4108. }
  4109. }
  4110. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4111. }
  4112. else
  4113. {
  4114. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4115. {
  4116. tempIndex = 2;
  4117. }
  4118. else
  4119. {
  4120. tempIndex = gun_index;
  4121. }
  4122. for (int index = 0; index < AC_QUANTITY; index++)
  4123. {
  4124. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4125. {
  4126. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  4127. }
  4128. }// End of for AC_QUANTITY
  4129. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  4130. }
  4131. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4132. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  4133. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  4134. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  4135. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4136. }
  4137. // ================================= Energy.Active.Import.Interval ==============================================
  4138. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4139. {
  4140. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4141. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4142. {
  4143. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4144. {
  4145. tempIndex = ((gun_index==2) ? 1: 0);
  4146. }
  4147. else
  4148. {
  4149. tempIndex = gun_index;
  4150. }
  4151. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4152. {
  4153. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4154. {
  4155. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4156. }
  4157. }// END OF CHAdeMO_QUANTITY
  4158. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4159. }
  4160. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4161. {
  4162. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4163. {
  4164. tempIndex = ((gun_index==2) ? 1: 0);
  4165. }
  4166. else
  4167. {
  4168. tempIndex = gun_index;
  4169. }
  4170. for (int index = 0; index < CCS_QUANTITY; index++)
  4171. {
  4172. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4173. {
  4174. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4175. }
  4176. }// END OF CCS_QUANTITY
  4177. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4178. }
  4179. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4180. {
  4181. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4182. {
  4183. tempIndex = ((gun_index==2) ? 1: 0);
  4184. }
  4185. else
  4186. {
  4187. tempIndex = gun_index;
  4188. }
  4189. for (int index = 0; index < GB_QUANTITY; index++)
  4190. {
  4191. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4192. {
  4193. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4194. }
  4195. }// END OF GB_QUANTITY
  4196. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4197. }
  4198. else if(gunType[gun_index] == GUN_TYPE_DO)
  4199. {
  4200. tempIndex = gun_index;
  4201. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4202. {
  4203. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4204. {
  4205. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4206. }
  4207. }
  4208. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4209. }
  4210. else
  4211. {
  4212. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4213. {
  4214. tempIndex = 2;
  4215. }
  4216. else
  4217. {
  4218. tempIndex = gun_index;
  4219. }
  4220. for (int index = 0; index < AC_QUANTITY; index++)
  4221. {
  4222. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4223. {
  4224. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4225. }
  4226. }// END OF AC_QUANTITY
  4227. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  4228. }
  4229. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4230. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  4231. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  4232. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  4233. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4234. }
  4235. //=================================== Power.Active.Import ==================================================
  4236. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  4237. {
  4238. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4239. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4240. {
  4241. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4242. {
  4243. tempIndex = ((gun_index==2) ? 1: 0);
  4244. }
  4245. else
  4246. {
  4247. tempIndex = gun_index;
  4248. }
  4249. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4250. {
  4251. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4252. {
  4253. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4254. }
  4255. } // End for CHAdeMO_QUANTITY
  4256. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4257. }
  4258. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4259. {
  4260. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4261. {
  4262. tempIndex = ((gun_index==2) ? 1: 0);
  4263. }
  4264. else
  4265. {
  4266. tempIndex = gun_index;
  4267. }
  4268. for (int index = 0; index < CCS_QUANTITY; index++)
  4269. {
  4270. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4271. {
  4272. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4273. }
  4274. } // END for CCS_QUANTITY
  4275. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4276. }
  4277. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4278. {
  4279. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4280. {
  4281. tempIndex = ((gun_index==2) ? 1: 0);
  4282. }
  4283. else
  4284. {
  4285. tempIndex = gun_index;
  4286. }
  4287. for (int index = 0; index < GB_QUANTITY; index++)
  4288. {
  4289. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4290. {
  4291. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4292. }
  4293. }// END for GB_QUANTITY
  4294. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4295. }
  4296. else if(gunType[gun_index] == GUN_TYPE_DO)
  4297. {
  4298. tempIndex = gun_index;
  4299. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4300. {
  4301. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4302. {
  4303. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4304. }
  4305. }
  4306. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4307. }
  4308. else
  4309. {
  4310. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4311. {
  4312. tempIndex = 2;
  4313. }
  4314. else
  4315. {
  4316. tempIndex = gun_index;
  4317. }
  4318. for (int index = 0; index < AC_QUANTITY; index++)
  4319. {
  4320. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4321. {
  4322. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4323. }
  4324. } // END for AC_QUANTITY
  4325. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  4326. }
  4327. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4328. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  4329. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  4330. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  4331. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  4332. }
  4333. //============================ Voltage L1 ====================================
  4334. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4335. {
  4336. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4337. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4338. {
  4339. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4340. {
  4341. tempIndex = ((gun_index==2) ? 1: 0);
  4342. }
  4343. else
  4344. {
  4345. tempIndex = gun_index;
  4346. }
  4347. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4348. {
  4349. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4350. {
  4351. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4352. }
  4353. } // END OF FOR CHAdeMO_QUANTITY
  4354. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4355. }
  4356. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4357. {
  4358. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4359. {
  4360. tempIndex = ((gun_index==2) ? 1: 0);
  4361. }
  4362. else
  4363. {
  4364. tempIndex = gun_index;
  4365. }
  4366. for (int index = 0; index < CCS_QUANTITY; index++)
  4367. {
  4368. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4369. {
  4370. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4371. }
  4372. } // END OF FOR CCS_QUANTITY
  4373. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4374. }
  4375. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4376. {
  4377. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4378. {
  4379. tempIndex = ((gun_index==2) ? 1: 0);
  4380. }
  4381. else
  4382. {
  4383. tempIndex = gun_index;
  4384. }
  4385. for (int index = 0; index < GB_QUANTITY; index++)
  4386. {
  4387. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4388. {
  4389. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4390. }
  4391. } // END OF FOR GB_QUANTITY
  4392. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4393. }
  4394. else if(gunType[gun_index] == GUN_TYPE_DO)
  4395. {
  4396. tempIndex = gun_index;
  4397. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4398. {
  4399. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4400. {
  4401. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4402. }
  4403. }
  4404. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4405. }
  4406. else
  4407. {
  4408. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4409. {
  4410. tempIndex = 2;
  4411. }
  4412. else
  4413. {
  4414. tempIndex = gun_index;
  4415. }
  4416. for (int index = 0; index < AC_QUANTITY; index++)
  4417. {
  4418. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4419. {
  4420. 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
  4421. }
  4422. } // END OF FOR AC_QUANTITY
  4423. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  4424. }
  4425. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4426. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  4427. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  4428. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  4429. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4430. }
  4431. //====================== End SoC ================================
  4432. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4433. {
  4434. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4435. 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))
  4436. {
  4437. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4438. {
  4439. tempIndex = ((gun_index==2) ? 1: 0);
  4440. }
  4441. else
  4442. {
  4443. tempIndex = gun_index;
  4444. }
  4445. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4446. {
  4447. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4448. {
  4449. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4450. {
  4451. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  4452. }
  4453. }
  4454. }
  4455. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4456. {
  4457. for (int index = 0; index < CCS_QUANTITY; index++)
  4458. {
  4459. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4460. {
  4461. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  4462. }
  4463. }
  4464. }
  4465. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4466. {
  4467. for (int index = 0; index < GB_QUANTITY; index++)
  4468. {
  4469. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4470. {
  4471. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  4472. }
  4473. }
  4474. }
  4475. else if(gunType[gun_index] == GUN_TYPE_DO)
  4476. {
  4477. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4478. {
  4479. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4480. {
  4481. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  4482. }
  4483. }
  4484. }
  4485. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4486. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  4487. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4488. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  4489. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  4490. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4491. } // END FOR DC CASE
  4492. }
  4493. // ================================= Current.Import L2 ===============================================
  4494. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4495. {
  4496. // AC 3 phse L2 current
  4497. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4498. {
  4499. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4500. {
  4501. tempIndex = 2;
  4502. }
  4503. else
  4504. {
  4505. tempIndex = gun_index;
  4506. }
  4507. for (int index = 0; index < AC_QUANTITY; index++)
  4508. {
  4509. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4510. {
  4511. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  4512. }
  4513. }// End of for AC_QUANTITY
  4514. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  4515. }
  4516. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4517. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  4518. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  4519. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  4520. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4521. }
  4522. // ================================= Current.Import L3 ===============================================
  4523. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4524. {
  4525. // AC 3 phse L3 current
  4526. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4527. {
  4528. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4529. {
  4530. tempIndex = 2;
  4531. }
  4532. else
  4533. {
  4534. tempIndex = gun_index;
  4535. }
  4536. for (int index = 0; index < AC_QUANTITY; index++)
  4537. {
  4538. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4539. {
  4540. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  4541. }
  4542. }// End of for AC_QUANTITY
  4543. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  4544. }
  4545. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4546. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  4547. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  4548. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  4549. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4550. }
  4551. //============================ Voltage L2 ====================================
  4552. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4553. {
  4554. // AC 3 phse L2 voltage
  4555. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4556. {
  4557. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4558. {
  4559. tempIndex = 2;
  4560. }
  4561. else
  4562. {
  4563. tempIndex = gun_index;
  4564. }
  4565. for (int index = 0; index < AC_QUANTITY; index++)
  4566. {
  4567. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4568. {
  4569. 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
  4570. }
  4571. } // END OF FOR AC_QUANTITY
  4572. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  4573. }
  4574. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4575. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  4576. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  4577. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  4578. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4579. }
  4580. //============================ Voltage L3 ====================================
  4581. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4582. {
  4583. // AC 3 phse L3 voltage
  4584. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4585. {
  4586. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4587. {
  4588. tempIndex = 2;
  4589. }
  4590. else
  4591. {
  4592. tempIndex = gun_index;
  4593. }
  4594. for (int index = 0; index < AC_QUANTITY; index++)
  4595. {
  4596. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4597. {
  4598. 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
  4599. }
  4600. } // END OF FOR AC_QUANTITY
  4601. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  4602. }
  4603. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4604. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  4605. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  4606. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  4607. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4608. }
  4609. //====================== Start SoC ================================
  4610. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4611. {
  4612. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4613. 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))
  4614. {
  4615. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4616. {
  4617. tempIndex = ((gun_index==2) ? 1: 0);
  4618. }
  4619. else
  4620. {
  4621. tempIndex = gun_index;
  4622. }
  4623. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4624. {
  4625. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4626. {
  4627. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4628. {
  4629. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  4630. }
  4631. }
  4632. }
  4633. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4634. {
  4635. for (int index = 0; index < CCS_QUANTITY; index++)
  4636. {
  4637. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4638. {
  4639. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  4640. }
  4641. }
  4642. }
  4643. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4644. {
  4645. for (int index = 0; index < GB_QUANTITY; index++)
  4646. {
  4647. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4648. {
  4649. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  4650. }
  4651. }
  4652. }
  4653. else if(gunType[gun_index] == GUN_TYPE_DO)
  4654. {
  4655. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4656. {
  4657. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4658. {
  4659. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  4660. }
  4661. }
  4662. }
  4663. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4664. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  4665. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4666. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  4667. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  4668. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4669. } // END FOR DC CASE
  4670. }
  4671. //================================================ Message create ====================================================
  4672. json_object *StopTransaction = json_object_new_object();
  4673. json_object *transactionDatas = json_object_new_array();
  4674. json_object *sampledValues = json_object_new_array();
  4675. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  4676. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  4677. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  4678. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  4679. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  4680. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  4681. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  4682. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  4683. {
  4684. json_object *transactionData = json_object_new_object();
  4685. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  4686. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  4687. {
  4688. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  4689. {
  4690. json_object *sampledValue = json_object_new_object();
  4691. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  4692. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  4693. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  4694. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  4695. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  4696. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  4697. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  4698. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  4699. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  4700. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  4701. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  4702. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  4703. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  4704. json_object_array_add(sampledValues, sampledValue);
  4705. }
  4706. }
  4707. json_object_object_add(transactionData, "sampledValue", sampledValues);
  4708. json_object_array_add(transactionDatas, transactionData);
  4709. }
  4710. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  4711. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  4712. ,MESSAGE_TYPE_CALL
  4713. ,guid
  4714. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  4715. json_object_put(StopTransaction);
  4716. #if 1 // for TempStopTransaction
  4717. //Delete TempStopTransaction
  4718. if((access(TempStopTransaction,F_OK))!=-1)
  4719. {
  4720. remove(TempStopTransaction); // remove file "TempStopTransaction"
  4721. }
  4722. #endif
  4723. #if 1
  4724. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4725. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4726. {
  4727. result = PASS;
  4728. //DEBUG_INFO("StopTransaction mapitem pass\n");
  4729. }
  4730. #endif
  4731. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4732. OCPP_insert_transaction_msg(NO, queuedata);
  4733. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4734. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  4735. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  4736. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4737. {
  4738. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  4739. }
  4740. //for test
  4741. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4742. return result;
  4743. }
  4744. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  4745. {
  4746. mtrace();
  4747. int result = FAIL;
  4748. char guid[37]={0};
  4749. char tempdata[65]={0};
  4750. int tempIndex = 0;
  4751. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4752. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4753. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  4754. //set value
  4755. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4756. 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) )?
  4757. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  4758. -1);
  4759. random_uuid(guid);
  4760. //UTC Date time
  4761. struct timeval tmnow;
  4762. struct tm *tm;
  4763. char buf[28];//, usec_buf[6];
  4764. gettimeofday(&tmnow, NULL);
  4765. time_t t;
  4766. t = time(NULL);
  4767. /*UTC time and date*/
  4768. tm = gmtime(&t);
  4769. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4770. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4771. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4772. //********************************(1)Current.Import L1************************************************/
  4773. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  4774. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  4775. (dataType == ReadingContext_Trigger))
  4776. {
  4777. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4778. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4779. {
  4780. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4781. {
  4782. tempIndex = ((gun_index==2) ? 1: 0);
  4783. }
  4784. else
  4785. {
  4786. tempIndex = gun_index;
  4787. }
  4788. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4789. {
  4790. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4791. {
  4792. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4793. }
  4794. }
  4795. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4796. }
  4797. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4798. {
  4799. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4800. {
  4801. tempIndex = ((gun_index==2) ? 1: 0);
  4802. }
  4803. else
  4804. {
  4805. tempIndex = gun_index;
  4806. }
  4807. for (int index = 0; index < CCS_QUANTITY; index++)
  4808. {
  4809. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4810. {
  4811. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4812. }
  4813. }
  4814. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4815. }
  4816. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4817. {
  4818. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4819. {
  4820. tempIndex = ((gun_index==2) ? 1: 0);
  4821. }
  4822. else
  4823. {
  4824. tempIndex = gun_index;
  4825. }
  4826. for (int index = 0; index < GB_QUANTITY; index++)
  4827. {
  4828. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4829. {
  4830. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4831. }
  4832. }
  4833. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4834. }
  4835. else if(gunType[gun_index] == GUN_TYPE_DO)
  4836. {
  4837. tempIndex = gun_index;
  4838. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4839. {
  4840. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4841. {
  4842. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  4843. }
  4844. }
  4845. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4846. }
  4847. else
  4848. {
  4849. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4850. {
  4851. tempIndex = 2;
  4852. }
  4853. else
  4854. {
  4855. tempIndex = gun_index;
  4856. }
  4857. for (int index = 0; index < AC_QUANTITY; index++)
  4858. {
  4859. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4860. {
  4861. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4862. }
  4863. }
  4864. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4865. }
  4866. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4867. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4868. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4869. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4870. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4871. }
  4872. //********************************(2)Energy.Active.Import.Register ************************************************/
  4873. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4874. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4875. (dataType == ReadingContext_Trigger))
  4876. {
  4877. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4878. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4879. {
  4880. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4881. {
  4882. tempIndex = ((gun_index==2) ? 1: 0);
  4883. }
  4884. else
  4885. {
  4886. tempIndex = gun_index;
  4887. }
  4888. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4889. {
  4890. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4891. {
  4892. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4893. }
  4894. }
  4895. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4896. }
  4897. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4898. {
  4899. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4900. {
  4901. tempIndex = ((gun_index==2) ? 1: 0);
  4902. }
  4903. else
  4904. {
  4905. tempIndex = gun_index;
  4906. }
  4907. for (int index = 0; index < CCS_QUANTITY; index++)
  4908. {
  4909. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4910. {
  4911. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4912. }
  4913. }
  4914. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4915. }
  4916. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4917. {
  4918. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4919. {
  4920. tempIndex = ((gun_index==2) ? 1: 0);
  4921. }
  4922. else
  4923. {
  4924. tempIndex = gun_index;
  4925. }
  4926. for (int index = 0; index < GB_QUANTITY; index++)
  4927. {
  4928. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4929. {
  4930. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4931. }
  4932. }
  4933. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4934. }
  4935. else if(gunType[gun_index] == GUN_TYPE_DO)
  4936. {
  4937. tempIndex = gun_index;
  4938. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4939. {
  4940. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4941. {
  4942. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  4943. }
  4944. }
  4945. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4946. }
  4947. else
  4948. {
  4949. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4950. {
  4951. tempIndex = 2;
  4952. }
  4953. else
  4954. {
  4955. tempIndex = gun_index;
  4956. }
  4957. for (int index = 0; index < AC_QUANTITY; index++)
  4958. {
  4959. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4960. {
  4961. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  4962. }
  4963. }
  4964. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4965. }
  4966. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  4967. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  4968. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  4969. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  4970. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4971. }
  4972. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  4973. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  4974. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  4975. (dataType == ReadingContext_Trigger))
  4976. {
  4977. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4978. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4979. {
  4980. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4981. {
  4982. tempIndex = ((gun_index==2) ? 1: 0);
  4983. }
  4984. else
  4985. {
  4986. tempIndex = gun_index;
  4987. }
  4988. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4989. {
  4990. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4991. {
  4992. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  4993. }
  4994. } // END OF FOR CHAdeMO_QUANTITY
  4995. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4996. }
  4997. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4998. {
  4999. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5000. {
  5001. tempIndex = ((gun_index==2) ? 1: 0);
  5002. }
  5003. else
  5004. {
  5005. tempIndex = gun_index;
  5006. }
  5007. for (int index = 0; index < CCS_QUANTITY; index++)
  5008. {
  5009. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5010. {
  5011. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  5012. }
  5013. } // END OF CCS_QUANTITY
  5014. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5015. }
  5016. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5017. {
  5018. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5019. {
  5020. tempIndex = ((gun_index==2) ? 1: 0);
  5021. }
  5022. else
  5023. {
  5024. tempIndex = gun_index;
  5025. }
  5026. for (int index = 0; index < GB_QUANTITY; index++)
  5027. {
  5028. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5029. {
  5030. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  5031. }
  5032. } // END OF GB_QUANTITY
  5033. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5034. }
  5035. else if(gunType[gun_index] == GUN_TYPE_DO)
  5036. {
  5037. tempIndex = gun_index;
  5038. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5039. {
  5040. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5041. {
  5042. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  5043. }
  5044. }
  5045. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5046. }
  5047. else
  5048. {
  5049. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5050. {
  5051. tempIndex = 2;
  5052. }
  5053. else
  5054. {
  5055. tempIndex = gun_index;
  5056. }
  5057. for (int index = 0; index < AC_QUANTITY; index++)
  5058. {
  5059. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5060. {
  5061. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  5062. }
  5063. }
  5064. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  5065. }
  5066. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  5067. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  5068. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  5069. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  5070. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5071. }
  5072. //********************************(4)Power.Active.Import************************************************/
  5073. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Power.Active.Import") != NULL)) ||
  5074. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Power.Active.Import") != NULL)) ||
  5075. (dataType == ReadingContext_Trigger))
  5076. {
  5077. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5078. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5079. {
  5080. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5081. {
  5082. tempIndex = ((gun_index==2) ? 1: 0);
  5083. }
  5084. else
  5085. {
  5086. tempIndex = gun_index;
  5087. }
  5088. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5089. {
  5090. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5091. {
  5092. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  5093. }
  5094. } // END OF FOR
  5095. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5096. }
  5097. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5098. {
  5099. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5100. {
  5101. tempIndex = ((gun_index==2) ? 1: 0);
  5102. }
  5103. else
  5104. {
  5105. tempIndex = gun_index;
  5106. }
  5107. for (int index = 0; index < CCS_QUANTITY; index++)
  5108. {
  5109. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5110. {
  5111. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  5112. }
  5113. }
  5114. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5115. }
  5116. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5117. {
  5118. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5119. {
  5120. tempIndex = ((gun_index==2) ? 1: 0);
  5121. }
  5122. else
  5123. {
  5124. tempIndex = gun_index;
  5125. }
  5126. for (int index = 0; index < GB_QUANTITY; index++)
  5127. {
  5128. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5129. {
  5130. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5131. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  5132. }
  5133. }
  5134. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5135. }
  5136. else if(gunType[gun_index] == GUN_TYPE_DO)
  5137. {
  5138. tempIndex = gun_index;
  5139. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5140. {
  5141. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5142. {
  5143. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5144. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  5145. }
  5146. }
  5147. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5148. }
  5149. else
  5150. {
  5151. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5152. {
  5153. tempIndex = 2;
  5154. }
  5155. else
  5156. {
  5157. tempIndex = gun_index;
  5158. }
  5159. for (int index = 0; index < AC_QUANTITY; index++)
  5160. {
  5161. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5162. {
  5163. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  5164. }
  5165. }
  5166. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  5167. }
  5168. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  5169. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  5170. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  5171. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  5172. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  5173. }
  5174. //***********************************************(5)VOLTAGE L1******************************************************/
  5175. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5176. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5177. (dataType == ReadingContext_Trigger))
  5178. {
  5179. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5180. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5181. {
  5182. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5183. {
  5184. tempIndex = ((gun_index==2) ? 1: 0);
  5185. }
  5186. else
  5187. {
  5188. tempIndex = gun_index;
  5189. }
  5190. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5191. {
  5192. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5193. {
  5194. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  5195. }
  5196. }
  5197. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5198. }
  5199. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5200. {
  5201. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5202. {
  5203. tempIndex = ((gun_index==2) ? 1: 0);
  5204. }
  5205. else
  5206. {
  5207. tempIndex = gun_index;
  5208. }
  5209. for (int index = 0; index < CCS_QUANTITY; index++)
  5210. {
  5211. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5212. {
  5213. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  5214. }
  5215. }
  5216. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5217. }
  5218. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5219. {
  5220. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5221. {
  5222. tempIndex = ((gun_index==2) ? 1: 0);
  5223. }
  5224. else
  5225. {
  5226. tempIndex = gun_index;
  5227. }
  5228. for (int index = 0; index < GB_QUANTITY; index++)
  5229. {
  5230. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5231. {
  5232. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  5233. }
  5234. }
  5235. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5236. }
  5237. else if(gunType[gun_index] == GUN_TYPE_DO)
  5238. {
  5239. tempIndex = gun_index;
  5240. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5241. {
  5242. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5243. {
  5244. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  5245. }
  5246. }
  5247. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5248. }
  5249. else
  5250. {
  5251. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5252. {
  5253. tempIndex = 2;
  5254. }
  5255. else
  5256. {
  5257. tempIndex = gun_index;
  5258. }
  5259. for (int index = 0; index < AC_QUANTITY; index++)
  5260. {
  5261. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5262. {
  5263. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  5264. }
  5265. }
  5266. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  5267. }
  5268. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  5269. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  5270. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  5271. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  5272. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5273. }
  5274. //***********************************************(6)SOC******************************************************/
  5275. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "SOC") != NULL)) ||
  5276. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "SOC") != NULL)) ||
  5277. (dataType == ReadingContext_Trigger))
  5278. {
  5279. 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))
  5280. {
  5281. //idx_sample=5;
  5282. //sampledValue = NULL;
  5283. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5284. {
  5285. tempIndex = ((gun_index==2) ? 1: 0);
  5286. }
  5287. else
  5288. {
  5289. tempIndex = gun_index;
  5290. }
  5291. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5292. {
  5293. //tempIndex = ((gun_index==2) ? 1: 0);
  5294. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5295. {
  5296. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5297. {
  5298. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  5299. }
  5300. }
  5301. }
  5302. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5303. {
  5304. //tempIndex = ((gun_index==2) ? 1: 0);
  5305. for (int index = 0; index < CCS_QUANTITY; index++)
  5306. {
  5307. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5308. {
  5309. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  5310. }
  5311. }
  5312. }
  5313. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5314. {
  5315. //tempIndex = ((gun_index==2) ? 1: 0);
  5316. for (int index = 0; index < GB_QUANTITY; index++)
  5317. {
  5318. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5319. {
  5320. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  5321. }
  5322. }
  5323. }
  5324. else if(gunType[gun_index] == GUN_TYPE_DO)
  5325. {
  5326. //tempIndex = ((gun_index==2) ? 1: 0);
  5327. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5328. {
  5329. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5330. {
  5331. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  5332. }
  5333. }
  5334. }
  5335. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  5336. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  5337. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  5338. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  5339. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  5340. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  5341. }
  5342. }
  5343. //********************************(7)Current.Import L2************************************************/
  5344. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5345. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5346. (dataType == ReadingContext_Trigger))
  5347. {
  5348. // Only for AC 3 phase
  5349. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5350. {
  5351. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5352. {
  5353. tempIndex = 2;
  5354. }
  5355. else
  5356. {
  5357. tempIndex = gun_index;
  5358. }
  5359. for (int index = 0; index < AC_QUANTITY; index++)
  5360. {
  5361. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5362. {
  5363. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  5364. }
  5365. }
  5366. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  5367. }
  5368. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  5369. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  5370. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  5371. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  5372. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5373. }
  5374. //********************************(8)Current.Import L3************************************************/
  5375. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5376. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5377. (dataType == ReadingContext_Trigger))
  5378. {
  5379. // Only for AC 3 phase
  5380. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5381. {
  5382. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5383. {
  5384. tempIndex = 2;
  5385. }
  5386. else
  5387. {
  5388. tempIndex = gun_index;
  5389. }
  5390. for (int index = 0; index < AC_QUANTITY; index++)
  5391. {
  5392. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5393. {
  5394. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  5395. }
  5396. }
  5397. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  5398. }
  5399. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  5400. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  5401. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  5402. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  5403. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5404. }
  5405. //***********************************************(9)VOLTAGE L2******************************************************/
  5406. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5407. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5408. (dataType == ReadingContext_Trigger))
  5409. {
  5410. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5411. {
  5412. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5413. {
  5414. tempIndex = 2;
  5415. }
  5416. else
  5417. {
  5418. tempIndex = gun_index;
  5419. }
  5420. for (int index = 0; index < AC_QUANTITY; index++)
  5421. {
  5422. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5423. {
  5424. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  5425. }
  5426. }
  5427. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  5428. }
  5429. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  5430. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  5431. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  5432. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  5433. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5434. }
  5435. //***********************************************(10)VOLTAGE L3******************************************************/
  5436. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5437. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5438. (dataType == ReadingContext_Trigger))
  5439. {
  5440. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5441. {
  5442. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5443. {
  5444. tempIndex = 2;
  5445. }
  5446. else
  5447. {
  5448. tempIndex = gun_index;
  5449. }
  5450. for (int index = 0; index < AC_QUANTITY; index++)
  5451. {
  5452. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5453. {
  5454. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  5455. }
  5456. }
  5457. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  5458. }
  5459. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  5460. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  5461. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  5462. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  5463. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5464. }
  5465. // Message create ====================================================================================================
  5466. if(TRUE)
  5467. {
  5468. json_object *MeterValueReq = json_object_new_object();
  5469. json_object *MeterValues = json_object_new_array();
  5470. json_object *sampledValues = json_object_new_array();
  5471. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  5472. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  5473. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  5474. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  5475. {
  5476. json_object *MeterValue = json_object_new_object();
  5477. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  5478. {
  5479. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  5480. {
  5481. json_object *sampledValue = json_object_new_object();
  5482. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  5483. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  5484. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  5485. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  5486. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  5487. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  5488. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  5489. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  5490. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  5491. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  5492. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  5493. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  5494. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  5495. json_object_array_add(sampledValues, sampledValue);
  5496. }
  5497. }
  5498. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  5499. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  5500. json_object_array_add(MeterValues, MeterValue);
  5501. }
  5502. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  5503. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  5504. ,gun_index + 1
  5505. ,MESSAGE_TYPE_CALL
  5506. ,guid
  5507. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  5508. json_object_put(MeterValueReq);
  5509. }
  5510. // Put request guid to hash map
  5511. sprintf(tempdata, "MeterValues,%d", (gun_index));
  5512. 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*/)
  5513. {
  5514. result = PASS;
  5515. //DEBUG_INFO("MeterValues mapitem pass\n");
  5516. }
  5517. if((dataType != ReadingContext_Trigger) &&
  5518. (dataType != ReadingContext_Sample_Clock) &&
  5519. (ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1))
  5520. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  5521. else
  5522. {
  5523. if(FirstHeartBeat)
  5524. LWS_Send(queuedata +2);
  5525. }
  5526. return result;
  5527. }
  5528. int sendLogStatusNotificationRequest(char *status)
  5529. {
  5530. mtrace();
  5531. int result = PASS;
  5532. char message[4096]={0};
  5533. char guid[37]={0};
  5534. char tempdata[128]={0};
  5535. json_object *LogStatusNotification = json_object_new_object();
  5536. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  5537. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  5538. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  5539. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  5540. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  5541. random_uuid(guid);
  5542. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  5543. json_object_put(LogStatusNotification);
  5544. LWS_Send(message);
  5545. sprintf(tempdata, "LogStatusNotification,%d", 0);
  5546. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5547. {
  5548. result = PASS;
  5549. }
  5550. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  5551. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  5552. return result;
  5553. }
  5554. int sendSecurityEventNotificationRequest()
  5555. {
  5556. mtrace();
  5557. int result = PASS;
  5558. char message[4096]={0};
  5559. char guid[37]={0};
  5560. char tempdata[128]={0};
  5561. json_object *SecurityEventNotification = json_object_new_object();
  5562. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  5563. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  5564. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  5565. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  5566. random_uuid(guid);
  5567. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  5568. json_object_put(SecurityEventNotification);
  5569. LWS_Send(message);
  5570. sprintf(tempdata, "SecurityEventNotification,0");
  5571. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5572. {
  5573. result = PASS;
  5574. }
  5575. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  5576. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  5577. return result;
  5578. }
  5579. int sendSignCertificateRequest()
  5580. {
  5581. mtrace();
  5582. int result = PASS;
  5583. char message[4096]={0};
  5584. char guid[37]={0};
  5585. char tempdata[128]={0};
  5586. json_object *SignCertificate = json_object_new_object();
  5587. DEBUG_INFO("sendSignCertificateRequest...\n");
  5588. // Read csr file content
  5589. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  5590. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  5591. char *line = NULL;
  5592. size_t len = 0;
  5593. while(getline(&line, &len, fp) != -1)
  5594. {
  5595. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  5596. {
  5597. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  5598. }
  5599. }
  5600. fclose(fp);
  5601. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  5602. random_uuid(guid);
  5603. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  5604. json_object_put(SignCertificate);
  5605. LWS_Send(message);
  5606. sprintf(tempdata, "SignCertificate,0");
  5607. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5608. {
  5609. result = PASS;
  5610. }
  5611. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  5612. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  5613. return result;
  5614. }
  5615. int sendSignedFirmwareStatusNotificationRequest(char *status)
  5616. {
  5617. mtrace();
  5618. int result = PASS;
  5619. char message[110]={0};
  5620. char guid[37]={0};
  5621. char tempdata[65]={0};
  5622. json_object *FirmwareStatusNotification = json_object_new_object();
  5623. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  5624. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  5625. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  5626. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  5627. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  5628. random_uuid(guid);
  5629. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  5630. json_object_put(FirmwareStatusNotification);
  5631. LWS_Send(message);
  5632. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  5633. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5634. {
  5635. result = PASS;
  5636. }
  5637. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  5638. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  5639. return result;
  5640. }
  5641. //==========================================
  5642. // send confirm routine
  5643. //==========================================
  5644. int sendCancelReservationConfirmation(char *uuid,char *payload)
  5645. {
  5646. mtrace();
  5647. int result = FAIL;
  5648. char message[100]={0};
  5649. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  5650. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5651. LWS_Send(message);
  5652. result = TRUE;
  5653. return result;
  5654. }
  5655. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  5656. {
  5657. mtrace();
  5658. int result = FAIL;
  5659. char message[100]={0};
  5660. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  5661. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5662. LWS_Send(message);
  5663. result = TRUE;
  5664. return result;
  5665. }
  5666. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  5667. {
  5668. mtrace();
  5669. int result = FAIL;
  5670. char message[100]={0};
  5671. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  5672. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5673. LWS_Send(message);
  5674. result = TRUE;
  5675. return result;
  5676. }
  5677. int sendClearCacheConfirmation(char *uuid,char *payload)
  5678. {
  5679. mtrace();
  5680. int result = FAIL;
  5681. char message[500]={0};
  5682. DEBUG_INFO("sendClearCacheConfirmation...\n");
  5683. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5684. LWS_Send(message);
  5685. return result;
  5686. }
  5687. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  5688. {
  5689. mtrace();
  5690. int result = FAIL;
  5691. char message[500]={0};
  5692. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  5693. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5694. LWS_Send(message);
  5695. return result;
  5696. }
  5697. int sendDataTransferConfirmation(char *uuid,char *payload)
  5698. {
  5699. mtrace();
  5700. char statusStr[20]={0};
  5701. char dataStr[10]={0};
  5702. char sstr[20]={0};
  5703. int c = 0;
  5704. char *loc;
  5705. int result = FAIL;
  5706. DEBUG_INFO("sendDataTransferConfirmation...\n");
  5707. /**********************status**************************/
  5708. loc = strstr(payload, "status");
  5709. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5710. c = 0;
  5711. while (loc[3+strlen("status")+c] != '\"')
  5712. {
  5713. sstr[c] = loc[3+strlen("status")+c];
  5714. c++;
  5715. }
  5716. sstr[c] = '\0';
  5717. strcpy(statusStr, sstr);
  5718. /**********************data**************************/
  5719. loc = strstr(payload, "data");
  5720. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5721. c = 0;
  5722. while (loc[3+strlen("data")+c] != '\"')
  5723. {
  5724. sstr[c] = loc[3+strlen("data")+c];
  5725. c++;
  5726. }
  5727. sstr[c] = '\0';
  5728. strcpy(dataStr, sstr);
  5729. return result;
  5730. }
  5731. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  5732. {
  5733. mtrace();
  5734. int result = FAIL;
  5735. char message[1000]={0};
  5736. int CompositeScheduleIndex = 0;
  5737. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  5738. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  5739. if(nPeriod == 0)
  5740. {
  5741. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  5742. {
  5743. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  5744. ,MESSAGE_TYPE_CALLRESULT
  5745. ,uuid
  5746. ,payload
  5747. ,connectorIdInt);
  5748. }
  5749. else
  5750. {
  5751. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  5752. ,MESSAGE_TYPE_CALLRESULT
  5753. ,uuid
  5754. ,payload
  5755. ,connectorIdInt
  5756. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5757. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5758. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5759. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  5760. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  5761. }
  5762. }
  5763. else
  5764. {
  5765. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  5766. ,MESSAGE_TYPE_CALLRESULT
  5767. ,uuid
  5768. ,payload
  5769. ,connectorIdInt
  5770. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5771. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5772. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5773. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  5774. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  5775. {
  5776. if (idx_sample == 0)
  5777. {
  5778. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5779. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5780. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5781. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5782. }
  5783. else
  5784. {
  5785. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5786. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5787. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5788. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5789. }
  5790. }
  5791. sprintf(message + strlen(message), "]}}]");
  5792. }
  5793. LWS_Send(message);
  5794. result = TRUE;
  5795. return result;
  5796. }
  5797. int sendGetConfigurationConfirmation(char *uuid)
  5798. {
  5799. mtrace();
  5800. int result = FAIL;
  5801. int MaxKeySupported = 0;
  5802. int sentConfigurationNumber= 0;
  5803. int sentunConfigurationNumber= 0;
  5804. char message[4000]={0};
  5805. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  5806. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  5807. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  5808. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  5809. ,MESSAGE_TYPE_CALLRESULT
  5810. ,uuid );
  5811. //configuration key
  5812. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  5813. {
  5814. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  5815. {
  5816. if (sentConfigurationNumber == 0)
  5817. {
  5818. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5819. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5820. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5821. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5822. }
  5823. else
  5824. {
  5825. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5826. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5827. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5828. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5829. }
  5830. sentConfigurationNumber = sentConfigurationNumber + 1;
  5831. }
  5832. }
  5833. sprintf(message + strlen(message), "]");
  5834. if(UnknownKeynum != 0)
  5835. {
  5836. sprintf(message + strlen(message), ",\"unknownKey\":[");
  5837. //unkown key
  5838. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  5839. {
  5840. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  5841. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  5842. if(sentunConfigurationNumber == 0)
  5843. {
  5844. sprintf(message + strlen(message), "\"%s\""
  5845. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5846. }
  5847. else
  5848. {
  5849. sprintf(message + strlen(message), ",\"%s\""
  5850. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5851. }
  5852. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  5853. }
  5854. sprintf(message + strlen(message), "]");
  5855. }
  5856. sprintf(message + strlen(message), "}]");
  5857. LWS_Send(message);
  5858. return result;
  5859. }
  5860. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  5861. {
  5862. mtrace();
  5863. int result = FAIL;
  5864. char message[400]={0};
  5865. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  5866. if(strcmp(payload,"")==0)
  5867. {
  5868. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5869. }
  5870. else
  5871. {
  5872. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5873. }
  5874. LWS_Send(message);
  5875. result = TRUE;
  5876. return result;
  5877. }
  5878. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  5879. {
  5880. mtrace();
  5881. int result = FAIL;
  5882. char message[80]={0};
  5883. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  5884. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  5885. LWS_Send(message);
  5886. result = TRUE;
  5887. return result;
  5888. }
  5889. int sendRemoteStartConfirmation(char *uuid,char *payload)
  5890. {
  5891. mtrace();
  5892. int result = FAIL;
  5893. char message[80]={0};
  5894. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  5895. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5896. LWS_Send(message);
  5897. result = TRUE;
  5898. return result;
  5899. }
  5900. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5901. {
  5902. mtrace();
  5903. int result = FAIL;
  5904. char message[80]={0};
  5905. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5906. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5907. LWS_Send(message);
  5908. result = TRUE;
  5909. return result;
  5910. }
  5911. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5912. {
  5913. mtrace();
  5914. int result = FAIL;
  5915. char message[80]={0};
  5916. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5917. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  5918. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5919. LWS_Send(message);
  5920. result = TRUE;
  5921. return result;
  5922. }
  5923. int sendResetConfirmation(char *uuid,char *payload)
  5924. {
  5925. mtrace();
  5926. int result = FAIL;
  5927. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  5928. char message[80]={0};
  5929. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  5930. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5931. LWS_Send(message);
  5932. result = TRUE;
  5933. return result;
  5934. }
  5935. int sendSendLocalListConfirmation(char *uuid,char *payload)
  5936. {
  5937. mtrace();
  5938. int result = FAIL;
  5939. char message[500]={0};
  5940. // [ 3, "1571284266109", { "status": "Accepted" } ]
  5941. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5942. LWS_Send(message);
  5943. result = TRUE;
  5944. return result;
  5945. }
  5946. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  5947. {
  5948. mtrace();
  5949. int result = FAIL;
  5950. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  5951. char message[80]={0};
  5952. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  5953. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5954. LWS_Send(message);
  5955. result = TRUE;
  5956. return result;
  5957. }
  5958. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  5959. {
  5960. mtrace();
  5961. int result = FAIL;
  5962. char message[80]={0};
  5963. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  5964. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5965. LWS_Send(message);
  5966. result = TRUE;
  5967. return result;
  5968. }
  5969. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  5970. {
  5971. mtrace();
  5972. int result = FAIL;
  5973. char message[80]={0};
  5974. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5975. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  5976. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5977. LWS_Send(message);
  5978. result = TRUE;
  5979. return result;
  5980. }
  5981. int sendUpdateFirmwareConfirmation(char *uuid)
  5982. {
  5983. mtrace();
  5984. int result = FAIL;
  5985. char message[60]={0};
  5986. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5987. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  5988. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5989. LWS_Send(message);
  5990. result = TRUE;
  5991. return result;
  5992. }
  5993. int sendCertificateSignedConfirmation(char *uuid)
  5994. {
  5995. mtrace();
  5996. int result = PASS;
  5997. char message[4096]={0};
  5998. json_object *CertificateSigned = json_object_new_object();
  5999. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  6000. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  6001. sprintf(message,"[%d,\"%s\",%s]"
  6002. ,MESSAGE_TYPE_CALLRESULT
  6003. ,uuid
  6004. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  6005. json_object_put(CertificateSigned);
  6006. LWS_Send(message);
  6007. return result;
  6008. }
  6009. int sendDeleteCertificateConfirmation(char *uuid)
  6010. {
  6011. mtrace();
  6012. int result = PASS;
  6013. char message[4096]={0};
  6014. json_object *DeleteCertificate = json_object_new_object();
  6015. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  6016. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  6017. sprintf(message,"[%d,\"%s\",%s]"
  6018. ,MESSAGE_TYPE_CALLRESULT
  6019. ,uuid
  6020. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  6021. json_object_put(DeleteCertificate);
  6022. LWS_Send(message);
  6023. return result;
  6024. }
  6025. int sendExtendedTriggerMessageConfirmation(char *uuid)
  6026. {
  6027. mtrace();
  6028. int result = PASS;
  6029. char message[4096]={0};
  6030. json_object *ExtendedTriggerMessage = json_object_new_object();
  6031. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  6032. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  6033. sprintf(message,"[%d,\"%s\",%s]"
  6034. ,MESSAGE_TYPE_CALLRESULT
  6035. ,uuid
  6036. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  6037. json_object_put(ExtendedTriggerMessage);
  6038. LWS_Send(message);
  6039. return result;
  6040. }
  6041. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  6042. {
  6043. mtrace();
  6044. int result = PASS;
  6045. char message[4096]={0};
  6046. json_object *GetInstalledCertificateIds = json_object_new_object();
  6047. json_object *certificateHashDataDatas = json_object_new_array();
  6048. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  6049. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  6050. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  6051. {
  6052. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  6053. {
  6054. json_object *certificateHashData = json_object_new_object();
  6055. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  6056. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  6057. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  6058. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  6059. json_object_array_add(certificateHashDataDatas, certificateHashData);
  6060. }
  6061. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  6062. }
  6063. else
  6064. {
  6065. json_object_put(certificateHashDataDatas);
  6066. }
  6067. sprintf(message,"[%d,\"%s\",%s]"
  6068. ,MESSAGE_TYPE_CALLRESULT
  6069. ,uuid
  6070. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  6071. json_object_put(GetInstalledCertificateIds);
  6072. LWS_Send(message);
  6073. return result;
  6074. }
  6075. int sendGetLogConfirmation(char *uuid)
  6076. {
  6077. mtrace();
  6078. int result = PASS;
  6079. char message[4096]={0};
  6080. json_object *GetLog = json_object_new_object();
  6081. DEBUG_INFO("sendGetLogConfirmation...\n");
  6082. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  6083. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  6084. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  6085. sprintf(message,"[%d,\"%s\",%s]"
  6086. ,MESSAGE_TYPE_CALLRESULT
  6087. ,uuid
  6088. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  6089. json_object_put(GetLog);
  6090. LWS_Send(message);
  6091. return result;
  6092. }
  6093. int sendInstallCertificateConfirmation(char *uuid)
  6094. {
  6095. mtrace();
  6096. int result = PASS;
  6097. char message[4096]={0};
  6098. json_object *InstallCertificate = json_object_new_object();
  6099. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  6100. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  6101. sprintf(message,"[%d,\"%s\",%s]"
  6102. ,MESSAGE_TYPE_CALLRESULT
  6103. ,uuid
  6104. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  6105. json_object_put(InstallCertificate);
  6106. LWS_Send(message);
  6107. return result;
  6108. }
  6109. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  6110. {
  6111. mtrace();
  6112. int result = PASS;
  6113. char message[4096]={0};
  6114. json_object *SignedUpdateFirmware = json_object_new_object();
  6115. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  6116. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  6117. sprintf(message,"[%d,\"%s\",%s]"
  6118. ,MESSAGE_TYPE_CALLRESULT
  6119. ,uuid
  6120. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  6121. json_object_put(SignedUpdateFirmware);
  6122. LWS_Send(message);
  6123. return result;
  6124. }
  6125. int sendUnknownConfirmation(char *uuid)
  6126. {
  6127. mtrace();
  6128. int result = PASS;
  6129. char message[256]={0};
  6130. DEBUG_INFO("sendUnknownConfirmation...\n");
  6131. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  6132. LWS_Send(message);
  6133. return result;
  6134. }
  6135. //==========================================
  6136. // Handle server request routine Start
  6137. //==========================================
  6138. int handleCancelReservationRequest(char *uuid, char *payload)
  6139. {
  6140. mtrace();
  6141. int result = FAIL;
  6142. int gunNO = 0;
  6143. int reservationIdInt = -1;
  6144. char comfirmstr[20];
  6145. DEBUG_INFO("handleCancelReservationRequest...\n");
  6146. json_object *CancelReservation;
  6147. CancelReservation = json_tokener_parse(payload);
  6148. if(!is_error(CancelReservation))
  6149. {
  6150. // Required data
  6151. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  6152. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  6153. }
  6154. json_object_put(CancelReservation);
  6155. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  6156. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6157. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  6158. if(reservationIdInt != -1)
  6159. {
  6160. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6161. //check Transaction active
  6162. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6163. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6164. {
  6165. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  6166. {
  6167. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6168. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6169. if(gunType[2] == GUN_TYPE_CHAdeMO)
  6170. {
  6171. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  6172. }
  6173. else
  6174. {
  6175. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  6176. }
  6177. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6178. goto end;
  6179. }
  6180. }
  6181. for (int index = 0; index < CCS_QUANTITY; index++)
  6182. {
  6183. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  6184. {
  6185. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6186. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6187. if(gunType[2] == GUN_TYPE_CCS)
  6188. {
  6189. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  6190. }
  6191. else
  6192. {
  6193. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  6194. }
  6195. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6196. goto end;
  6197. }
  6198. }
  6199. for (int index = 0; index < GB_QUANTITY; index++)
  6200. {
  6201. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  6202. {
  6203. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6204. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6205. if(gunType[2] == GUN_TYPE_GBT)
  6206. {
  6207. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  6208. }
  6209. else
  6210. {
  6211. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  6212. }
  6213. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6214. goto end;
  6215. }
  6216. }
  6217. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6218. {
  6219. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  6220. {
  6221. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6222. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6223. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  6224. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6225. goto end;
  6226. }
  6227. }
  6228. for (int index = 0; index < AC_QUANTITY; index++)
  6229. {
  6230. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  6231. {
  6232. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6233. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6234. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6235. {
  6236. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  6237. }
  6238. else
  6239. {
  6240. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  6241. }
  6242. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6243. goto end;
  6244. }
  6245. }
  6246. }
  6247. //The reservationId does NOT match the reservationId
  6248. sendCancelReservationConfirmation(uuid, comfirmstr);
  6249. end:
  6250. // Fill in ocpp packet uuid
  6251. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  6252. return result;
  6253. }
  6254. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  6255. {
  6256. mtrace();
  6257. int result = FAIL;
  6258. int gunIndex = 0;
  6259. char typeStr[16]={0};
  6260. char comfirmstr[20];
  6261. int specificId = FALSE;
  6262. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  6263. json_object *ChangeAvailability;
  6264. ChangeAvailability = json_tokener_parse(payload);
  6265. if(!is_error(ChangeAvailability))
  6266. {
  6267. // Required data
  6268. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  6269. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  6270. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  6271. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  6272. }
  6273. json_object_put(ChangeAvailability);
  6274. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6275. {
  6276. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  6277. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  6278. }
  6279. else if(gunIndex == 0)
  6280. {
  6281. for(int i=0; i < gunTotalNumber; i++)
  6282. {
  6283. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  6284. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  6285. }
  6286. }
  6287. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6288. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6289. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  6290. {
  6291. specificId = TRUE;
  6292. }
  6293. if(specificId == FALSE)
  6294. goto end;
  6295. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  6296. {
  6297. //----------------------gunIndex is 0 ------------------------------------------------//
  6298. if(gunIndex == 0)
  6299. {
  6300. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6301. {
  6302. for(int i=0; i < gunTotalNumber; i++)
  6303. {
  6304. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6305. {
  6306. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  6307. {
  6308. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6309. {
  6310. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6311. goto end;
  6312. }
  6313. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6314. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6315. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6316. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6317. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6318. {
  6319. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6320. goto end;
  6321. }
  6322. }
  6323. }//END FOR CHAdeMO_QUANTITY
  6324. for (int index = 0; index < CCS_QUANTITY; index++)
  6325. {
  6326. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  6327. {
  6328. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  6329. {
  6330. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6331. goto end;
  6332. }
  6333. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6334. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6335. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6336. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6337. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6338. {
  6339. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6340. goto end;
  6341. }
  6342. }
  6343. }//END FOR CCS_QUANTITY
  6344. for (int index = 0; index < GB_QUANTITY; index++)
  6345. {
  6346. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  6347. {
  6348. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6349. {
  6350. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6351. goto end;
  6352. }
  6353. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6354. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6355. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6356. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6357. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6358. {
  6359. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6360. goto end;
  6361. }
  6362. }
  6363. }// END FOR GB_QUANTITY
  6364. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6365. {
  6366. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  6367. {
  6368. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6369. {
  6370. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6371. goto end;
  6372. }
  6373. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  6374. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  6375. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  6376. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  6377. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6378. {
  6379. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6380. goto end;
  6381. }
  6382. }
  6383. }// END FOR GENERAL_GUN_QUANTITY
  6384. for (int index = 0; index < AC_QUANTITY; index++)
  6385. {
  6386. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  6387. {
  6388. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6389. {
  6390. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6391. goto end;
  6392. }
  6393. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6394. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6395. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6396. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6397. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6398. {
  6399. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6400. goto end;
  6401. }
  6402. }
  6403. }//END FOR AC_QUANTITY
  6404. }// END FOR gunTotalNumber
  6405. }
  6406. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6407. {
  6408. for(int i=0; i < gunTotalNumber; i++)
  6409. {
  6410. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6411. {
  6412. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6413. goto end;
  6414. }
  6415. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6416. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  6417. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  6418. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  6419. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6420. {
  6421. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6422. goto end;
  6423. }
  6424. }
  6425. }
  6426. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6427. goto end;
  6428. }
  6429. //----------------------gunIndex is not 0 ------------------------------------------------//
  6430. //check Transaction active
  6431. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6432. {
  6433. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  6434. {
  6435. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  6436. {
  6437. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6438. goto end;
  6439. }
  6440. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6441. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6442. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6443. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6444. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6445. {
  6446. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6447. goto end;
  6448. }
  6449. else
  6450. {
  6451. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  6452. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6453. goto end;
  6454. }
  6455. }
  6456. }//END FOR CHAdeMO_QUANTITY
  6457. for (int index = 0; index < CCS_QUANTITY; index++)
  6458. {
  6459. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  6460. {
  6461. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  6462. {
  6463. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6464. goto end;
  6465. }
  6466. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6467. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6468. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6469. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6470. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6471. {
  6472. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6473. goto end;
  6474. }
  6475. else
  6476. {
  6477. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  6478. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6479. goto end;
  6480. }
  6481. }
  6482. }//END FOR CCS_QUANTITY
  6483. for (int index = 0; index < GB_QUANTITY; index++)
  6484. {
  6485. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  6486. {
  6487. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6488. {
  6489. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6490. goto end;
  6491. }
  6492. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6493. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6494. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6495. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6496. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6497. {
  6498. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6499. goto end;
  6500. }
  6501. else
  6502. {
  6503. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  6504. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6505. goto end;
  6506. }
  6507. }
  6508. }// END FOR GB_QUANTITY
  6509. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6510. {
  6511. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  6512. {
  6513. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6514. {
  6515. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6516. goto end;
  6517. }
  6518. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  6519. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  6520. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  6521. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  6522. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6523. {
  6524. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6525. goto end;
  6526. }
  6527. else
  6528. {
  6529. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  6530. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6531. goto end;
  6532. }
  6533. }
  6534. }// END FOR GENERAL_GUN_QUANTITY
  6535. for (int index = 0; index < AC_QUANTITY; index++)
  6536. {
  6537. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  6538. {
  6539. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6540. {
  6541. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6542. goto end;
  6543. }
  6544. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6545. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6546. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6547. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6548. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6549. {
  6550. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6551. goto end;
  6552. }
  6553. else
  6554. {
  6555. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  6556. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6557. goto end;
  6558. }
  6559. }
  6560. }//END FOR AC_QUANTITY
  6561. }//END FOR AvailabilityTypeStr[Inoperative]
  6562. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  6563. {
  6564. //----------------------gunIndex is 0 ------------------------------------------------//
  6565. if(gunIndex == 0)
  6566. {
  6567. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6568. {
  6569. for(int i=0; i < gunTotalNumber; i++)
  6570. {
  6571. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6572. {
  6573. 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
  6574. {
  6575. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6576. goto end;
  6577. }
  6578. }//END FOR CHAdeMO_QUANTITY
  6579. for (int index = 0; index < CCS_QUANTITY; index++)
  6580. {
  6581. 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
  6582. {
  6583. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6584. goto end;
  6585. }
  6586. }//END FOR CCS_QUANTITY
  6587. for (int index = 0; index < GB_QUANTITY; index++)
  6588. {
  6589. 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
  6590. {
  6591. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6592. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6593. goto end;
  6594. }
  6595. }// END FOR GB_QUANTITY
  6596. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6597. {
  6598. 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
  6599. {
  6600. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6601. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6602. goto end;
  6603. }
  6604. }// END FOR GENERAL_GUN_QUANTITY
  6605. for (int index = 0; index < AC_QUANTITY; index++)
  6606. {
  6607. 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
  6608. {
  6609. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6610. goto end;
  6611. }
  6612. }//END FOR CHAdeMO_QUANTITY
  6613. }// END FOR gunTotalNumber
  6614. }
  6615. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6616. {
  6617. for(int i=0; i < gunTotalNumber; i++)
  6618. {
  6619. for (int index = 0; index < AC_QUANTITY; index++)
  6620. {
  6621. 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
  6622. {
  6623. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6624. goto end;
  6625. }
  6626. }//END FOR CHAdeMO_QUANTITY
  6627. } // END FOR gunTotalNumber
  6628. }
  6629. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6630. goto end;
  6631. }
  6632. //----------------------gunIndex is not 0 ------------------------------------------------//
  6633. //check Transaction active
  6634. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6635. {
  6636. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6637. {
  6638. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6639. goto end;
  6640. }
  6641. }//END FOR CHAdeMO_QUANTITY
  6642. for (int index = 0; index < CCS_QUANTITY; index++)
  6643. {
  6644. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6645. {
  6646. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6647. goto end;
  6648. }
  6649. }//END FOR CCS_QUANTITY
  6650. for (int index = 0; index < GB_QUANTITY; index++)
  6651. {
  6652. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6653. {
  6654. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6655. goto end;
  6656. }
  6657. }// END FOR GB_QUANTITY
  6658. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6659. {
  6660. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6661. {
  6662. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6663. goto end;
  6664. }
  6665. }// END FOR GENERAL_GUN_QUANTITY
  6666. for (int index = 0; index < AC_QUANTITY; index++)
  6667. {
  6668. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6669. {
  6670. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6671. goto end;
  6672. }
  6673. }//END FOR AC_QUANTITY
  6674. }//END FOR AvailabilityTypeStr[Operative]
  6675. end:
  6676. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6677. {
  6678. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  6679. }
  6680. else
  6681. {
  6682. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  6683. }
  6684. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6685. {
  6686. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6687. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6688. }
  6689. else if(gunIndex == 0)
  6690. {
  6691. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6692. {
  6693. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  6694. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  6695. }
  6696. }
  6697. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  6698. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6699. return result;
  6700. }
  6701. int handleChangeConfigurationRequest(char *uuid, char *payload)
  6702. {
  6703. mtrace();
  6704. int result = FAIL;
  6705. char keystr[40]={0};
  6706. char valuestr[256]={0};
  6707. char comfirmstr[20]={0};
  6708. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  6709. json_object *ChangeConfiguration;
  6710. ChangeConfiguration = json_tokener_parse(payload);
  6711. if(!is_error(ChangeConfiguration))
  6712. {
  6713. // Required data
  6714. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  6715. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  6716. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  6717. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  6718. }
  6719. json_object_put(ChangeConfiguration);
  6720. if((uuid==NULL) || (payload ==NULL) )
  6721. {
  6722. DEBUG_ERROR("Payload is null\n");
  6723. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6724. }
  6725. else
  6726. {
  6727. int status = setKeyValue(keystr, valuestr);
  6728. switch(status)
  6729. {
  6730. case ConfigurationStatus_Accepted:
  6731. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  6732. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  6733. StoreConfigurationTable();
  6734. break;
  6735. case RebootRequired:
  6736. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  6737. StoreConfigurationTable();
  6738. break;
  6739. case NotSupported:
  6740. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  6741. break;
  6742. case ConfigurationStatus_Rejected:
  6743. default:
  6744. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6745. break;
  6746. }
  6747. }
  6748. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  6749. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  6750. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6751. {
  6752. ChageWebSocketPingInterval(atoi(valuestr));
  6753. }
  6754. if((strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6755. {
  6756. SetOcppConnStatus(FALSE);
  6757. }
  6758. return result;
  6759. }
  6760. int handleClearCacheRequest(char *uuid, char *payload)
  6761. {
  6762. mtrace();
  6763. int result = FAIL;
  6764. char comfirmstr[20];
  6765. char rmFileCmd[100]={0};
  6766. struct stat stats;
  6767. DEBUG_INFO("handleClearCacheRequest...\n");
  6768. stat("/Storage/OCPP", &stats);
  6769. // Check for directory existence
  6770. if (S_ISDIR(stats.st_mode) == 1)
  6771. {}
  6772. else
  6773. {
  6774. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  6775. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  6776. system(rmFileCmd);
  6777. }
  6778. if(OCPP_cleanLocalCache())
  6779. {
  6780. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  6781. }
  6782. else
  6783. {
  6784. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  6785. }
  6786. sendClearCacheConfirmation(uuid, comfirmstr);
  6787. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6788. return result;
  6789. }
  6790. int handleClearChargingProfileRequest(char *uuid, char *payload)
  6791. {
  6792. mtrace();
  6793. int result = FAIL;
  6794. int resultRename;
  6795. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  6796. char chargingProfilePurposeStr[26]={0};
  6797. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  6798. char tempchargingProfilePurposeStr[26]={0};
  6799. char str[100]={0};
  6800. char fname[200]={0};
  6801. char comfirmstr[20]={0};
  6802. char word[1600]={0};
  6803. int clearflag = FALSE;
  6804. int chargingProfileIdIsNULL = FALSE;
  6805. int connectorIsNULL = FALSE;
  6806. int chargingProfilePurposeIsNULL = FALSE;
  6807. int stackLevelIsNULL = FALSE;
  6808. //int GotoEnd = FALSE;
  6809. FILE *fptr1, *fptr2;
  6810. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  6811. int n_chargingProfile=0;
  6812. int isEmptyFile = FALSE;
  6813. char sLineWord[1600]={0};
  6814. char chargingProfiles[10][100]={0};
  6815. int ChargeProfileCount = 0;
  6816. int ch;
  6817. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  6818. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  6819. json_object *ClearChargingProfile;
  6820. ClearChargingProfile = json_tokener_parse(payload);
  6821. if(!is_error(ClearChargingProfile))
  6822. {
  6823. // Optional data
  6824. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  6825. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  6826. else
  6827. chargingProfileIdIsNULL = TRUE;
  6828. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  6829. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  6830. else
  6831. connectorIsNULL = TRUE;
  6832. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  6833. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  6834. else
  6835. chargingProfilePurposeIsNULL = TRUE;
  6836. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  6837. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  6838. else
  6839. stackLevelIsNULL = TRUE;
  6840. }
  6841. json_object_put(ClearChargingProfile);
  6842. if(connectorIsNULL == FALSE)
  6843. {
  6844. switch(connectorIdInt)
  6845. {
  6846. case 0:
  6847. if(chargingProfilePurposeIsNULL == TRUE)
  6848. {
  6849. int l = 0;
  6850. strcpy(fname, ChargePointMaxProfile_JSON);
  6851. if((access(fname,F_OK))!=-1)
  6852. {
  6853. strcpy(chargingProfiles[l], fname);
  6854. l = l + 1;
  6855. }
  6856. strcpy(fname, TxDefaultProfile_0_JSON);
  6857. if((access(fname,F_OK))!=-1)
  6858. {
  6859. strcpy(chargingProfiles[l], fname);
  6860. l = l + 1;
  6861. }
  6862. ChargeProfileCount = l;
  6863. }
  6864. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  6865. {
  6866. strcpy(fname, ChargePointMaxProfile_JSON);
  6867. if((access(fname,F_OK))!=-1)
  6868. {
  6869. strcpy(chargingProfiles[0], fname);
  6870. ChargeProfileCount = 1;
  6871. }
  6872. }
  6873. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6874. {
  6875. strcpy(fname, TxDefaultProfile_0_JSON);
  6876. if((access(fname,F_OK))!=-1)
  6877. {
  6878. strcpy(chargingProfiles[0], fname);
  6879. ChargeProfileCount = 1;
  6880. }
  6881. }
  6882. break;
  6883. default:
  6884. if(chargingProfilePurposeIsNULL == TRUE)
  6885. {
  6886. int m = 0;
  6887. memset(fname, 0, ARRAY_SIZE(fname));
  6888. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6889. if((access(fname,F_OK))!=-1)
  6890. {
  6891. strcpy(chargingProfiles[m], fname);
  6892. m = m + 1;
  6893. }
  6894. memset(fname, 0, ARRAY_SIZE(fname));
  6895. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6896. if((access(fname,F_OK))!=-1)
  6897. {
  6898. strcpy(chargingProfiles[m], fname);
  6899. m = m + 1;
  6900. }
  6901. ChargeProfileCount = m;
  6902. }
  6903. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6904. {
  6905. //strcpy(fname, TxDefaultProfile_1_JSON);
  6906. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6907. if((access(fname,F_OK))!=-1)
  6908. {
  6909. strcpy(chargingProfiles[0], fname);
  6910. ChargeProfileCount = 1;
  6911. }
  6912. }
  6913. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  6914. {
  6915. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6916. if((access(fname,F_OK))!=-1)
  6917. {
  6918. strcpy(chargingProfiles[0], fname);
  6919. ChargeProfileCount = 1;
  6920. }
  6921. //strcpy(fname, TxProfile_1_JSON);
  6922. }
  6923. //strcpy(fname, ChargePointMaxProfile_JSON );
  6924. break;
  6925. }
  6926. }
  6927. else // Check all Charging Profiles
  6928. {
  6929. int i = 0;
  6930. char fnametemp[200]={0};
  6931. ChargeProfileCount = 0;
  6932. //Check ChargePointMaxProfile.json exit
  6933. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  6934. {
  6935. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  6936. i = i + 1;
  6937. }
  6938. //Check TxDefaultProfile_0.json exit
  6939. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  6940. {
  6941. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  6942. i = i + 1;
  6943. }
  6944. //Check TxDefaultProfile_%d.json
  6945. for(int j=1; j <= gunTotalNumber; j++)
  6946. {
  6947. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6948. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  6949. if((access(fnametemp,F_OK))!=-1)
  6950. {
  6951. strcpy(chargingProfiles[i], fnametemp);
  6952. i = i + 1;
  6953. }
  6954. }
  6955. //Check TxProfile_%d.json
  6956. for(int j=1; j <= gunTotalNumber; j++)
  6957. {
  6958. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6959. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  6960. if((access(fnametemp,F_OK))!=-1)
  6961. {
  6962. strcpy(chargingProfiles[i], fnametemp);
  6963. i = i + 1;
  6964. }
  6965. }
  6966. ChargeProfileCount = i;
  6967. }// End connectorIsNULL is TRUE
  6968. if(ChargeProfileCount == 0)
  6969. {
  6970. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6971. goto end;
  6972. }
  6973. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  6974. {
  6975. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6976. goto end;
  6977. }
  6978. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  6979. {
  6980. memset(str, 0, ARRAY_SIZE(str));
  6981. // clear temp file
  6982. sprintf(str,"rm -f %s",temp);
  6983. system(str);
  6984. for(int k=0; k < ChargeProfileCount; k++)
  6985. {
  6986. memset(str, 0, ARRAY_SIZE(str));
  6987. //clear file in C
  6988. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6989. system(str);
  6990. }
  6991. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6992. goto end;
  6993. }
  6994. else if(connectorIsNULL == TRUE)
  6995. {
  6996. for(int k=0; k < ChargeProfileCount; k++)
  6997. {
  6998. fptr1 = fopen(chargingProfiles[k], "r");
  6999. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  7000. //Check Charging Profile Count
  7001. while(fscanf(fptr1, "%s", word) != EOF)
  7002. {
  7003. //DEBUG_INFO("word=%s\n",word);
  7004. if(strstr(word, "chargingProfileId")!= NULL)
  7005. {
  7006. //DEBUG_INFO("test chargingProfileId \n");
  7007. n_chargingProfile = n_chargingProfile + 1;
  7008. //DEBUG_INFO("chargingProfileId Found\n");
  7009. }
  7010. }
  7011. rewind(fptr1);
  7012. //search Charging Profile Element
  7013. //int i= 0;
  7014. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7015. {
  7016. json_object *tmpProfilee;
  7017. tmpProfilee = json_tokener_parse(sLineWord);
  7018. if(!is_error(tmpProfilee))
  7019. {
  7020. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7021. {
  7022. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7023. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7024. }
  7025. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7026. {
  7027. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7028. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7029. }
  7030. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7031. {
  7032. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7033. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7034. }
  7035. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7036. {
  7037. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7038. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7039. }
  7040. }
  7041. json_object_put(tmpProfilee);
  7042. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7043. {
  7044. //------- not write to fptr2-------//
  7045. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7046. //clearflag = TRUE;
  7047. }
  7048. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7049. {
  7050. //------- not write to fptr2-------//
  7051. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7052. }
  7053. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7054. {
  7055. //------- not write to fptr2-------//
  7056. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7057. }
  7058. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  7059. {
  7060. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7061. }
  7062. else
  7063. {
  7064. fprintf(fptr2, sLineWord);//writing data into file
  7065. }
  7066. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7067. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7068. if(clearflag == TRUE)
  7069. {
  7070. fclose(fptr1);
  7071. fclose(fptr2);
  7072. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7073. system(str);
  7074. // clear temp file
  7075. sprintf(str,"rm -f %s",temp);
  7076. system(str);
  7077. }
  7078. else
  7079. {
  7080. fclose(fptr1);
  7081. fclose(fptr2);
  7082. memset(str, 0, ARRAY_SIZE(str));
  7083. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7084. system(str);
  7085. resultRename = rename(temp, chargingProfiles[k]);
  7086. if(resultRename == 0)
  7087. {
  7088. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  7089. }
  7090. else
  7091. {
  7092. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  7093. }
  7094. if(comfirmstr[0]== 0)
  7095. {
  7096. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7097. }
  7098. //Check chargingProfile is empty file
  7099. /*------ Read the file ----------------*/
  7100. fptr1=fopen(chargingProfiles[k],"r");
  7101. ch=fgetc(fptr1);
  7102. rewind(fptr1);
  7103. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7104. if(ch!=EOF)
  7105. {
  7106. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7107. {
  7108. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7109. if(sLineWord[0]=='\0')
  7110. {
  7111. isEmptyFile = TRUE;
  7112. break;
  7113. }
  7114. else
  7115. {
  7116. isEmptyFile = FALSE;
  7117. break;
  7118. }
  7119. }
  7120. }
  7121. else
  7122. isEmptyFile = TRUE;
  7123. fclose(fptr1);
  7124. if(isEmptyFile == TRUE)
  7125. {
  7126. memset(str, 0, ARRAY_SIZE(str));
  7127. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7128. system(str);
  7129. }
  7130. }
  7131. }// End of while(int k=0; k < ChargePointCount; k++)
  7132. }
  7133. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  7134. {
  7135. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  7136. for(int k=0; k < ChargeProfileCount; k++)
  7137. {
  7138. fptr1 = fopen(chargingProfiles[k], "r");
  7139. fptr2 = fopen(temp, "w+");
  7140. //Check Charging Profile Count
  7141. while(fscanf(fptr1, "%s", word) != EOF)
  7142. {
  7143. //DEBUG_INFO("word=%s\n",word);
  7144. if(strstr(word, "chargingProfileId")!= NULL)
  7145. {
  7146. n_chargingProfile = n_chargingProfile + 1;
  7147. }
  7148. }
  7149. rewind(fptr1);
  7150. //search Charging Profile Element
  7151. //int i= 0;
  7152. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7153. {
  7154. json_object *tmpProfilee;
  7155. tmpProfilee = json_tokener_parse(sLineWord);
  7156. if(!is_error(tmpProfilee))
  7157. {
  7158. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7159. {
  7160. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7161. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7162. }
  7163. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7164. {
  7165. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7166. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7167. }
  7168. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7169. {
  7170. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7171. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7172. }
  7173. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7174. {
  7175. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7176. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7177. }
  7178. }
  7179. json_object_put(tmpProfilee);
  7180. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7181. {
  7182. //------- not write to fptr2-------//
  7183. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7184. //clearflag = TRUE;
  7185. }
  7186. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7187. {
  7188. //------- not write to fptr2-------//
  7189. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7190. }
  7191. else if(stackLevelIsNULL == TRUE)
  7192. {
  7193. //Clear Whole File
  7194. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7195. clearflag = TRUE;
  7196. break;
  7197. }
  7198. else
  7199. {
  7200. fprintf(fptr2, sLineWord);//writing data into file
  7201. }
  7202. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7203. }
  7204. if(clearflag == TRUE)
  7205. {
  7206. fclose(fptr1);
  7207. fclose(fptr2);
  7208. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7209. system(str);
  7210. // clear temp file
  7211. sprintf(str,"rm -f %s",temp);
  7212. system(str);
  7213. }
  7214. else
  7215. {
  7216. fclose(fptr1);
  7217. fclose(fptr2);
  7218. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7219. system(str);
  7220. resultRename = rename(temp, chargingProfiles[k]);
  7221. if(resultRename == 0)
  7222. {
  7223. DEBUG_INFO("File ChargingProfile renamed successfully");
  7224. }
  7225. else
  7226. {
  7227. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  7228. }
  7229. if(comfirmstr[0]== 0)
  7230. {
  7231. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7232. }
  7233. //Check chargingProfile is empty file
  7234. /*------ Read the file ----------------*/
  7235. fptr1=fopen(chargingProfiles[k],"r");
  7236. ch=fgetc(fptr1);
  7237. rewind(fptr1);
  7238. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7239. if(ch!=EOF)
  7240. {
  7241. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7242. {
  7243. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7244. if(sLineWord[0]=='\0')
  7245. {
  7246. isEmptyFile = TRUE;
  7247. break;
  7248. }
  7249. else
  7250. {
  7251. isEmptyFile = FALSE;
  7252. break;
  7253. }
  7254. }
  7255. }
  7256. else
  7257. isEmptyFile = TRUE;
  7258. fclose(fptr1);
  7259. if(isEmptyFile == TRUE)
  7260. {
  7261. memset(str, 0, ARRAY_SIZE(str));
  7262. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7263. system(str);
  7264. }
  7265. /*------- End of reading ---------------*/
  7266. }
  7267. } // while(int k=0; k < ChargeProfileCount; k++)
  7268. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  7269. end:
  7270. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  7271. {
  7272. if(connectorIdInt == 0)
  7273. {
  7274. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  7275. {
  7276. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  7277. }
  7278. }
  7279. else
  7280. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  7281. }
  7282. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  7283. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7284. return result;
  7285. }
  7286. void createFirmwareVersionByDataTransfer(void)
  7287. {
  7288. json_object *FirmwareDataTransfer = json_object_new_object();
  7289. // AC & DC model
  7290. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  7291. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  7292. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  7293. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  7294. // DC model
  7295. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O')
  7296. {
  7297. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  7298. {
  7299. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7300. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7301. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  7302. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  7303. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7304. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7305. }
  7306. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  7307. ((gunType[1] != GUN_TYPE_UNKNOWN) || (gunType[2] != GUN_TYPE_UNKNOWN) || (gunType[3] != GUN_TYPE_UNKNOWN)))
  7308. {
  7309. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  7310. }
  7311. }
  7312. else
  7313. {
  7314. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7315. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7316. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7317. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7318. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  7319. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  7320. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  7321. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  7322. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  7323. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  7324. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  7325. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  7326. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  7327. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  7328. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  7329. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  7330. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  7331. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  7332. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  7333. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  7334. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  7335. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  7336. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  7337. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  7338. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  7339. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  7340. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  7341. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  7342. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  7343. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  7344. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  7345. }
  7346. // 4G model
  7347. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  7348. {
  7349. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  7350. }
  7351. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  7352. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  7353. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  7354. json_object_put(FirmwareDataTransfer);
  7355. }
  7356. int handleDataTransferRequest(char *uuid, char *payload)
  7357. {
  7358. mtrace();
  7359. json_object *response = json_object_new_object();
  7360. int result = FAIL;
  7361. char tempvendorId[255]={0};
  7362. char tempmessageId[50]={0};
  7363. char tempdata[512]={0};
  7364. char message[2048]={0};
  7365. DEBUG_INFO("handleDataTransferRequest...\n");
  7366. if((uuid != NULL) && (payload != NULL))
  7367. {
  7368. json_object *DataTransfer;
  7369. DataTransfer = json_tokener_parse(payload);
  7370. if(!is_error(DataTransfer))
  7371. {
  7372. // Required data
  7373. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  7374. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  7375. // Optional data
  7376. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  7377. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  7378. if(json_object_object_get(DataTransfer, "data") != NULL)
  7379. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  7380. result = PASS;
  7381. }
  7382. json_object_put(DataTransfer);
  7383. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  7384. {
  7385. // Send all moudle firmware version on EVSE
  7386. createFirmwareVersionByDataTransfer();
  7387. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7388. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  7389. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7390. json_object_put(response);
  7391. }
  7392. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  7393. {
  7394. system("/usr/bin/run_tmate_restart.sh &");
  7395. }
  7396. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  7397. {
  7398. json_object *data;
  7399. data = json_tokener_parse(tempdata);
  7400. if(!is_error(data))
  7401. {
  7402. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  7403. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  7404. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  7405. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  7406. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  7407. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  7408. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  7409. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  7410. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  7411. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  7412. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7413. }
  7414. else
  7415. {
  7416. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7417. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7418. }
  7419. json_object_put(data);
  7420. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7421. json_object_put(response);
  7422. }
  7423. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  7424. {
  7425. json_object *data;
  7426. data = json_tokener_parse(tempdata);
  7427. if(!is_error(data))
  7428. {
  7429. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  7430. if(json_object_object_get(data, "idToken") != NULL)
  7431. {
  7432. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  7433. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  7434. }
  7435. if(json_object_object_get(data, "price") != NULL)
  7436. {
  7437. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  7438. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  7439. }
  7440. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7441. }
  7442. else
  7443. {
  7444. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7445. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7446. }
  7447. json_object_put(data);
  7448. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7449. json_object_put(response);
  7450. }
  7451. else if(strstr(tempmessageId, "RunningCost") != NULL)
  7452. {
  7453. json_object *data;
  7454. data = json_tokener_parse(tempdata);
  7455. if(!is_error(data))
  7456. {
  7457. if(json_object_object_get(data, "txId") != NULL)
  7458. {
  7459. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7460. for(int idx = 0;idx<gunTotalNumber;idx++)
  7461. {
  7462. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7463. {
  7464. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  7465. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7466. if(json_object_object_get(data, "description") != NULL)
  7467. {
  7468. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7469. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7470. }
  7471. }
  7472. }
  7473. }
  7474. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7475. }
  7476. else
  7477. {
  7478. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7479. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7480. }
  7481. json_object_put(data);
  7482. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7483. json_object_put(response);
  7484. }
  7485. else if(strstr(tempmessageId, "FinalCost") != NULL)
  7486. {
  7487. json_object *data;
  7488. data = json_tokener_parse(tempdata);
  7489. if(!is_error(data))
  7490. {
  7491. if(json_object_object_get(data, "txId") != NULL)
  7492. {
  7493. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7494. for(int idx = 0;idx<gunTotalNumber;idx++)
  7495. {
  7496. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7497. {
  7498. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  7499. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7500. if(json_object_object_get(data, "description") != NULL)
  7501. {
  7502. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7503. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7504. }
  7505. }
  7506. }
  7507. }
  7508. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7509. }
  7510. else
  7511. {
  7512. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7513. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7514. }
  7515. json_object_put(data);
  7516. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7517. json_object_put(response);
  7518. }
  7519. else
  7520. {
  7521. // Can not find valid message id
  7522. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  7523. }
  7524. }
  7525. else
  7526. {
  7527. // Payload is null
  7528. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  7529. }
  7530. LWS_Send(message);
  7531. return result;
  7532. }
  7533. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  7534. {
  7535. mtrace();
  7536. int result = FAIL;
  7537. int connectorIdInt, durationInt;
  7538. char chargingRateUnitStr[4]={0};
  7539. char comfirmstr[20];
  7540. int confirmPeriods = 0;
  7541. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  7542. json_object *GetCompositeSchedule;
  7543. GetCompositeSchedule = json_tokener_parse(payload);
  7544. if(!is_error(GetCompositeSchedule))
  7545. {
  7546. // Required data
  7547. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  7548. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  7549. else
  7550. connectorIdInt = -1;
  7551. if(json_object_object_get(GetCompositeSchedule, "duration"))
  7552. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  7553. else
  7554. durationInt = 86400;
  7555. // Optional data
  7556. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  7557. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  7558. }
  7559. json_object_put(GetCompositeSchedule);
  7560. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  7561. if((connectorIdInt == 0) ||
  7562. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  7563. {
  7564. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  7565. struct StructChargingProfile tmpProfile[1];
  7566. if(strstr(chargingRateUnitStr, "W") != NULL)
  7567. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  7568. else
  7569. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  7570. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7571. {
  7572. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7573. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7574. }
  7575. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  7576. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  7577. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  7578. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7579. {
  7580. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7581. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7582. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  7583. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  7584. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  7585. {
  7586. confirmPeriods = idx;
  7587. break;
  7588. }
  7589. }
  7590. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  7591. {
  7592. confirmPeriods += 1;
  7593. }
  7594. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  7595. }
  7596. else
  7597. {
  7598. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  7599. }
  7600. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  7601. return result;
  7602. }
  7603. int handleGetConfigurationRequest(char *uuid, char *payload)
  7604. {
  7605. mtrace();
  7606. int result = FAIL;
  7607. int MaxKeySupported = 0;
  7608. int n_keys = 0;
  7609. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  7610. DEBUG_INFO("handleGetConfigurationRequest...\n");
  7611. json_object *GetConfiguration;
  7612. GetConfiguration = json_tokener_parse(payload);
  7613. if(!is_error(GetConfiguration))
  7614. {
  7615. // Optional data
  7616. if(json_object_object_get(GetConfiguration, "key") != NULL)
  7617. {
  7618. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  7619. {
  7620. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  7621. n_keys = idx + 1;
  7622. }
  7623. }
  7624. }
  7625. json_object_put(GetConfiguration);
  7626. UnknownKeynum = 0;
  7627. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  7628. MaxKeySupported = GetConfigurationMaxKeysNUM;
  7629. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  7630. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  7631. if(n_keys != 0)
  7632. {
  7633. for(int i=0;i<n_keys;i++)
  7634. {
  7635. getKeyValue(requestKey[i]);
  7636. }
  7637. }
  7638. else
  7639. {
  7640. DEBUG_INFO("There is no key in Message, get all configuration\n");
  7641. getKeyValue("");
  7642. }
  7643. processUnkownKey();
  7644. sendGetConfigurationConfirmation(uuid);
  7645. return result;
  7646. }
  7647. static char fnamePlusPath[100]={0};
  7648. static char fnamePWithNoPath[60]={0};
  7649. void checkUploadLog(void)
  7650. {
  7651. FILE *fp;
  7652. /* Open the command for reading. */
  7653. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  7654. if (fp == NULL) {
  7655. printf("Failed to run command\n" );
  7656. exit(1);
  7657. }
  7658. int ftppathlen = 0;
  7659. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  7660. int i = 0;
  7661. /* Read the output a line at a time - output it. */
  7662. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  7663. if(i==0)
  7664. {
  7665. ftppathlen = strlen(fnamePlusPath);
  7666. printf("%s\n", fnamePlusPath);
  7667. fnamePlusPath[ftppathlen]='\0';
  7668. break;
  7669. }
  7670. i= i+1;
  7671. }
  7672. /* close */
  7673. pclose(fp);
  7674. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  7675. {
  7676. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  7677. {
  7678. fnamePlusPath[k]='\0';
  7679. }
  7680. }
  7681. i=1;
  7682. //char fname[60]={0};
  7683. while(i < ftppathlen)
  7684. {
  7685. int len=ftppathlen-i;
  7686. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  7687. {
  7688. printf("compare '/' all right\n");
  7689. break;
  7690. }
  7691. i=i+1;
  7692. }
  7693. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  7694. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  7695. fnamePWithNoPath[i+1] = '\0';
  7696. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  7697. {
  7698. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  7699. {
  7700. fnamePWithNoPath[j]='\0';
  7701. }
  7702. }
  7703. FILE* fp1 = fopen(fnamePlusPath, "r");
  7704. if (fp1)
  7705. {
  7706. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  7707. // file exists
  7708. fclose(fp1);
  7709. }
  7710. else
  7711. {
  7712. // file doesn't exist
  7713. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  7714. }
  7715. }
  7716. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  7717. {
  7718. mtrace();
  7719. int result = FAIL;
  7720. time_t CurrentTime;
  7721. struct tm *tm;
  7722. pthread_t th_Status;
  7723. CurrentTime = time(NULL);
  7724. tm = localtime(&CurrentTime);
  7725. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  7726. 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);
  7727. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  7728. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  7729. return result;
  7730. }
  7731. void* GetDiagnosticsProcess(void* data)
  7732. {
  7733. pthread_detach(pthread_self());
  7734. mtrace();
  7735. int retriesInt=0, retryIntervalInt=0;
  7736. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  7737. 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};
  7738. int port=0;
  7739. int isSuccess = FALSE;
  7740. char ftpbuf[200]={0};
  7741. char cmdBuf[2048];
  7742. struct tm *tmNow;
  7743. time_t CurrentTime;
  7744. struct tm tmStart;
  7745. struct tm tmStop;
  7746. CurrentTime = time(NULL);
  7747. tmNow=localtime(&CurrentTime);
  7748. uint16_t targetYear, targetMonth;
  7749. json_object *GetDiagnostics;
  7750. DEBUG_INFO("GetDiagnosticsProcess...\n");
  7751. GetDiagnostics = json_tokener_parse(data);
  7752. if(!is_error(GetDiagnostics))
  7753. {
  7754. // Required data
  7755. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  7756. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  7757. // Optional data
  7758. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  7759. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  7760. else
  7761. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  7762. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  7763. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  7764. else
  7765. retryIntervalInt = 30;
  7766. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  7767. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  7768. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  7769. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  7770. }
  7771. json_object_put(GetDiagnostics);
  7772. // Pack log to compress file
  7773. 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) &&
  7774. (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))
  7775. {
  7776. // Pack system log
  7777. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  7778. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  7779. targetYear = tmStart.tm_year;
  7780. targetMonth = tmStart.tm_mon;
  7781. do
  7782. {
  7783. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7784. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7785. if(targetMonth+1>=13)
  7786. {
  7787. targetYear += 1;
  7788. targetMonth = 1;
  7789. }
  7790. else
  7791. {
  7792. targetMonth += 1;
  7793. }
  7794. }while((targetYear < (tmNow->tm_year+1900)) ||
  7795. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  7796. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  7797. system(cmdBuf);
  7798. // Pack charging & event log
  7799. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  7800. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  7801. targetYear = tmStart.tm_year;
  7802. targetMonth = tmStart.tm_mon;
  7803. do
  7804. {
  7805. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7806. if(targetMonth+1>=13)
  7807. {
  7808. targetYear += 1;
  7809. targetMonth = 1;
  7810. }
  7811. else
  7812. {
  7813. targetMonth += 1;
  7814. }
  7815. }while((targetYear < (tmNow->tm_year+1900)) ||
  7816. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  7817. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  7818. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  7819. system(cmdBuf);
  7820. // Combine log file
  7821. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  7822. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  7823. }
  7824. else
  7825. {
  7826. system("exec /root/logPackTools 'log' 6");
  7827. }
  7828. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  7829. system(cmdBuf);
  7830. checkUploadLog();
  7831. //****************location*******************/
  7832. if(strcmp(locationstr,"")==0)
  7833. {
  7834. DEBUG_INFO("location is <Empty>!\n");
  7835. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7836. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7837. goto end;
  7838. }
  7839. memset(protocol, 0, ARRAY_SIZE(protocol));
  7840. memset(user, 0, ARRAY_SIZE(user) );
  7841. memset(password, 0, ARRAY_SIZE(password));
  7842. memset(host, 0, ARRAY_SIZE(host));
  7843. memset(path, 0, ARRAY_SIZE(path));
  7844. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  7845. memset(host1, 0, ARRAY_SIZE(host1));
  7846. memset(path1, 0, ARRAY_SIZE(path1));
  7847. /*location: ftp://user:password@host:port/path*/
  7848. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  7849. if((access(fnamePlusPath,F_OK))!=-1)
  7850. {
  7851. DEBUG_INFO("fnamePlusPath exist.\n");
  7852. }
  7853. else
  7854. {
  7855. DEBUG_INFO("fnamePlusPath not exist!\n");
  7856. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7857. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7858. goto end;
  7859. }
  7860. if(strchr(locationstr,'@')==NULL)
  7861. {
  7862. sscanf(locationstr,
  7863. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  7864. protocol, host, &port, path);
  7865. strcpy(user,"anonymous");
  7866. strcpy(password,"");
  7867. }
  7868. else
  7869. {
  7870. //DEBUG_INFO("pch=%s\n", pch);
  7871. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  7872. protocol, user, password, host, &port, path);
  7873. }
  7874. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  7875. {
  7876. DEBUG_INFO("protocol is not ftp/http ! \n");
  7877. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7878. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7879. goto end;
  7880. }
  7881. if(strncmp(locationstr,"http", 4) == 0)
  7882. {
  7883. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  7884. sprintf(ftppath,"/%s", path);
  7885. do
  7886. {
  7887. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  7888. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7889. sleep(3);
  7890. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  7891. if(!isSuccess)
  7892. {
  7893. DEBUG_INFO("Diagnostics fail.\n");
  7894. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7895. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7896. sleep(retryIntervalInt);
  7897. }
  7898. else
  7899. {
  7900. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  7901. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  7902. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7903. }
  7904. retriesInt--;
  7905. }while((isSuccess == 0)&&(retriesInt >= 0));
  7906. }
  7907. else
  7908. {
  7909. sscanf(host,"%[^/]%s",host1, path1);
  7910. if(strlen(path) > 0)
  7911. sprintf(ftppath,"/%s", path);
  7912. else
  7913. sprintf(ftppath,"/%s", path1);
  7914. int ftppathlen=strlen(ftppath);
  7915. int i=1;
  7916. char filenametemp[50];
  7917. while(i < ftppathlen)
  7918. {
  7919. int len=ftppathlen-i;
  7920. if(ftppath[len]== 47) // '/' ascll code: 47
  7921. {
  7922. DEBUG_INFO("find '/' all right\n");
  7923. break;
  7924. }
  7925. i=i+1;
  7926. }
  7927. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  7928. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  7929. filenametemp[i+1] = 0;
  7930. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  7931. if(port == 0)
  7932. port = 21;
  7933. do
  7934. {
  7935. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  7936. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7937. sleep(3);
  7938. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  7939. if(!isSuccess)
  7940. {
  7941. DEBUG_INFO("Diagnostics fail.\n");
  7942. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7943. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7944. sleep(retryIntervalInt);
  7945. }
  7946. else
  7947. {
  7948. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  7949. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  7950. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7951. }
  7952. retriesInt--;
  7953. }while((!isSuccess)&&(retriesInt >= 0));
  7954. }
  7955. end:
  7956. system("rm -f /mnt/*");
  7957. sleep(5);
  7958. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  7959. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7960. pthread_exit(NULL);
  7961. }
  7962. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  7963. {
  7964. mtrace();
  7965. int result = FAIL;
  7966. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  7967. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  7968. {
  7969. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  7970. localversion = -1;
  7971. }
  7972. else
  7973. {
  7974. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  7975. OCPP_getListVerion();
  7976. }
  7977. //from db.OCPP_getListVerion
  7978. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  7979. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  7980. sendGetLocalListVersionConfirmation(uuid,"");
  7981. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  7982. return result;
  7983. }
  7984. int handleRemoteStartRequest(char *uuid, char *payload)
  7985. {
  7986. mtrace();
  7987. int result = FAIL;
  7988. int connectorIdInt=0;
  7989. int tempIndex = 0;
  7990. int connectorIdIsNULL, chargingProfileIsNULL;
  7991. char comfirmstr[20]={0};
  7992. char cmdBuf[512];
  7993. json_object *RemoteStartTransaction;
  7994. FILE *fp;
  7995. DEBUG_INFO("handleRemoteStartRequest ...\n");
  7996. if(server_pending == TRUE)
  7997. {
  7998. return 0;
  7999. }
  8000. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  8001. RemoteStartTransaction = json_tokener_parse(payload);
  8002. if(!is_error(RemoteStartTransaction))
  8003. {
  8004. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  8005. {
  8006. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  8007. if(connectorIdInt <= gunTotalNumber)
  8008. {
  8009. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  8010. // Required data
  8011. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  8012. // Optional data
  8013. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  8014. {
  8015. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  8016. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  8017. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  8018. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  8019. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  8020. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  8021. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  8022. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  8023. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  8024. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  8025. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  8026. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  8027. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  8028. {
  8029. 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")));
  8030. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  8031. 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"));
  8032. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  8033. 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"));
  8034. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  8035. 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")));
  8036. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  8037. {
  8038. 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++)
  8039. {
  8040. 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"));
  8041. 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"));
  8042. 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)
  8043. 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"));
  8044. }
  8045. }
  8046. }
  8047. }
  8048. else
  8049. chargingProfileIsNULL = TRUE;
  8050. }
  8051. }
  8052. else
  8053. connectorIdIsNULL = TRUE;
  8054. }
  8055. else
  8056. connectorIdIsNULL = TRUE;
  8057. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  8058. {
  8059. DEBUG_WARN("Connector id is NULL\n.");
  8060. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8061. goto end;
  8062. }
  8063. /*
  8064. enum _SYSTEM_STATUS
  8065. {
  8066. S_BOOTING = 0,
  8067. S_IDLE, = 1
  8068. S_AUTHORIZING, = 2
  8069. S_REASSIGN_CHECK, = 3
  8070. S_REASSIGN, = 4
  8071. S_PRECHARGE, = 5
  8072. S_PREPARING_FOR_EV, = 6
  8073. S_PREPARING_FOR_EVSE, = 7
  8074. S_CHARGING, = 8
  8075. S_TERMINATING, = 9
  8076. S_COMPLETE, = 10
  8077. S_ALARM, = 11
  8078. S_FAULT = 12
  8079. }
  8080. */
  8081. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  8082. {
  8083. //check Transaction active
  8084. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8085. {
  8086. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8087. {
  8088. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8089. }
  8090. else
  8091. {
  8092. tempIndex = connectorIdInt -1;
  8093. }
  8094. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8095. {
  8096. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  8097. {
  8098. 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))
  8099. {
  8100. //Reserved
  8101. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8102. }
  8103. 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))
  8104. {
  8105. //Reserved
  8106. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8107. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8108. goto end;
  8109. }
  8110. else
  8111. {
  8112. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8113. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  8114. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  8115. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  8116. {
  8117. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  8118. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8119. goto end;
  8120. }
  8121. }//END FOR ELSE
  8122. }
  8123. }// END FOR CHAdeMO_QUANTITY
  8124. }
  8125. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8126. {
  8127. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8128. {
  8129. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8130. }
  8131. else
  8132. {
  8133. tempIndex = connectorIdInt -1;
  8134. }
  8135. for (int index = 0; index < CCS_QUANTITY; index++)
  8136. {
  8137. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8138. {
  8139. 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))
  8140. {
  8141. //Reserved
  8142. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8143. }
  8144. 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))
  8145. {
  8146. //Reserved
  8147. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8148. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8149. goto end;
  8150. }
  8151. else
  8152. {
  8153. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8154. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8155. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8156. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8157. {
  8158. DEBUG_WARN("CCS connector not allow start\n.");
  8159. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8160. goto end;
  8161. }
  8162. }// END FOR ELSE
  8163. }
  8164. }// END FOR CCS_QUANTITY
  8165. }
  8166. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8167. {
  8168. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8169. {
  8170. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8171. }
  8172. else
  8173. {
  8174. tempIndex = connectorIdInt -1;
  8175. }
  8176. for (int index = 0; index < GB_QUANTITY; index++)
  8177. {
  8178. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  8179. {
  8180. 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))
  8181. {
  8182. //Reserved
  8183. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8184. }
  8185. 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))
  8186. {
  8187. //Reserved
  8188. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8189. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8190. goto end;
  8191. }
  8192. else
  8193. {
  8194. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8195. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8196. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8197. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8198. {
  8199. DEBUG_WARN("GB connector not allow start\n.");
  8200. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8201. goto end;
  8202. }
  8203. }// END FOR ELSE
  8204. }
  8205. } // END FOR GB_QUANTITY
  8206. }
  8207. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8208. {
  8209. tempIndex = connectorIdInt -1;
  8210. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8211. {
  8212. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  8213. {
  8214. 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))
  8215. {
  8216. //Reserved
  8217. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8218. }
  8219. 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))
  8220. {
  8221. //Reserved
  8222. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8223. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8224. goto end;
  8225. }
  8226. else
  8227. {
  8228. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8229. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8230. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8231. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8232. {
  8233. DEBUG_WARN("GB connector not allow start\n.");
  8234. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8235. goto end;
  8236. }
  8237. }// END FOR ELSE
  8238. }
  8239. } // END FOR GB_QUANTITY
  8240. }
  8241. else
  8242. {
  8243. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8244. {
  8245. tempIndex = 2;
  8246. }
  8247. else
  8248. {
  8249. tempIndex = connectorIdInt -1;
  8250. }
  8251. for (int index = 0; index < AC_QUANTITY; index++)
  8252. {
  8253. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  8254. {
  8255. 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))
  8256. {
  8257. //Reserved
  8258. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8259. }
  8260. 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))
  8261. {
  8262. //Reserved
  8263. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8264. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8265. goto end;
  8266. }
  8267. else
  8268. {
  8269. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8270. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8271. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8272. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8273. {
  8274. DEBUG_WARN("AC connector not allow start\n.");
  8275. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8276. goto end;
  8277. }
  8278. }//END FOR ELSE
  8279. }
  8280. }// END FOR AC_QUANTITY
  8281. }
  8282. if(chargingProfileIsNULL == FALSE)
  8283. {
  8284. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8285. {
  8286. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  8287. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8288. //memset idTag
  8289. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  8290. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8291. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  8292. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8293. // Save profile to file
  8294. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8295. system(cmdBuf);
  8296. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8297. fp = fopen(cmdBuf, "w");
  8298. 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));
  8299. fclose(fp);
  8300. }
  8301. else
  8302. {
  8303. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  8304. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8305. }
  8306. }
  8307. else
  8308. {
  8309. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  8310. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8311. //memset idTag
  8312. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  8313. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8314. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  8315. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8316. }
  8317. }
  8318. else
  8319. {
  8320. DEBUG_WARN("Connector id over\n.");
  8321. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8322. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  8323. }
  8324. end:
  8325. json_object_put(RemoteStartTransaction);
  8326. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  8327. {
  8328. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  8329. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  8330. }
  8331. //OCPP send RemoteStartConfirmation by first.
  8332. sendRemoteStartConfirmation(uuid, comfirmstr);
  8333. return result;
  8334. }
  8335. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  8336. {
  8337. mtrace();
  8338. int result = FAIL;
  8339. int match = FALSE;
  8340. int GunNO = 0;
  8341. int tempIndex = 0;
  8342. int transactionIdInt=0;
  8343. int transactionIdIsNULL= TRUE;
  8344. char comfirmstr[20];
  8345. json_object *RemoteStopTransaction;
  8346. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  8347. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  8348. if(server_pending == TRUE)
  8349. {
  8350. return 0;
  8351. }
  8352. RemoteStopTransaction = json_tokener_parse(payload);
  8353. if(!is_error(RemoteStopTransaction))
  8354. {
  8355. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  8356. {
  8357. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  8358. transactionIdIsNULL = FALSE;
  8359. }
  8360. }
  8361. json_object_put(RemoteStopTransaction);
  8362. if(transactionIdIsNULL == FALSE)
  8363. {
  8364. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  8365. {
  8366. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  8367. {
  8368. //check Transaction active
  8369. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  8370. {
  8371. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8372. {
  8373. tempIndex = ((gun_index==2) ? 1: 0);
  8374. }
  8375. else
  8376. {
  8377. tempIndex = gun_index;
  8378. }
  8379. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8380. {
  8381. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8382. {
  8383. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8384. {
  8385. match = TRUE;
  8386. GunNO = gun_index;
  8387. }
  8388. }
  8389. }// END FOR CHAdeMO_QUANTITY
  8390. }
  8391. else if(gunType[gun_index] == GUN_TYPE_CCS)
  8392. {
  8393. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8394. {
  8395. tempIndex = ((gun_index==2) ? 1: 0);
  8396. }
  8397. else
  8398. {
  8399. tempIndex = gun_index;
  8400. }
  8401. for (int index = 0; index < CCS_QUANTITY; index++)
  8402. {
  8403. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8404. {
  8405. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8406. {
  8407. match = TRUE;
  8408. GunNO = gun_index;
  8409. }
  8410. }
  8411. }// END FOR CCS_QUANTITY
  8412. }
  8413. else if(gunType[gun_index] == GUN_TYPE_GBT)
  8414. {
  8415. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8416. {
  8417. tempIndex = ((gun_index==2) ? 1: 0);
  8418. }
  8419. else
  8420. {
  8421. tempIndex = gun_index;
  8422. }
  8423. for (int index = 0; index < GB_QUANTITY; index++)
  8424. {
  8425. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8426. {
  8427. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8428. {
  8429. match = TRUE;
  8430. GunNO = gun_index;
  8431. }
  8432. }
  8433. }// END FOR GB_QUANTITY
  8434. }
  8435. else if(gunType[gun_index] == GUN_TYPE_DO)
  8436. {
  8437. tempIndex = gun_index;
  8438. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8439. {
  8440. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8441. {
  8442. 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
  8443. {
  8444. match = TRUE;
  8445. GunNO = gun_index;
  8446. }
  8447. }
  8448. }// END FOR GB_QUANTITY
  8449. }
  8450. else
  8451. {
  8452. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8453. {
  8454. tempIndex = 2;
  8455. }
  8456. else
  8457. {
  8458. tempIndex = gun_index;
  8459. }
  8460. for (int index = 0; index < AC_QUANTITY; index++)
  8461. {
  8462. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8463. {
  8464. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8465. {
  8466. match = TRUE;
  8467. GunNO = gun_index;
  8468. }
  8469. }
  8470. }// END FOR CHAdeMO_QUANTITY
  8471. } // END FOR AC ELSE
  8472. }// CHECK IF ResponseTransactionId == transactionIdInt
  8473. }//END FOR
  8474. if( match == TRUE)
  8475. {
  8476. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  8477. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8478. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  8479. }
  8480. else
  8481. {
  8482. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8483. }
  8484. }
  8485. else
  8486. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8487. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  8488. return result;
  8489. }
  8490. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  8491. {
  8492. mtrace();
  8493. int result = FAIL;
  8494. int connectorIdInt=0, reservationIdInt=0;
  8495. int tempIndex = 0;
  8496. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  8497. char comfirmstr[20]={0};
  8498. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  8499. int c = 0;
  8500. char *loc;
  8501. //char *ptr;
  8502. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  8503. strcpy(sstrtemp, stringtrimspace(payload));
  8504. //***(1)connectorId ****/
  8505. c=0;
  8506. loc = strstr(sstrtemp, "connectorId");
  8507. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8508. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  8509. {
  8510. sstr[c] = loc[strlen("connectorId")+2+c];
  8511. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8512. c++;
  8513. }
  8514. sstr[c] = '\0';
  8515. connectorIdInt = atoi(sstr);
  8516. //***(2)expiryDate ****/
  8517. loc = strstr(sstrtemp, "expiryDate");
  8518. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8519. c = 0;
  8520. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  8521. {
  8522. sstr[c] = loc[3+strlen("expiryDate")+c];
  8523. c++;
  8524. }
  8525. sstr[c] = '\0';
  8526. strcpy(expiryDatestr, sstr);
  8527. //***(3)idTag ****/
  8528. loc = strstr(sstrtemp, "idTag");
  8529. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8530. c = 0;
  8531. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  8532. {
  8533. sstr[c] = loc[3+strlen("idTag")+c];
  8534. c++;
  8535. }
  8536. sstr[c] = '\0';
  8537. strcpy(idTagstr, sstr);
  8538. //***(4)parentIdTag ****/
  8539. loc = strstr(sstrtemp, "parentIdTag");
  8540. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8541. c = 0;
  8542. if(loc == NULL)
  8543. {
  8544. strcpy(parentIdTagstr, "");
  8545. }
  8546. else
  8547. {
  8548. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8549. {
  8550. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8551. c++;
  8552. }
  8553. sstr[c] = '\0';
  8554. strcpy(parentIdTagstr, sstr);
  8555. }
  8556. //***(5)reservationId ****/
  8557. c=0;
  8558. loc = strstr(sstrtemp, "reservationId");
  8559. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8560. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  8561. {
  8562. sstr[c] = loc[strlen("reservationId")+2+c];
  8563. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8564. c++;
  8565. }
  8566. sstr[c] = '\0';
  8567. reservationIdInt = atoi(sstr);
  8568. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8569. /*
  8570. enum SYSTEM_STATUS
  8571. {
  8572. SYS_MODE_BOOTING = 0,
  8573. SYS_MODE_IDLE = 1,
  8574. SYS_MODE_AUTHORIZING = 2,
  8575. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  8576. SYS_MODE_REASSIGN = 4,
  8577. SYS_MODE_PREPARING = 5,
  8578. SYS_MODE_PREPARE_FOR_EV = 6,
  8579. SYS_MODE_PREPARE_FOR_EVSE = 7,
  8580. SYS_MODE_CHARGING = 8,
  8581. SYS_MODE_TERMINATING = 9,
  8582. SYS_MODE_COMPLETE = 10,
  8583. SYS_MODE_ALARM = 11,
  8584. SYS_MODE_FAULT = 12,
  8585. SYS_MODE_RESERVATION = 13,
  8586. SYS_MODE_BOOKING = 14,
  8587. SYS_MODE_MAINTAIN = 15,
  8588. SYS_MODE_DEBUG = 16,
  8589. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  8590. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  8591. SYS_MODE_UPDATE = 19
  8592. };
  8593. */
  8594. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  8595. {
  8596. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8597. goto end;
  8598. }
  8599. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  8600. {
  8601. //check Transaction active
  8602. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8603. {
  8604. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8605. {
  8606. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8607. }
  8608. else
  8609. {
  8610. tempIndex = connectorIdInt -1;
  8611. }
  8612. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8613. {
  8614. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8615. {
  8616. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  8617. {
  8618. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8619. {
  8620. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8621. {
  8622. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8623. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8624. }
  8625. 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'))
  8626. {
  8627. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8628. }
  8629. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8630. {
  8631. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8632. }
  8633. else
  8634. {
  8635. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8636. }
  8637. }
  8638. 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
  8639. {
  8640. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8641. }
  8642. }
  8643. else
  8644. {
  8645. //replace reservation
  8646. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8647. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8648. }
  8649. }
  8650. } // END FOR CHAdeMO_QUANTITY
  8651. }
  8652. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8653. {
  8654. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8655. {
  8656. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8657. }
  8658. else
  8659. {
  8660. tempIndex = connectorIdInt -1;
  8661. }
  8662. for (int index = 0; index < CCS_QUANTITY; index++)
  8663. {
  8664. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8665. {
  8666. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8667. {
  8668. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8669. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8670. {
  8671. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8672. {
  8673. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8674. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8675. }
  8676. 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'))
  8677. {
  8678. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8679. }
  8680. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  8681. {
  8682. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8683. }
  8684. else
  8685. {
  8686. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8687. }
  8688. }
  8689. 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
  8690. {
  8691. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8692. }
  8693. }
  8694. else
  8695. {
  8696. //replace reservation
  8697. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8698. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8699. }
  8700. }
  8701. } // END FOR CCS_QUANTITY
  8702. }
  8703. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8704. {
  8705. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8706. {
  8707. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8708. }
  8709. else
  8710. {
  8711. tempIndex = connectorIdInt -1;
  8712. }
  8713. for (int index = 0; index < GB_QUANTITY; index++)
  8714. {
  8715. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8716. {
  8717. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8718. {
  8719. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8720. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  8721. {
  8722. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8723. {
  8724. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8725. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8726. }
  8727. 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'))
  8728. {
  8729. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8730. }
  8731. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8732. {
  8733. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8734. }
  8735. else
  8736. {
  8737. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8738. }
  8739. }
  8740. 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
  8741. {
  8742. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8743. }
  8744. }
  8745. else
  8746. {
  8747. //replace reservation
  8748. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8749. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8750. }
  8751. }
  8752. }// END FOR GB_QUANTITY
  8753. }
  8754. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8755. {
  8756. tempIndex = connectorIdInt -1;
  8757. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8758. {
  8759. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8760. {
  8761. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  8762. {
  8763. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8764. 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
  8765. {
  8766. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8767. {
  8768. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8769. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8770. }
  8771. 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'))
  8772. {
  8773. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8774. }
  8775. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8776. {
  8777. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8778. }
  8779. else
  8780. {
  8781. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8782. }
  8783. }
  8784. 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
  8785. {
  8786. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8787. }
  8788. }
  8789. else
  8790. {
  8791. //replace reservation
  8792. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8793. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8794. }
  8795. }
  8796. }// END FOR GB_QUANTITY
  8797. }
  8798. else
  8799. {
  8800. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8801. {
  8802. tempIndex = 2;
  8803. }
  8804. else
  8805. {
  8806. tempIndex = (connectorIdInt -1);
  8807. }
  8808. for (int index = 0; index < AC_QUANTITY; index++)
  8809. {
  8810. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8811. {
  8812. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  8813. {
  8814. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  8815. {
  8816. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8817. {
  8818. 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))
  8819. {
  8820. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8821. }
  8822. else
  8823. {
  8824. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8825. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8826. }
  8827. }
  8828. 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'))
  8829. {
  8830. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8831. }
  8832. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8833. {
  8834. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8835. }
  8836. else
  8837. {
  8838. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8839. }
  8840. }
  8841. 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
  8842. {
  8843. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8844. }
  8845. }
  8846. else
  8847. {
  8848. //replace reservation
  8849. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8850. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8851. }
  8852. }
  8853. } // END FOR AC_QUANTITY
  8854. }
  8855. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8856. }
  8857. else if(connectorIdInt == 0)
  8858. {
  8859. //check Transaction active
  8860. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8861. {
  8862. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  8863. {
  8864. 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'))
  8865. {
  8866. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8867. goto end;
  8868. }
  8869. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8870. {
  8871. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8872. goto end;
  8873. }
  8874. 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
  8875. {
  8876. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8877. goto end;
  8878. }
  8879. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8880. {
  8881. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8882. goto end;
  8883. }
  8884. }
  8885. }// END FOR CHAdeMO_QUANTITY
  8886. for (int index = 0; index < CCS_QUANTITY; index++)
  8887. {
  8888. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8889. {
  8890. 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'))
  8891. {
  8892. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8893. goto end;
  8894. }
  8895. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  8896. {
  8897. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8898. goto end;
  8899. }
  8900. 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
  8901. {
  8902. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8903. goto end;
  8904. }
  8905. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8906. {
  8907. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8908. goto end;
  8909. }
  8910. }
  8911. } // END FOR CCS_QUANTITY
  8912. for (int index = 0; index < GB_QUANTITY; index++)
  8913. {
  8914. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8915. {
  8916. 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'))
  8917. {
  8918. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8919. goto end;
  8920. }
  8921. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8922. {
  8923. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8924. goto end;
  8925. }
  8926. 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
  8927. {
  8928. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8929. goto end;
  8930. }
  8931. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8932. {
  8933. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8934. goto end;
  8935. }
  8936. }
  8937. } // END FOR GB_QUANTITY
  8938. for (int index = 0; index < AC_QUANTITY; index++)
  8939. {
  8940. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  8941. {
  8942. 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'))
  8943. {
  8944. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8945. goto end;
  8946. }
  8947. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8948. {
  8949. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8950. goto end;
  8951. }
  8952. 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
  8953. {
  8954. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8955. goto end;
  8956. }
  8957. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8958. {
  8959. 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))
  8960. {
  8961. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8962. goto end;
  8963. }
  8964. }
  8965. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8966. {
  8967. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8968. goto end;
  8969. }
  8970. }
  8971. }// END FOR AC_QUANTITY
  8972. //The connectorId is 0
  8973. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  8974. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8975. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  8976. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  8977. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  8978. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  8979. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  8980. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  8981. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  8982. result = TRUE;
  8983. return result;
  8984. }
  8985. else
  8986. {
  8987. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8988. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8989. }
  8990. if(strcmp(comfirmstr,"Accepted") == 0)
  8991. {
  8992. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  8993. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  8994. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  8995. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  8996. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  8997. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  8998. result = TRUE;
  8999. return result;
  9000. }
  9001. end:
  9002. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  9003. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  9004. return result;
  9005. }
  9006. int handleResetRequest(char *uuid, char *payload)
  9007. {
  9008. mtrace();
  9009. int result = FAIL;
  9010. char sstr[10]={0},sstrtemp[30]={ 0 };
  9011. char typestr[10]={0};
  9012. char comfirmstr[20]={0};
  9013. int c = 0;
  9014. char *loc;
  9015. DEBUG_INFO("handleResetRequest...\n");
  9016. strcpy(sstrtemp, stringtrimspace(payload));
  9017. loc = strstr(sstrtemp, "type");
  9018. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9019. c = 0;
  9020. while (loc[3+strlen("type")+c] != '\"')
  9021. {
  9022. sstr[c] = loc[3+strlen("type")+c];
  9023. c++;
  9024. }
  9025. sstr[c] = '\0';
  9026. strcpy(typestr,sstr);
  9027. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  9028. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  9029. {
  9030. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  9031. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  9032. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  9033. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  9034. }
  9035. else
  9036. {
  9037. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  9038. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  9039. result = PASS;
  9040. }
  9041. sendResetConfirmation(uuid, comfirmstr);
  9042. return result;
  9043. }
  9044. int handleSendLocalListRequest(char *uuid, char *payload)
  9045. {
  9046. mtrace();
  9047. int result = FAIL;
  9048. int listVersionInt;
  9049. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  9050. char listsearch[]="listVersion";
  9051. char updateTypesearch[]="updateType";
  9052. char localAuthorizationListsearch[]="localAuthorizationList";
  9053. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  9054. char CardList[500][160]={0};
  9055. char updateTypestr[15]={0};
  9056. char idTagstr[20]={0};
  9057. char parentIdTag[20]={0};
  9058. char expiryDate[30]={0};
  9059. char idTagstatus[16]={0};
  9060. int c = 0;
  9061. int i = 0;
  9062. char *delim1 = "}";
  9063. char * pch;
  9064. char *loc;
  9065. //char *ptr;
  9066. char comfirmstr[20];
  9067. //int n_localAuthorizations = 0;
  9068. int checkState_Faulted = FALSE;
  9069. DEBUG_INFO("handleSendLocalListRequest...\n");
  9070. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  9071. {
  9072. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9073. goto end;
  9074. }
  9075. //check Charge Point state
  9076. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9077. {
  9078. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9079. {
  9080. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9081. }
  9082. }
  9083. for (int index = 0; index < CCS_QUANTITY; index++)
  9084. {
  9085. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9086. {
  9087. checkState_Faulted = TRUE; //OCPP Status
  9088. }
  9089. }
  9090. for (int index = 0; index < GB_QUANTITY; index++)
  9091. {
  9092. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9093. {
  9094. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9095. }
  9096. }
  9097. //check Charge Point state
  9098. for (int index = 0; index < AC_QUANTITY; index++)
  9099. {
  9100. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9101. {
  9102. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9103. }
  9104. }
  9105. if(checkState_Faulted == TRUE)
  9106. {
  9107. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9108. goto end;
  9109. }
  9110. //Filter payload space
  9111. strcpy(sstrtemp, stringtrimspace(payload));
  9112. //listVersion
  9113. c = 0;
  9114. loc = strstr(sstrtemp, listsearch);
  9115. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  9116. {
  9117. sstr[c] = loc[strlen("listVersion")+2+c];
  9118. c++;
  9119. }
  9120. sstr[c] = '\0';
  9121. listVersionInt = atoi(sstr);
  9122. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  9123. //updateType
  9124. loc = strstr(sstrtemp, updateTypesearch);
  9125. c = 0;
  9126. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  9127. {
  9128. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  9129. c++;
  9130. }
  9131. sstr[c] = '\0';
  9132. strcpy(updateTypestr, sstr);
  9133. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  9134. //localAuthorizationList
  9135. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9136. loc = strstr(sstrtemp, localAuthorizationListsearch);
  9137. if(loc != NULL) // localAuthorizationList is not NULL
  9138. {
  9139. //Check UpdateType
  9140. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  9141. {
  9142. //Local list full update
  9143. printf("Local list full update.\n");
  9144. OCPP_getListVerion();
  9145. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  9146. {
  9147. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9148. goto end;
  9149. }
  9150. OCPP_cleanLocalList();
  9151. }
  9152. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  9153. {
  9154. //Local list different update
  9155. printf("Local list different update.\n");
  9156. OCPP_getListVerion();
  9157. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  9158. {
  9159. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  9160. goto end;
  9161. }
  9162. }
  9163. else
  9164. {
  9165. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9166. goto end;
  9167. }
  9168. c = 0;
  9169. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  9170. {
  9171. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  9172. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9173. c++;
  9174. }
  9175. sstr[c] = '\0';
  9176. //DEBUG_INFO("sstr=%s\n", sstr);
  9177. //parsing strings to words
  9178. i = 0;
  9179. pch = strtok(sstr,delim1);
  9180. while (pch != NULL)
  9181. {
  9182. strcpy(CardList[i], pch);
  9183. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  9184. pch = strtok (NULL, delim1);
  9185. i = i + 1;
  9186. }
  9187. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  9188. //local Authorizations List Numbers
  9189. //n_localAuthorizations = i;
  9190. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  9191. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  9192. c= 0;
  9193. while(c < i) // i is CardList Number
  9194. {
  9195. //Search "IdToken"
  9196. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9197. loc = strstr(CardList[c], "idTag");
  9198. int j = 0;
  9199. while (loc[3+strlen("idTag")+j] != '\"')
  9200. {
  9201. sstr[j] = loc[3+strlen("idTag")+j];
  9202. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9203. j++;
  9204. }
  9205. sstr[j] = '\0';
  9206. strcpy(idTagstr, sstr);
  9207. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  9208. //Search "expiryDate"
  9209. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9210. loc = strstr(CardList[c], "expiryDate");
  9211. j = 0;
  9212. if(loc != NULL)
  9213. {
  9214. while (loc[3+strlen("expiryDate")+j] != '\"')
  9215. {
  9216. sstr[j] = loc[3+strlen("expiryDate")+j];
  9217. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9218. j++;
  9219. }
  9220. sstr[j] = '\0';
  9221. strcpy(expiryDate, sstr);
  9222. }
  9223. else
  9224. {
  9225. strcpy(expiryDate, "");
  9226. }
  9227. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  9228. //Search "parentIdTag"
  9229. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9230. loc = strstr(CardList[c], "parentIdTag");
  9231. j = 0;
  9232. if(loc != NULL)
  9233. {
  9234. while (loc[3+strlen("parentIdTag")+j] != '\"')
  9235. {
  9236. sstr[j] = loc[3+strlen("parentIdTag")+j];
  9237. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9238. j++;
  9239. }
  9240. sstr[j] = '\0';
  9241. strcpy(parentIdTag, sstr);
  9242. }
  9243. else
  9244. {
  9245. strcpy(parentIdTag, "");
  9246. }
  9247. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  9248. //Search "status"
  9249. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9250. loc = strstr(CardList[c], "status");
  9251. j = 0;
  9252. while (loc[3+strlen("status")+j] != '\"')
  9253. {
  9254. sstr[j] = loc[3+strlen("status")+j];
  9255. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9256. j++;
  9257. }
  9258. sstr[j] = '\0';
  9259. strcpy(idTagstatus, sstr);
  9260. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  9261. OCPP_getIdTagFromLocalList(idTagstr);
  9262. //OCPP_getIdTagFromLocalList("test"); For Test
  9263. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  9264. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  9265. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  9266. {
  9267. //Local list full update
  9268. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  9269. // update list
  9270. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  9271. //DEBUG_INFO("Local list full update. 1\n");
  9272. //OCPP_get_TableAuthlocalAllData();
  9273. //DEBUG_INFO("Local list full update. 2\n");
  9274. }
  9275. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  9276. {
  9277. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  9278. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  9279. }
  9280. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  9281. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  9282. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  9283. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  9284. c++;
  9285. }
  9286. }
  9287. else
  9288. {
  9289. //Check UpdateType
  9290. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  9291. {
  9292. //Local list full update
  9293. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  9294. OCPP_cleanLocalList();
  9295. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9296. goto end;
  9297. }
  9298. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  9299. {
  9300. //Local list different update
  9301. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  9302. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9303. goto end;
  9304. }
  9305. }
  9306. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9307. end:
  9308. sendSendLocalListConfirmation(uuid, comfirmstr);
  9309. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  9310. return result;
  9311. }
  9312. #define MAX 200
  9313. int handleSetChargingProfileRequest(char *uuid, char *payload)
  9314. {
  9315. mtrace();
  9316. int result = FAIL;
  9317. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  9318. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  9319. char chargingProfilePurposeStr[30]={0};
  9320. char chargingProfileKindStr[16]={0};
  9321. char recurrencyKindStr[10]={0};
  9322. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  9323. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  9324. int chargingSchedulePeriodCount = 0;
  9325. char comfirmstr[20]={0};
  9326. int meet= FALSE;
  9327. FILE *fptr1;
  9328. char filename[MAX]={0};
  9329. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  9330. char rmFileCmd[50]={0};
  9331. char tempchargingProfilePurposeStr[30]={0};
  9332. char word[1600]={0};
  9333. int n_chargingProfile = 0;
  9334. json_object *SetChargingProfile;
  9335. DEBUG_INFO("handleSetChargingProfileRequest\n");
  9336. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  9337. SetChargingProfile = json_tokener_parse(payload);
  9338. if(!is_error(SetChargingProfile))
  9339. {
  9340. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  9341. {
  9342. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  9343. if(connectorIdInt == 0)
  9344. {
  9345. memset(&ShmOCPP16Data->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  9346. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  9347. }
  9348. else
  9349. {
  9350. memset(&ShmOCPP16Data->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  9351. ShmOCPP16Data->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  9352. }
  9353. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  9354. }
  9355. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  9356. {
  9357. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  9358. {
  9359. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  9360. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9361. {
  9362. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  9363. }
  9364. else
  9365. {
  9366. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  9367. }
  9368. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  9369. }
  9370. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  9371. {
  9372. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  9373. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9374. {
  9375. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  9376. }
  9377. else
  9378. {
  9379. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  9380. }
  9381. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  9382. }
  9383. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9384. {
  9385. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  9386. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9387. {
  9388. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  9389. }
  9390. else
  9391. {
  9392. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  9393. }
  9394. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  9395. }
  9396. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  9397. {
  9398. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  9399. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9400. {
  9401. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  9402. }
  9403. else
  9404. {
  9405. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  9406. }
  9407. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  9408. }
  9409. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  9410. {
  9411. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  9412. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9413. {
  9414. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  9415. }
  9416. else
  9417. {
  9418. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  9419. }
  9420. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  9421. }
  9422. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  9423. {
  9424. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  9425. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9426. {
  9427. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9428. }
  9429. else
  9430. {
  9431. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9432. }
  9433. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  9434. }
  9435. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  9436. {
  9437. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  9438. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9439. {
  9440. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  9441. }
  9442. else
  9443. {
  9444. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  9445. }
  9446. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  9447. }
  9448. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  9449. {
  9450. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  9451. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9452. {
  9453. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  9454. }
  9455. else
  9456. {
  9457. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  9458. }
  9459. //DEBUG_INFO("validToStr: %s\n", validToStr);
  9460. }
  9461. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  9462. {
  9463. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  9464. {
  9465. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  9466. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9467. {
  9468. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9469. }
  9470. else
  9471. {
  9472. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9473. }
  9474. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  9475. }
  9476. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  9477. {
  9478. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  9479. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9480. {
  9481. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9482. }
  9483. else
  9484. {
  9485. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9486. }
  9487. //DEBUG_INFO("durationInt: %d\n", durationInt);
  9488. }
  9489. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  9490. {
  9491. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  9492. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9493. {
  9494. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9495. }
  9496. else
  9497. {
  9498. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9499. }
  9500. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  9501. }
  9502. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  9503. {
  9504. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  9505. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9506. {
  9507. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9508. }
  9509. else
  9510. {
  9511. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9512. }
  9513. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  9514. }
  9515. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9516. {
  9517. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  9518. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  9519. if(chargingSchedulePeriodCount <= 10)
  9520. {
  9521. 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++)
  9522. {
  9523. 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)
  9524. {
  9525. 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"));
  9526. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9527. {
  9528. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9529. }
  9530. else
  9531. {
  9532. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9533. }
  9534. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  9535. }
  9536. 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)
  9537. {
  9538. 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"));
  9539. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9540. {
  9541. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9542. }
  9543. else
  9544. {
  9545. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9546. }
  9547. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  9548. }
  9549. 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)
  9550. {
  9551. 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"));
  9552. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9553. {
  9554. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9555. }
  9556. else
  9557. {
  9558. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9559. }
  9560. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  9561. }
  9562. }
  9563. }
  9564. }
  9565. }
  9566. }
  9567. }
  9568. json_object_put(SetChargingProfile);
  9569. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  9570. {
  9571. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9572. goto end;
  9573. }
  9574. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  9575. {
  9576. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  9577. if(connectorIdInt != 0)
  9578. {
  9579. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9580. goto end;
  9581. }
  9582. strcpy(filename, ChargePointMaxProfile_JSON );
  9583. fptr1 = fopen(filename, "r");
  9584. if (!fptr1)
  9585. {
  9586. //file not exist
  9587. DEBUG_INFO("Unable to open the input file!!\n");
  9588. fptr1 = fopen(filename, "w+");
  9589. }
  9590. else
  9591. {
  9592. //Check Charging Profile Count
  9593. while(fscanf(fptr1, "%s", word) != EOF)
  9594. {
  9595. //DEBUG_INFO("word=%s\n",word);
  9596. if(strstr(word, "chargingProfileId")!= NULL)
  9597. {
  9598. //DEBUG_INFO("test chargingProfileId \n");
  9599. n_chargingProfile = n_chargingProfile + 1;
  9600. //DEBUG_INFO("chargingProfileId Found\n");
  9601. }
  9602. }
  9603. }
  9604. fclose(fptr1);
  9605. }
  9606. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  9607. {
  9608. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  9609. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9610. {
  9611. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9612. goto end;
  9613. }
  9614. memset(filename, 0, ARRAY_SIZE(filename));
  9615. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9616. fptr1 = fopen(filename, "r");
  9617. if (!fptr1)
  9618. {
  9619. //file not exist
  9620. //DEBUG_INFO("Unable to open the input file!!\n");
  9621. fptr1 = fopen(filename, "w+");
  9622. }
  9623. else
  9624. {
  9625. //Check Charging Profile Count
  9626. while(fscanf(fptr1, "%s", word) != EOF)
  9627. {
  9628. //DEBUG_INFO("word=%s\n",word);
  9629. if(strstr(word, "chargingProfileId")!= NULL)
  9630. {
  9631. //DEBUG_INFO("test chargingProfileId \n");
  9632. n_chargingProfile = n_chargingProfile + 1;
  9633. //DEBUG_INFO("chargingProfileId Found\n");
  9634. }
  9635. }
  9636. }
  9637. fclose(fptr1);
  9638. }
  9639. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9640. {
  9641. //printf("set chargingProfile 1-4\n");
  9642. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  9643. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  9644. if(connectorIdInt == 0)
  9645. {
  9646. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9647. goto end;
  9648. }
  9649. int tempIndex = 0;
  9650. //check Transaction active
  9651. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9652. {
  9653. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9654. {
  9655. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9656. }
  9657. else
  9658. {
  9659. tempIndex = connectorIdInt -1;
  9660. }
  9661. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9662. {
  9663. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9664. {
  9665. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9666. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9667. {
  9668. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9669. {
  9670. meet = TRUE;
  9671. break;
  9672. }
  9673. }
  9674. }
  9675. }
  9676. }
  9677. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9678. {
  9679. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9680. {
  9681. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9682. }
  9683. else
  9684. {
  9685. tempIndex = connectorIdInt -1;
  9686. }
  9687. for (int index = 0; index < CCS_QUANTITY; index++)
  9688. {
  9689. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9690. {
  9691. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9692. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9693. {
  9694. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9695. {
  9696. meet = TRUE;
  9697. break;
  9698. }
  9699. }
  9700. }
  9701. }
  9702. }
  9703. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9704. {
  9705. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9706. {
  9707. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9708. }
  9709. else
  9710. {
  9711. tempIndex = connectorIdInt -1;
  9712. }
  9713. for (int index = 0; index < GB_QUANTITY; index++)
  9714. {
  9715. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9716. {
  9717. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9718. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9719. {
  9720. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9721. {
  9722. meet = TRUE;
  9723. break;
  9724. }
  9725. }
  9726. }
  9727. }
  9728. }
  9729. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9730. {
  9731. tempIndex = connectorIdInt -1;
  9732. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9733. {
  9734. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9735. {
  9736. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  9737. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9738. {
  9739. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9740. {
  9741. meet = TRUE;
  9742. break;
  9743. }
  9744. }
  9745. }
  9746. }
  9747. }
  9748. else
  9749. {
  9750. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9751. {
  9752. tempIndex = 2;
  9753. }
  9754. else
  9755. {
  9756. tempIndex = (connectorIdInt -1);
  9757. }
  9758. for (int index = 0; index < AC_QUANTITY; index++)
  9759. {
  9760. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9761. {
  9762. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9763. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9764. {
  9765. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9766. {
  9767. meet = TRUE;
  9768. break;
  9769. }
  9770. }
  9771. }
  9772. }
  9773. }
  9774. //check Transaction active
  9775. if(meet == FALSE)
  9776. {
  9777. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9778. goto end;
  9779. }
  9780. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9781. {
  9782. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9783. goto end;
  9784. }
  9785. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9786. fptr1 = fopen(filename, "r");
  9787. if (!fptr1)
  9788. {
  9789. //file not exist
  9790. DEBUG_INFO("Unable to open the input file!!\n");
  9791. fptr1 = fopen(filename, "w+");
  9792. }
  9793. else
  9794. {
  9795. //Check Charging Profile Count
  9796. while(fscanf(fptr1, "%s", word) != EOF)
  9797. {
  9798. //DEBUG_INFO("word=%s\n",word);
  9799. if(strstr(word, "chargingProfileId")!= NULL)
  9800. {
  9801. //DEBUG_INFO("test chargingProfileId \n");
  9802. n_chargingProfile = n_chargingProfile + 1;
  9803. //DEBUG_INFO("chargingProfileId Found\n");
  9804. }
  9805. }
  9806. }
  9807. fclose(fptr1);
  9808. }
  9809. // Check ChargeProfileMaxStackLevel
  9810. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  9811. {
  9812. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9813. goto end;
  9814. }
  9815. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9816. {
  9817. int i = 0;
  9818. char fnametemp[200]={0};
  9819. n_chargingProfile = 0;
  9820. //Check ChargePointMaxProfile.json exit
  9821. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9822. {
  9823. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  9824. //Check Charging Profile Count
  9825. while(fscanf(fptr1, "%s", word) != EOF)
  9826. {
  9827. //DEBUG_INFO("word=%s\n",word);
  9828. if(strstr(word, "chargingProfileId")!= NULL)
  9829. {
  9830. //DEBUG_INFO("test chargingProfileId \n");
  9831. n_chargingProfile = n_chargingProfile + 1;
  9832. i = i + 1;
  9833. //DEBUG_INFO("chargingProfileId Found\n");
  9834. }
  9835. memset(word, 0, ARRAY_SIZE(word));
  9836. }
  9837. fclose(fptr1);
  9838. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  9839. }
  9840. //Check TxDefaultProfile_0.json exit
  9841. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9842. {
  9843. i = 0;
  9844. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  9845. //Check Charging Profile Count
  9846. while(fscanf(fptr1, "%s", word) != EOF)
  9847. {
  9848. //DEBUG_INFO("word=%s\n",word);
  9849. if(strstr(word, "chargingProfileId")!= NULL)
  9850. {
  9851. //DEBUG_INFO("test chargingProfileId \n");
  9852. n_chargingProfile = n_chargingProfile + 1;
  9853. i = i + 1;
  9854. //DEBUG_INFO("chargingProfileId Found\n");
  9855. }
  9856. memset(word, 0, ARRAY_SIZE(word));
  9857. }
  9858. fclose(fptr1);
  9859. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  9860. }
  9861. //Check TxDefaultProfile_%d.json
  9862. for(int j=1; j <= gunTotalNumber; j++)
  9863. {
  9864. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9865. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9866. if((access(fnametemp,F_OK))!=-1)
  9867. {
  9868. i = 0;
  9869. fptr1 = fopen(fnametemp, "r");
  9870. //Check Charging Profile Count
  9871. while(fscanf(fptr1, "%s", word) != EOF)
  9872. {
  9873. //DEBUG_INFO("word=%s\n",word);
  9874. if(strstr(word, "chargingProfileId")!= NULL)
  9875. {
  9876. //DEBUG_INFO("test chargingProfileId \n");
  9877. n_chargingProfile = n_chargingProfile + 1;
  9878. i = i + 1;
  9879. //DEBUG_INFO("chargingProfileId Found\n");
  9880. }
  9881. memset(word, 0, ARRAY_SIZE(word));
  9882. }
  9883. fclose(fptr1);
  9884. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9885. }
  9886. }
  9887. //Check TxProfile_%d.json
  9888. for(int j=1; j <= gunTotalNumber; j++)
  9889. {
  9890. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9891. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9892. if((access(fnametemp,F_OK))!=-1)
  9893. {
  9894. i = 0;
  9895. fptr1 = fopen(fnametemp, "r");
  9896. //Check Charging Profile Count
  9897. while(fscanf(fptr1, "%s", word) != EOF)
  9898. {
  9899. //DEBUG_INFO("word=%s\n",word);
  9900. if(strstr(word, "chargingProfileId")!= NULL)
  9901. {
  9902. //DEBUG_INFO("test chargingProfileId \n");
  9903. n_chargingProfile = n_chargingProfile + 1;
  9904. i = i + 1;
  9905. //DEBUG_INFO("chargingProfileId Found\n");
  9906. }
  9907. memset(word, 0, ARRAY_SIZE(word));
  9908. }
  9909. fclose(fptr1);
  9910. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9911. }
  9912. }
  9913. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  9914. {
  9915. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9916. goto end;
  9917. }
  9918. }
  9919. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9920. //**********************************Write to File********************************************************/
  9921. FILE *infile;
  9922. FILE *outfile;
  9923. infile = fopen (filename, "r");
  9924. outfile = fopen (tempfile, "w");
  9925. int d =0;
  9926. d = fgetc(infile);
  9927. rewind(infile);
  9928. if(d == EOF)
  9929. {
  9930. // Profile is empty
  9931. fprintf(outfile,"%s\n",payload);
  9932. fclose(infile);
  9933. fclose(outfile);
  9934. sprintf(rmFileCmd,"rm -f %s",filename);
  9935. system(rmFileCmd);
  9936. rename(tempfile, filename);
  9937. }
  9938. else
  9939. {
  9940. // Profile is not empty
  9941. char buf[2048]={0};
  9942. int ChargingProfileAdded = FALSE;
  9943. while (fgets(buf, sizeof(buf), infile) != NULL)
  9944. {
  9945. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9946. json_object *tmpChargingProfile;
  9947. tmpChargingProfile = json_tokener_parse(buf);
  9948. if(!is_error(SetChargingProfile))
  9949. {
  9950. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  9951. {
  9952. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  9953. }
  9954. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  9955. {
  9956. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  9957. {
  9958. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  9959. }
  9960. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  9961. {
  9962. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  9963. }
  9964. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9965. {
  9966. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  9967. }
  9968. }
  9969. }
  9970. json_object_put(tmpChargingProfile);
  9971. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  9972. {
  9973. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9974. {
  9975. //DEBUG_INFO("update set chargingProfile to file -0\n");
  9976. if(ChargingProfileAdded == FALSE)
  9977. {
  9978. fprintf(outfile,"%s\n",payload);
  9979. ChargingProfileAdded = TRUE;
  9980. }
  9981. }
  9982. else
  9983. {
  9984. if(tempstackLevelInt < stackLevelInt)
  9985. {
  9986. if(ChargingProfileAdded == FALSE)
  9987. {
  9988. fprintf(outfile,"%s\n",buf);
  9989. fprintf(outfile,"%s\n",payload);
  9990. ChargingProfileAdded = TRUE;
  9991. }
  9992. else
  9993. {
  9994. fprintf(outfile,"%s\n",buf);
  9995. }
  9996. }
  9997. else
  9998. {
  9999. if(ChargingProfileAdded == FALSE)
  10000. {
  10001. fprintf(outfile,"%s\n",buf);
  10002. fprintf(outfile,"%s\n",payload);
  10003. ChargingProfileAdded = TRUE;
  10004. }
  10005. else
  10006. {
  10007. fprintf(outfile,"%s\n",buf);
  10008. }
  10009. }
  10010. }
  10011. }
  10012. else
  10013. {
  10014. if(tempchargingProfileIdInt < chargingProfileIdInt)
  10015. {
  10016. if(ChargingProfileAdded == FALSE)
  10017. {
  10018. fprintf(outfile,"%s\n",buf);
  10019. fprintf(outfile,"%s\n",payload);
  10020. ChargingProfileAdded = TRUE;
  10021. }
  10022. else
  10023. {
  10024. fprintf(outfile,"%s\n",buf);
  10025. }
  10026. }
  10027. else if(tempstackLevelInt < stackLevelInt)
  10028. {
  10029. if(ChargingProfileAdded == FALSE)
  10030. {
  10031. fprintf(outfile,"%s\n",buf);
  10032. fprintf(outfile,"%s\n",payload);
  10033. ChargingProfileAdded = TRUE;
  10034. }
  10035. else
  10036. {
  10037. fprintf(outfile,"%s\n",buf);
  10038. }
  10039. }
  10040. else
  10041. {
  10042. if(ChargingProfileAdded == FALSE)
  10043. {
  10044. fprintf(outfile,"%s\n",buf);
  10045. fprintf(outfile,"%s\n",payload);
  10046. ChargingProfileAdded = TRUE;
  10047. }
  10048. else
  10049. {
  10050. fprintf(outfile,"%s\n",buf);
  10051. }
  10052. }
  10053. }
  10054. } // end of while loop
  10055. fclose(infile);
  10056. fclose(outfile);
  10057. sprintf(rmFileCmd,"rm -f %s",filename);
  10058. system(rmFileCmd);
  10059. rename(tempfile, filename);
  10060. }
  10061. sleep(1);
  10062. result = TRUE;
  10063. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  10064. end:
  10065. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  10066. {
  10067. if(connectorIdInt == 0)
  10068. {
  10069. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  10070. {
  10071. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  10072. }
  10073. }
  10074. else
  10075. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  10076. }
  10077. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  10078. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10079. return result;
  10080. }
  10081. int handleTriggerMessageRequest(char *uuid, char *payload)
  10082. {
  10083. mtrace();
  10084. int result = FAIL;
  10085. int connectorIdIsNULL = FALSE;
  10086. int connectorIdInt =0;
  10087. char sstr[40]={0},sstrtemp[100]={ 0 };
  10088. char requestedMessagestr[40]={0};
  10089. char comfirmstr[20]={0};
  10090. int c = 0;
  10091. char *loc;
  10092. DEBUG_INFO("handleTriggerMessageRequest\n");
  10093. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  10094. strcpy(sstrtemp, stringtrimspace(payload));
  10095. c = 0;
  10096. loc = strstr(sstrtemp, "requestedMessage");
  10097. while (loc[3+strlen("requestedMessage")+c] != '\"')
  10098. {
  10099. sstr[c] = loc[3+strlen("requestedMessage")+c];
  10100. c++;
  10101. }
  10102. sstr[c] = '\0';
  10103. strcpy(requestedMessagestr, sstr);
  10104. c = 0;
  10105. loc = strstr(sstrtemp, "connectorId");
  10106. if(loc == NULL)
  10107. {
  10108. connectorIdIsNULL = TRUE;
  10109. }
  10110. else
  10111. {
  10112. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10113. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  10114. {
  10115. sstr[c] = loc[strlen("connectorId")+2+c];
  10116. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10117. c++;
  10118. }
  10119. sstr[c] = '\0';
  10120. connectorIdInt = atoi(sstr);
  10121. }
  10122. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  10123. {
  10124. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  10125. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  10126. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  10127. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  10128. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  10129. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  10130. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  10131. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  10132. {
  10133. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  10134. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10135. return TRUE;
  10136. }
  10137. else
  10138. {
  10139. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  10140. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10141. }
  10142. }
  10143. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  10144. {
  10145. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  10146. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10147. return TRUE;
  10148. }
  10149. //==========================
  10150. // Trigger message
  10151. //==========================
  10152. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  10153. {
  10154. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  10155. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  10156. {
  10157. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  10158. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  10159. }
  10160. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10161. }
  10162. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  10163. {
  10164. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  10165. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10166. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10167. }
  10168. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  10169. {
  10170. //sendBootNotificationRequest();
  10171. server_sign = FALSE;
  10172. }
  10173. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  10174. {
  10175. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  10176. }
  10177. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  10178. {
  10179. if(connectorIdIsNULL == FALSE)
  10180. {
  10181. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  10182. {
  10183. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  10184. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  10185. }
  10186. }
  10187. else
  10188. {
  10189. for(int idx=0;idx< gunTotalNumber;idx++)
  10190. {
  10191. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  10192. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  10193. }
  10194. }
  10195. }
  10196. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  10197. {
  10198. if(connectorIdIsNULL == FALSE)
  10199. {
  10200. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  10201. {
  10202. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  10203. cpinitateMsg.bits[connectorIdInt -1].StatusNotificationReq = 1;
  10204. }
  10205. }
  10206. else
  10207. {
  10208. for(int idx=0;idx< gunTotalNumber;idx++)
  10209. {
  10210. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  10211. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  10212. }
  10213. }
  10214. }
  10215. return result;
  10216. }
  10217. int handleUnlockConnectorRequest(char *uuid, char *payload)
  10218. {
  10219. mtrace();
  10220. int result = FAIL;
  10221. int connectorIdInt =0;
  10222. char comfirmstr[20]={0};
  10223. int tempIndex = 0;
  10224. json_object *UnlockConnector;
  10225. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  10226. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  10227. UnlockConnector = json_tokener_parse(payload);
  10228. if(!is_error(UnlockConnector))
  10229. {
  10230. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  10231. {
  10232. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  10233. }
  10234. }
  10235. json_object_put(UnlockConnector);
  10236. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  10237. if(gunTotalNumber == 0)
  10238. {
  10239. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10240. goto end;
  10241. }
  10242. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  10243. {
  10244. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10245. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10246. goto end;
  10247. }
  10248. else
  10249. {
  10250. //check Transaction active
  10251. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  10252. {
  10253. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10254. {
  10255. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10256. }
  10257. else
  10258. {
  10259. tempIndex = connectorIdInt -1;
  10260. }
  10261. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10262. {
  10263. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10264. {
  10265. //stop Transaction
  10266. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10267. }
  10268. }
  10269. }
  10270. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  10271. {
  10272. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10273. {
  10274. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10275. }
  10276. else
  10277. {
  10278. tempIndex = connectorIdInt -1;
  10279. }
  10280. for (int index = 0; index < CCS_QUANTITY; index++)
  10281. {
  10282. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10283. {
  10284. //stop Transaction
  10285. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10286. }
  10287. }
  10288. }
  10289. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  10290. {
  10291. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10292. {
  10293. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10294. }
  10295. else
  10296. {
  10297. tempIndex = connectorIdInt -1;
  10298. }
  10299. for (int index = 0; index < GB_QUANTITY; index++)
  10300. {
  10301. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  10302. {
  10303. //stop Transaction
  10304. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10305. }
  10306. }
  10307. }
  10308. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  10309. {
  10310. tempIndex = connectorIdInt -1;
  10311. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10312. {
  10313. 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)))
  10314. {
  10315. //stop Transaction
  10316. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10317. }
  10318. }
  10319. }
  10320. else
  10321. {
  10322. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10323. {
  10324. tempIndex = 2;
  10325. }
  10326. else
  10327. {
  10328. tempIndex = connectorIdInt-1;
  10329. }
  10330. for (int index = 0; index < AC_QUANTITY; index++)
  10331. {
  10332. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10333. {
  10334. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10335. }
  10336. }
  10337. }
  10338. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  10339. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  10340. result = TRUE;
  10341. return result;
  10342. }
  10343. end:
  10344. //json_object_put(obj); --- remove temporally
  10345. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  10346. return result;
  10347. }
  10348. static char UpdateFirmwarepayloadData[300]={0};
  10349. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  10350. {
  10351. mtrace();
  10352. int result = FAIL;
  10353. pthread_t t;
  10354. sendUpdateFirmwareConfirmation(uuid);
  10355. memset(UpdateFirmwarepayloadData, 0, 300);
  10356. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  10357. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  10358. ////pthread_join(t, NULL); //
  10359. //pthread_detach(t);
  10360. //sendUpdateFirmwareConfirmation(uuid);
  10361. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  10362. return result;
  10363. }
  10364. void *UpdateFirmwareProcess(void *data)
  10365. {
  10366. pthread_detach(pthread_self());
  10367. mtrace();
  10368. int retriesInt =0, retryIntervalInt=0;
  10369. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  10370. int port=0;
  10371. char locationstr[512]={0}, retrieveDatestr[36]={0};
  10372. int isSuccess = 0;
  10373. char ftpbuf[512];
  10374. char temp[100];
  10375. char * pch;
  10376. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  10377. json_object *UpdateFirmware;
  10378. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  10379. if(!is_error(UpdateFirmware))
  10380. {
  10381. // Required data
  10382. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  10383. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  10384. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  10385. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  10386. // Optional data
  10387. if(json_object_object_get(UpdateFirmware, "retries"))
  10388. {
  10389. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  10390. }
  10391. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  10392. {
  10393. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  10394. }
  10395. }
  10396. json_object_put(UpdateFirmware);
  10397. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10398. memset(path, 0, ARRAY_SIZE(path));
  10399. // Wait retrieveData
  10400. if(strlen(retrieveDatestr) > 10)
  10401. {
  10402. do
  10403. {
  10404. sleep(1);
  10405. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  10406. }
  10407. // Ready to download
  10408. system("rm -f /mnt/*");
  10409. if(strncmp(locationstr,"http", 4) == 0)
  10410. {
  10411. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10412. sprintf(ftppath,"/%s", path);
  10413. DEBUG_INFO("locationstr: %s\n", locationstr);
  10414. DEBUG_INFO("protocol: %s\n",protocol);
  10415. DEBUG_INFO("host: %s\n",host);
  10416. DEBUG_INFO("path: %s\n",path);
  10417. DEBUG_INFO("ftppath: %s\n",ftppath);
  10418. int ftppathlen=strlen(ftppath);
  10419. int i=1;
  10420. char filenametemp[50];
  10421. while(i < ftppathlen)
  10422. {
  10423. int len=ftppathlen-i;
  10424. if(ftppath[len]== 47) // '/' ascll code: 47
  10425. {
  10426. DEBUG_INFO("compare '/' all right\n");
  10427. break;
  10428. }
  10429. i=i+1;
  10430. }
  10431. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10432. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10433. filenametemp[i+1] = 0;
  10434. do
  10435. {
  10436. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  10437. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10438. sleep(1);
  10439. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  10440. if(!isSuccess)
  10441. {
  10442. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10443. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10444. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  10445. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10446. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10447. }
  10448. else
  10449. {
  10450. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10451. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10452. }
  10453. retriesInt--;
  10454. }while((isSuccess == 0)&&(retriesInt >= 0));
  10455. }
  10456. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  10457. {
  10458. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  10459. memset(temp, 0, ARRAY_SIZE(temp));
  10460. //DEBUG_INFO("locationstr=%s\n",locationstr);
  10461. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  10462. int ftppathlen=strlen(ftpbuf);
  10463. int i=1;
  10464. char filenametemp[50];
  10465. while(i < ftppathlen)
  10466. {
  10467. int len=ftppathlen-i;
  10468. if(ftpbuf[len]== 47) // '/' ascll code: 47
  10469. {
  10470. DEBUG_INFO(" compare '/' all right\n");
  10471. break;
  10472. }
  10473. i=i+1;
  10474. }
  10475. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10476. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  10477. filenametemp[i+1] = 0;
  10478. strncpy(temp, ftpbuf, ftppathlen-i+1);
  10479. pch=strchr(temp,'@');
  10480. if(pch==NULL)
  10481. {
  10482. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10483. protocol, host, &port, path);
  10484. strcpy(user,"anonymous");
  10485. strcpy(password,"");
  10486. }
  10487. else
  10488. {
  10489. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10490. protocol, user, password, host, &port, path);
  10491. }
  10492. sscanf(host,"%[^/]%s",host1, path1);
  10493. sprintf(ftppath,"%s", path1);
  10494. //DEBUG_INFO("protocol =%s\n",protocol);
  10495. //DEBUG_INFO("user =%s\n",user);
  10496. //DEBUG_INFO("password =%s\n",password);
  10497. //DEBUG_INFO("host1 =%s\n",host1);
  10498. //DEBUG_INFO("port =%d\n",port);
  10499. //DEBUG_INFO("path1 =%s\n",path1);
  10500. //DEBUG_INFO("ftppath=%s\n",ftppath);
  10501. //ftpFile(host, user, password, port, ftppath, fname);
  10502. //download firmware pthred
  10503. if(port == 0)
  10504. {
  10505. port = 21;
  10506. }
  10507. do
  10508. {
  10509. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  10510. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10511. sleep(1);
  10512. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  10513. if(!isSuccess)
  10514. {
  10515. //BulldogUtil.sleepMs(interval*1000);
  10516. DEBUG_INFO("Update firmware request and download file fail.\n");
  10517. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10518. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10519. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  10520. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10521. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10522. }
  10523. else
  10524. {
  10525. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10526. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10527. }
  10528. retriesInt--;
  10529. }while((!isSuccess)&&(retriesInt >= 0));
  10530. }
  10531. else
  10532. {
  10533. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10534. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10535. sleep(1);
  10536. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10537. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10538. }
  10539. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  10540. pthread_exit(NULL);
  10541. }
  10542. int handleCertificateSignedRequest(char *uuid, char *payload)
  10543. {
  10544. mtrace();
  10545. int result = PASS;
  10546. json_object *CertificateSigned;
  10547. DEBUG_INFO("handleCertificateSignedRequest...\n");
  10548. CertificateSigned = json_tokener_parse(payload);
  10549. if(!is_error(CertificateSigned))
  10550. {
  10551. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  10552. }
  10553. json_object_put(CertificateSigned);
  10554. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  10555. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  10556. fclose(fp);
  10557. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10558. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  10559. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  10560. sendCertificateSignedConfirmation(uuid);
  10561. return result;
  10562. }
  10563. int handleDeleteCertificateRequest(char *uuid, char *payload)
  10564. {
  10565. mtrace();
  10566. int result = PASS;
  10567. json_object *DeleteCertificate;
  10568. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  10569. DeleteCertificate = json_tokener_parse(payload);
  10570. if(!is_error(DeleteCertificate))
  10571. {
  10572. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  10573. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  10574. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  10575. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  10576. }
  10577. json_object_put(DeleteCertificate);
  10578. /*
  10579. * TODO: Delete certificateSigned process
  10580. */
  10581. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  10582. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  10583. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  10584. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  10585. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  10586. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  10587. sendDeleteCertificateConfirmation(uuid);
  10588. return result;
  10589. }
  10590. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  10591. {
  10592. mtrace();
  10593. int result = PASS;
  10594. json_object *ExtendedTriggerMessage;
  10595. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  10596. ExtendedTriggerMessage = json_tokener_parse(payload);
  10597. if(!is_error(ExtendedTriggerMessage))
  10598. {
  10599. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  10600. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  10601. {
  10602. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  10603. }
  10604. else
  10605. {
  10606. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  10607. }
  10608. }
  10609. json_object_put(ExtendedTriggerMessage);
  10610. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  10611. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  10612. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  10613. {
  10614. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  10615. }
  10616. else
  10617. {
  10618. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  10619. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  10620. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  10621. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  10622. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  10623. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  10624. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  10625. {
  10626. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  10627. }
  10628. else
  10629. {
  10630. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  10631. }
  10632. }
  10633. sendExtendedTriggerMessageConfirmation(uuid);
  10634. //==========================
  10635. // Trigger message
  10636. //==========================
  10637. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  10638. {
  10639. //sendBootNotificationRequest();
  10640. server_sign = FALSE;
  10641. }
  10642. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  10643. {
  10644. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  10645. }
  10646. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  10647. {
  10648. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  10649. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  10650. {
  10651. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  10652. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  10653. }
  10654. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10655. }
  10656. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  10657. {
  10658. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  10659. }
  10660. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  10661. {
  10662. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  10663. {
  10664. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  10665. }
  10666. else
  10667. {
  10668. for(int idx=0;idx< gunTotalNumber;idx++)
  10669. {
  10670. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  10671. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  10672. }
  10673. }
  10674. }
  10675. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  10676. {
  10677. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  10678. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  10679. {
  10680. system("openssl req -newkey rsa:2048 -out /Storage/OCPP/certCP.csr -nodes -keyout /Storage/OCPP/certCP.key -subj \"/C=TW/ST=Taiwan/L=Taoyuan/O=Phihong Technology/OU=IT/CN=phihong.com\" &");
  10681. }
  10682. }
  10683. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  10684. {
  10685. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  10686. {
  10687. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  10688. }
  10689. else
  10690. {
  10691. for(int idx=0;idx< gunTotalNumber;idx++)
  10692. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  10693. }
  10694. }
  10695. return result;
  10696. }
  10697. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  10698. {
  10699. mtrace();
  10700. int result = PASS;
  10701. json_object *GetInstalledCertificateIds;
  10702. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  10703. GetInstalledCertificateIds = json_tokener_parse(payload);
  10704. if(!is_error(GetInstalledCertificateIds))
  10705. {
  10706. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  10707. }
  10708. json_object_put(GetInstalledCertificateIds);
  10709. /*
  10710. * TODO: Return installed certificate process
  10711. */
  10712. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  10713. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  10714. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  10715. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  10716. sendGetInstalledCertificateIdsConfirmation(uuid);
  10717. return result;
  10718. }
  10719. int handleGetLogRequest(char *uuid, char *payload)
  10720. {
  10721. mtrace();
  10722. int result = PASS;
  10723. json_object *GetLog;
  10724. DEBUG_INFO("handleGetLogRequest...\n");
  10725. GetLog = json_tokener_parse(payload);
  10726. if(!is_error(GetLog))
  10727. {
  10728. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  10729. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  10730. if(json_object_object_get(GetLog, "retries") != NULL)
  10731. {
  10732. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  10733. }
  10734. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  10735. {
  10736. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  10737. }
  10738. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  10739. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  10740. {
  10741. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  10742. }
  10743. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  10744. {
  10745. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  10746. }
  10747. }
  10748. json_object_put(GetLog);
  10749. /*
  10750. * TODO: Upload log process
  10751. */
  10752. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  10753. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  10754. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  10755. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  10756. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  10757. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  10758. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  10759. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  10760. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  10761. sendGetLogConfirmation(uuid);
  10762. return result;
  10763. }
  10764. int handleInstallCertificateRequest(char *uuid, char *payload)
  10765. {
  10766. mtrace();
  10767. int result = PASS;
  10768. json_object *InstallCertificate;
  10769. DEBUG_INFO("handleInstallCertificateRequest...\n");
  10770. InstallCertificate = json_tokener_parse(payload);
  10771. if(!is_error(InstallCertificate))
  10772. {
  10773. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  10774. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  10775. /*
  10776. * TODO: Install certificate process
  10777. */
  10778. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  10779. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  10780. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  10781. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  10782. sendInstallCertificateConfirmation(uuid);
  10783. }
  10784. json_object_put(InstallCertificate);
  10785. return result;
  10786. }
  10787. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  10788. {
  10789. mtrace();
  10790. int result = PASS;
  10791. json_object *SignedUpdateFirmware;
  10792. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  10793. SignedUpdateFirmware = json_tokener_parse(payload);
  10794. if(!is_error(SignedUpdateFirmware))
  10795. {
  10796. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  10797. {
  10798. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  10799. }
  10800. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  10801. {
  10802. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  10803. }
  10804. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  10805. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  10806. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  10807. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  10808. {
  10809. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  10810. }
  10811. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  10812. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  10813. }
  10814. json_object_put(SignedUpdateFirmware);
  10815. /*
  10816. * TODO: Upgrade firmware process
  10817. */
  10818. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  10819. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  10820. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  10821. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  10822. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  10823. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  10824. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  10825. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  10826. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  10827. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  10828. sendInstallCertificateConfirmation(uuid);
  10829. return result;
  10830. }
  10831. int handleUnknownRequest(char *uuid, char *payload)
  10832. {
  10833. mtrace();
  10834. int result = PASS;
  10835. DEBUG_INFO("handleUnknownRequest...\n");
  10836. sendUnknownConfirmation(uuid);
  10837. result = PASS;
  10838. return result;
  10839. }
  10840. //==========================================
  10841. // Handle server response routine
  10842. //==========================================
  10843. void handleAuthorizeResponse(char *payload, int gun_index)
  10844. {
  10845. mtrace();
  10846. char expiryDatestr[30]={0};
  10847. char parentIdTagstr[20]={0};
  10848. char statusstr[20]={0};
  10849. int expiryDateISNULL=FALSE;
  10850. int parentIdTagISNULL=FALSE;
  10851. DEBUG_INFO("handleAuthorizeResponse...\n");
  10852. json_object *Authorize;
  10853. Authorize = json_tokener_parse(payload);
  10854. if(!is_error(Authorize))
  10855. {
  10856. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  10857. {
  10858. // Required data
  10859. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  10860. // Optional data
  10861. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  10862. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  10863. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  10864. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  10865. }
  10866. }
  10867. json_object_put(Authorize);
  10868. if(expiryDateISNULL == FALSE)
  10869. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  10870. if(parentIdTagISNULL == FALSE)
  10871. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  10872. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  10873. //Update idTag information to authorization cache if supproted
  10874. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  10875. {
  10876. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  10877. }
  10878. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  10879. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  10880. authorizeRetryTimes = 0;
  10881. }
  10882. void handleBootNotificationResponse(char *payload, int gun_index)
  10883. {
  10884. mtrace();
  10885. char statusStr[12]={0};
  10886. char currentTimeStr[30]={0};
  10887. int intervalInt = 0;
  10888. DEBUG_INFO("handleBootNotificationResponse...\n");
  10889. json_object *BootNotification;
  10890. BootNotification = json_tokener_parse(payload);
  10891. if(!is_error(BootNotification))
  10892. {
  10893. // Required data
  10894. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  10895. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  10896. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  10897. }
  10898. json_object_put(BootNotification);
  10899. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10900. BootNotificationInterval = intervalInt;
  10901. HeartBeatWaitTime = intervalInt;
  10902. //write back to ShmOCPP16Data->BootNotification
  10903. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  10904. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10905. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  10906. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  10907. {
  10908. server_sign = TRUE;
  10909. server_pending =FALSE;
  10910. }
  10911. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  10912. {
  10913. server_pending = TRUE;
  10914. }
  10915. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  10916. srand(time(NULL));
  10917. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  10918. SetOcppConnStatus(TRUE);
  10919. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  10920. }
  10921. void handleDataTransferResponse(char *payload, int gun_index)
  10922. {
  10923. char sstr[160]={0};//sstr[200]={ 0 };
  10924. int c = 0;
  10925. char *loc;
  10926. DEBUG_INFO("handleDataTransferResponse ...\n");
  10927. loc = strstr(payload, "status");
  10928. printf("loc=%s\n",loc);
  10929. c = 0;
  10930. while (loc[3+strlen("status")+c] != '\"')
  10931. {
  10932. sstr[c] = loc[3+strlen("status")+c];
  10933. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10934. c++;
  10935. }
  10936. sstr[c] = '\0';
  10937. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  10938. }
  10939. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  10940. {
  10941. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  10942. //struct json_object *obj;
  10943. // obj = json_tokener_parse(payload);
  10944. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  10945. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  10946. //No fields are defined.
  10947. }
  10948. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  10949. {
  10950. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  10951. //struct json_object *obj;
  10952. // obj = json_tokener_parse(payload);
  10953. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  10954. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  10955. //No fields are defined.
  10956. }
  10957. void handleHeartbeatResponse(char *payload, int gun_index)
  10958. {
  10959. mtrace();
  10960. DEBUG_INFO("handleHeartbeatResponse...\n");
  10961. json_object *Heartbeat;
  10962. Heartbeat = json_tokener_parse(payload);
  10963. if(!is_error(Heartbeat))
  10964. {
  10965. // Required data
  10966. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  10967. }
  10968. json_object_put(Heartbeat);
  10969. if(FirstHeartBeat == 0)
  10970. {
  10971. FirstHeartBeat = 1;
  10972. DEBUG_INFO("FirstHeartBeat \n");
  10973. }
  10974. HeartBeatWithNOResponse = 0;
  10975. clientTime.Heartbeat=time((time_t*)NULL);
  10976. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  10977. }
  10978. void handleMeterValuesResponse(char *payload, int gun_index)
  10979. {
  10980. mtrace();
  10981. DEBUG_INFO("handleMeterValuesResponse...\n");
  10982. }
  10983. void handleStartTransactionResponse(char *payload, int gun_index)
  10984. {
  10985. mtrace();
  10986. //int transactionIdInt = 0;
  10987. FILE *outfile;
  10988. char data[100]={0};
  10989. DEBUG_INFO("handleStartTransactionResponse...\n");
  10990. json_object *StartTransaction;
  10991. StartTransaction = json_tokener_parse(payload);
  10992. if(!is_error(StartTransaction))
  10993. {
  10994. // Required data
  10995. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  10996. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  10997. // Optional data
  10998. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  10999. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  11000. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11001. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  11002. }
  11003. json_object_put(StartTransaction);
  11004. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  11005. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  11006. //-----------Start : write to the Queue TransactionId file -----------------//
  11007. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  11008. {}
  11009. else
  11010. {
  11011. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  11012. if(log == NULL)
  11013. {
  11014. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  11015. return ;
  11016. }
  11017. else
  11018. {
  11019. fclose(log);
  11020. }
  11021. }
  11022. // open file for writing
  11023. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  11024. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  11025. {
  11026. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  11027. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  11028. fputs(data, outfile);
  11029. fclose (outfile);
  11030. }
  11031. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11032. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11033. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  11034. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  11035. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11036. }
  11037. void handleStatusNotificationResponse(char *payload, int gun_index)
  11038. {
  11039. mtrace();
  11040. DEBUG_INFO("handleStatusNotificationResponse...\n");
  11041. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  11042. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  11043. }
  11044. void handleStopTransactionnResponse(char *payload, int gun_index)
  11045. {
  11046. mtrace();
  11047. DEBUG_INFO("handleStopTransactionnResponse...\n");
  11048. json_object *StopTransaction;
  11049. StopTransaction = json_tokener_parse(payload);
  11050. if(!is_error(StopTransaction))
  11051. {
  11052. // Optional data
  11053. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  11054. {
  11055. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  11056. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  11057. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  11058. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11059. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  11060. }
  11061. }
  11062. json_object_put(StopTransaction);
  11063. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  11064. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  11065. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11066. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11067. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  11068. }
  11069. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  11070. {
  11071. mtrace();
  11072. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  11073. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  11074. }
  11075. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  11076. {
  11077. mtrace();
  11078. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  11079. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  11080. }
  11081. void handleSignCertificateResponse(char *payload, int gun_index)
  11082. {
  11083. mtrace();
  11084. DEBUG_INFO("handleSignCertificateResponse...\n");
  11085. json_object *SignCertificate;
  11086. SignCertificate = json_tokener_parse(payload);
  11087. if(!is_error(SignCertificate))
  11088. {
  11089. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  11090. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  11091. }
  11092. json_object_put(SignCertificate);
  11093. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  11094. }
  11095. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11096. {
  11097. mtrace();
  11098. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  11099. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  11100. }
  11101. //==========================================
  11102. // Handle Error routine
  11103. //==========================================
  11104. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  11105. {
  11106. mtrace();
  11107. #ifdef SystemLogMessage
  11108. DEBUG_INFO("errorCode: %s\n", errorCode);
  11109. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  11110. DEBUG_INFO("errorDetails: %s\n", payload);
  11111. #endif
  11112. }
  11113. //===============================================
  11114. // Common routine
  11115. //===============================================
  11116. int initialConfigurationTable(void)
  11117. {
  11118. //clock_t start_t, end_t, total_t;
  11119. FILE *fp;
  11120. FILE *outfile;
  11121. char str[512]={0};
  11122. char sstr[256]={0};
  11123. int c = 0;
  11124. char *loc;
  11125. int confVersion = 2;
  11126. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  11127. //start_t = clock();
  11128. //printf("Starting of the program, start_t = %ld\n", start_t);
  11129. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  11130. // Check configuration file size is correct
  11131. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  11132. {
  11133. struct stat st;
  11134. stat("/Storage/OCPP/OCPPConfiguration", &st);
  11135. if(st.st_size < 3100)
  11136. {
  11137. system("rm -f /Storage/OCPP/OCPPConfiguration");
  11138. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  11139. }
  11140. }
  11141. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  11142. {
  11143. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  11144. if(outfile == NULL)
  11145. {
  11146. DEBUG_INFO("Error opening file\n");
  11147. return FALSE;
  11148. }
  11149. /*Core Profile*/
  11150. //AllowOfflineTxForUnknownId
  11151. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11152. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11153. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  11154. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11155. //AuthorizationCacheEnabled
  11156. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11157. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11158. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11159. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11160. //AuthorizeRemoteTxRequests
  11161. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11162. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11163. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  11164. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11165. //BlinkRepeat
  11166. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11167. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11168. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11169. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11170. //ClockAlignedDataInterval
  11171. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11172. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11173. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11174. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11175. //ConnectionTimeOut
  11176. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11177. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11178. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11179. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11180. //GetConfigurationMaxKeys
  11181. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11182. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11183. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  11184. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11185. // HeartbeatInterval
  11186. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11187. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11188. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  11189. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11190. // LightIntensity
  11191. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11192. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11193. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11194. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11195. // LocalAuthorizeOffline
  11196. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  11197. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  11198. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  11199. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11200. // LocalPreAuthorize
  11201. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  11202. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  11203. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  11204. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  11205. // MaxEnergyOnInvalidId
  11206. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  11207. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  11208. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  11209. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  11210. // MeterValuesAlignedData
  11211. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  11212. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  11213. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11214. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11215. else
  11216. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11217. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  11218. // MeterValuesAlignedDataMaxLength
  11219. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  11220. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  11221. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11222. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  11223. else
  11224. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "9" );
  11225. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  11226. // MeterValuesSampledData
  11227. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  11228. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  11229. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11230. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11231. else
  11232. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11233. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  11234. // MeterValuesSampledDataMaxLength
  11235. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  11236. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  11237. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11238. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  11239. else
  11240. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "9" );
  11241. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  11242. // MeterValueSampleInterval
  11243. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  11244. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  11245. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  11246. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  11247. // MinimumStatusDuration
  11248. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  11249. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  11250. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  11251. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  11252. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  11253. // NumberOfConnectors
  11254. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  11255. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  11256. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11257. {
  11258. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  11259. }
  11260. else
  11261. {
  11262. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  11263. }
  11264. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  11265. // ResetRetries
  11266. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  11267. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  11268. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  11269. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  11270. // ConnectorPhaseRotation
  11271. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  11272. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  11273. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  11274. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  11275. // ConnectorPhaseRotationMaxLength
  11276. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  11277. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  11278. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  11279. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  11280. // StopTransactionOnEVSideDisconnect
  11281. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  11282. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  11283. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  11284. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  11285. // StopTransactionOnInvalidId
  11286. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  11287. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  11288. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  11289. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  11290. // StopTxnAlignedData
  11291. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  11292. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  11293. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  11294. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  11295. // StopTxnAlignedDataMaxLength
  11296. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  11297. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  11298. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  11299. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  11300. // StopTxnSampledData
  11301. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  11302. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  11303. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11304. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11305. else
  11306. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11307. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  11308. // StopTxnSampledDataMaxLength
  11309. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  11310. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  11311. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11312. {
  11313. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  11314. }
  11315. else
  11316. {
  11317. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  11318. }
  11319. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  11320. // SupportedFeatureProfiles
  11321. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  11322. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  11323. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  11324. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  11325. // SupportedFeatureProfilesMaxLength
  11326. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  11327. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  11328. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  11329. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  11330. // TransactionMessageAttempts
  11331. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  11332. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  11333. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  11334. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11335. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11336. // TransactionMessageRetryInterval
  11337. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  11338. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  11339. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  11340. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11341. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11342. // UnlockConnectorOnEVSideDisconnect
  11343. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  11344. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  11345. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  11346. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  11347. // WebSocketPingInterval
  11348. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  11349. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  11350. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  11351. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  11352. // QueueOffLineStartTransactionMessage
  11353. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  11354. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  11355. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  11356. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  11357. // AuthorizationKey
  11358. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  11359. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  11360. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "" );
  11361. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  11362. // SecurityProfile
  11363. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  11364. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  11365. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "0" );
  11366. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  11367. // DefaultPrice
  11368. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  11369. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  11370. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  11371. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  11372. // CustomDisplayCostAndPrice
  11373. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  11374. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  11375. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  11376. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  11377. // CustomIdleFeeAfterStop
  11378. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  11379. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  11380. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  11381. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  11382. // Configuration Version
  11383. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  11384. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  11385. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  11386. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  11387. //* Local Auth List Management Profile*/
  11388. #if 0
  11389. //For OCTT Test Case
  11390. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11391. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  11392. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11393. #endif
  11394. #if 1
  11395. //LocalAuthListEnabled
  11396. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11397. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  11398. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11399. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11400. #endif
  11401. //LocalAuthListMaxLength
  11402. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  11403. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  11404. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  11405. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  11406. //SendLocalListMaxLength
  11407. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  11408. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  11409. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  11410. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  11411. //ReserveConnectorZeroSupported
  11412. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  11413. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  11414. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  11415. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11416. //* Smart Charging Profile */
  11417. //ChargeProfileMaxStackLevel
  11418. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  11419. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  11420. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  11421. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11422. // ChargingScheduleAllowedChargingRateUnit
  11423. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  11424. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  11425. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  11426. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11427. // ChargingScheduleMaxPeriods
  11428. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  11429. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  11430. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  11431. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11432. // ConnectorSwitch3to1PhaseSupported
  11433. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11434. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11435. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  11436. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11437. // MaxChargingProfilesInstalled
  11438. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11439. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11440. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  11441. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11442. fclose(outfile);
  11443. }
  11444. else
  11445. {
  11446. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  11447. char keystr[60]={0};
  11448. char readonlystr[10]={0};
  11449. char valuestr[256]={0};
  11450. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  11451. if(fp == NULL) {
  11452. DEBUG_INFO("Error opening file");
  11453. return FALSE;
  11454. }
  11455. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  11456. {
  11457. //DEBUG_INFO("Get Configuration \n");
  11458. if(strlen(str) > 0)
  11459. {
  11460. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  11461. //*************************key*********************************/
  11462. if(strstr(str, "key") != NULL)
  11463. {
  11464. loc = strstr(str, "key");
  11465. c = 0;
  11466. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11467. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  11468. {
  11469. sstr[c] = loc[strlen("key")+3+c];
  11470. c++;
  11471. }
  11472. sstr[c] = '\0';
  11473. strcpy(keystr,sstr);
  11474. }
  11475. //*************************readonly*********************************/
  11476. if(strstr(str, "readonly") != NULL)
  11477. {
  11478. loc = strstr(str, "readonly");
  11479. c = 0;
  11480. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11481. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  11482. {
  11483. sstr[c] = loc[strlen("readonly")+2+c];
  11484. c++;
  11485. }
  11486. sstr[c] = '\0';
  11487. strcpy(readonlystr,sstr);
  11488. }
  11489. //*************************value*********************************/
  11490. if(strstr(str, "value") != NULL)
  11491. {
  11492. loc = strstr(str, "value");
  11493. c = 0;
  11494. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11495. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  11496. {
  11497. sstr[c] = loc[strlen("value")+3+c];
  11498. c++;
  11499. }
  11500. sstr[c] = '\0';
  11501. strcpy(valuestr,sstr);
  11502. }
  11503. // DEBUG_INFO("keystr=%s\n",keystr);
  11504. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  11505. // DEBUG_INFO("valuestr=%s\n",valuestr);
  11506. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  11507. {
  11508. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11509. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11510. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  11511. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  11512. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  11513. }
  11514. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  11515. {
  11516. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11517. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11518. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  11519. }
  11520. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  11521. {
  11522. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11523. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  11524. }
  11525. if(strcmp(keystr, "BlinkRepeat") == 0)
  11526. {
  11527. //Charger.BlinkRepeat = Integer.parseInt(value);
  11528. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11529. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  11530. }
  11531. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  11532. {
  11533. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11534. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  11535. }
  11536. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  11537. {
  11538. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11539. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  11540. }
  11541. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  11542. {
  11543. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11544. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  11545. }
  11546. if(strcmp(keystr, "HeartbeatInterval") == 0)
  11547. {
  11548. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11549. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  11550. HeartBeatWaitTime = atoi(valuestr);
  11551. }
  11552. if(strcmp(keystr, "LightIntensity") == 0)
  11553. {
  11554. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11555. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  11556. }
  11557. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  11558. {
  11559. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11560. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  11561. }
  11562. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  11563. {
  11564. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11565. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  11566. }
  11567. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  11568. {
  11569. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11570. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  11571. }
  11572. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  11573. {
  11574. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11575. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  11576. }
  11577. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  11578. {
  11579. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11580. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  11581. }
  11582. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  11583. {
  11584. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11585. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  11586. }
  11587. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  11588. {
  11589. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11590. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  11591. }
  11592. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  11593. {
  11594. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11595. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  11596. }
  11597. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  11598. {
  11599. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11600. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  11601. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  11602. }
  11603. if(strcmp(keystr, "NumberOfConnectors") == 0)
  11604. {
  11605. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11606. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  11607. }
  11608. if(strcmp(keystr, "ResetRetries") == 0)
  11609. {
  11610. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11611. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  11612. }
  11613. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  11614. {
  11615. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11616. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  11617. }
  11618. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  11619. {
  11620. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11621. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  11622. }
  11623. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  11624. {
  11625. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11626. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  11627. }
  11628. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  11629. {
  11630. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11631. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  11632. }
  11633. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  11634. {
  11635. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11636. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  11637. }
  11638. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  11639. {
  11640. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11641. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  11642. }
  11643. if(strcmp(keystr, "StopTxnSampledData") == 0)
  11644. {
  11645. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11646. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  11647. }
  11648. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  11649. {
  11650. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11651. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  11652. }
  11653. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  11654. {
  11655. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11656. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  11657. }
  11658. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  11659. {
  11660. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11661. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  11662. }
  11663. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  11664. {
  11665. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11666. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  11667. TransactionMessageAttemptsValue = atoi(valuestr);
  11668. }
  11669. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  11670. {
  11671. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11672. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  11673. TransactionMessageRetryIntervalValue = atoi(valuestr);
  11674. }
  11675. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  11676. {
  11677. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11678. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  11679. }
  11680. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  11681. {
  11682. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11683. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  11684. }
  11685. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  11686. {
  11687. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11688. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  11689. }
  11690. if(strcmp(keystr, "AuthorizationKey") == 0)
  11691. {
  11692. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11693. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  11694. }
  11695. if(strcmp(keystr, "SecurityProfile") == 0)
  11696. {
  11697. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11698. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  11699. }
  11700. if(strcmp(keystr, "DefaultPrice") == 0)
  11701. {
  11702. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11703. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  11704. }
  11705. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  11706. {
  11707. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11708. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  11709. }
  11710. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  11711. {
  11712. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11713. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  11714. }
  11715. if(strcmp(keystr, "ConfigurationVersion") == 0)
  11716. {
  11717. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11718. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  11719. }
  11720. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  11721. {
  11722. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11723. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  11724. }
  11725. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  11726. {
  11727. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11728. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  11729. }
  11730. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  11731. {
  11732. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11733. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  11734. }
  11735. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  11736. {
  11737. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11738. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  11739. }
  11740. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  11741. {
  11742. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11743. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  11744. }
  11745. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  11746. {
  11747. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11748. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  11749. }
  11750. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  11751. {
  11752. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11753. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  11754. }
  11755. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  11756. {
  11757. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11758. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  11759. }
  11760. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  11761. {
  11762. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11763. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  11764. }
  11765. }
  11766. }
  11767. fclose(fp);
  11768. }
  11769. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  11770. {
  11771. return PASS;
  11772. }
  11773. else
  11774. {
  11775. return FAIL;
  11776. }
  11777. }
  11778. void StoreConfigurationTable(void)
  11779. {
  11780. FILE *outfile;
  11781. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  11782. if(outfile == NULL)
  11783. {
  11784. DEBUG_INFO("Error opening file");
  11785. return ;
  11786. }
  11787. /*Core Profile*/
  11788. //AllowOfflineTxForUnknownId
  11789. /*
  11790. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11791. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  11792. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11793. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  11794. */
  11795. //DEBUG_INFO("data=%s\n",data);
  11796. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11797. //AuthorizationCacheEnabled
  11798. /*
  11799. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11800. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11801. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11802. */
  11803. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11804. //AuthorizeRemoteTxRequests
  11805. /*
  11806. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11807. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11808. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  11809. */
  11810. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11811. //BlinkRepeat
  11812. /*
  11813. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11814. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11815. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11816. */
  11817. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11818. //ClockAlignedDataInterval
  11819. /*
  11820. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11821. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11822. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11823. */
  11824. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11825. //ConnectionTimeOut
  11826. /*
  11827. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11828. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11829. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11830. */
  11831. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11832. //GetConfigurationMaxKeys
  11833. /*
  11834. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11835. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11836. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  11837. */
  11838. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11839. // HeartbeatInterval
  11840. /*
  11841. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11842. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11843. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  11844. */
  11845. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11846. // LightIntensity
  11847. /*
  11848. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11849. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11850. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11851. */
  11852. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11853. // LocalAuthorizeOffline
  11854. /*
  11855. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  11856. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  11857. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  11858. */
  11859. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11860. // LocalPreAuthorize
  11861. /*
  11862. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  11863. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  11864. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  11865. */
  11866. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  11867. // MaxEnergyOnInvalidId
  11868. /*
  11869. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  11870. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  11871. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  11872. */
  11873. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  11874. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  11875. // MeterValuesAlignedData
  11876. /*
  11877. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  11878. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  11879. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  11880. */
  11881. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  11882. // MeterValuesAlignedDataMaxLength
  11883. /*
  11884. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  11885. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  11886. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  11887. */
  11888. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  11889. // MeterValuesSampledData
  11890. /*
  11891. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  11892. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  11893. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  11894. */
  11895. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  11896. // MeterValuesSampledDataMaxLength
  11897. /*
  11898. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  11899. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  11900. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  11901. */
  11902. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  11903. // MeterValueSampleInterval
  11904. /*
  11905. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  11906. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  11907. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  11908. */
  11909. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  11910. // MinimumStatusDuration
  11911. /*
  11912. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  11913. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  11914. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  11915. */
  11916. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  11917. // NumberOfConnectors
  11918. /*
  11919. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  11920. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  11921. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11922. {
  11923. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  11924. }
  11925. else
  11926. {
  11927. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  11928. }
  11929. */
  11930. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  11931. // ResetRetries
  11932. /*
  11933. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  11934. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  11935. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  11936. */
  11937. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  11938. // ConnectorPhaseRotation
  11939. /*
  11940. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  11941. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  11942. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  11943. */
  11944. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  11945. // ConnectorPhaseRotationMaxLength
  11946. /*
  11947. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  11948. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  11949. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  11950. */
  11951. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  11952. // StopTransactionOnEVSideDisconnect
  11953. /*
  11954. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  11955. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  11956. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  11957. */
  11958. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  11959. // StopTransactionOnInvalidId
  11960. /*
  11961. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  11962. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  11963. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  11964. */
  11965. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  11966. // StopTxnAlignedData
  11967. /*
  11968. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  11969. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  11970. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  11971. */
  11972. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  11973. // StopTxnAlignedDataMaxLength
  11974. /*
  11975. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  11976. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  11977. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  11978. */
  11979. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  11980. // StopTxnSampledData
  11981. /*
  11982. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  11983. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  11984. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  11985. */
  11986. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  11987. // StopTxnSampledDataMaxLength
  11988. /*
  11989. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  11990. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  11991. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  11992. */
  11993. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  11994. // SupportedFeatureProfiles
  11995. /*
  11996. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  11997. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  11998. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  11999. */
  12000. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12001. // SupportedFeatureProfilesMaxLength
  12002. /*
  12003. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12004. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12005. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12006. */
  12007. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12008. // TransactionMessageAttempts
  12009. /*
  12010. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12011. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12012. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12013. */
  12014. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12015. // TransactionMessageRetryInterval
  12016. /*
  12017. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12018. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12019. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  12020. */
  12021. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12022. // UnlockConnectorOnEVSideDisconnect
  12023. /*
  12024. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  12025. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  12026. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  12027. */
  12028. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  12029. // WebSocketPingInterval
  12030. /*
  12031. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  12032. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  12033. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  12034. */
  12035. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  12036. // QueueOffLineStartTransactionMessage
  12037. /*
  12038. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  12039. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  12040. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  12041. */
  12042. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  12043. // AuthorizationKey
  12044. /*
  12045. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12046. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12047. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  12048. */
  12049. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12050. // SecurityProfile
  12051. /*
  12052. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12053. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12054. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  12055. */
  12056. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12057. // DefaultPrice
  12058. /*
  12059. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12060. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12061. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12062. */
  12063. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12064. // CustomDisplayCostAndPrice
  12065. /*
  12066. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12067. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12068. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12069. */
  12070. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12071. // CustomIdleFeeAfterStop
  12072. /*
  12073. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12074. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12075. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12076. */
  12077. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12078. // ConfigurationVersion
  12079. /*
  12080. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  12081. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12082. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  12083. */
  12084. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12085. //* Local Auth List Management Profile*/
  12086. //LocalAuthListEnabled
  12087. /*
  12088. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12089. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12090. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12091. */
  12092. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12093. //LocalAuthListMaxLength
  12094. /*
  12095. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12096. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12097. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  12098. */
  12099. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12100. //SendLocalListMaxLength
  12101. /*
  12102. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12103. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  12105. */
  12106. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12107. //ReserveConnectorZeroSupported
  12108. /*
  12109. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12110. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12112. */
  12113. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12114. //* Smart Charging Profile */
  12115. //ChargeProfileMaxStackLevel
  12116. /*
  12117. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12118. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12119. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12120. */
  12121. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12122. // ChargingScheduleAllowedChargingRateUnit
  12123. /*
  12124. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12125. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12126. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  12127. */
  12128. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12129. // ChargingScheduleMaxPeriods
  12130. /*
  12131. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12132. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12134. */
  12135. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12136. // ConnectorSwitch3to1PhaseSupported
  12137. /*
  12138. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  12139. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  12140. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  12141. */
  12142. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12143. // MaxChargingProfilesInstalled
  12144. /*
  12145. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  12146. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  12147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  12148. */
  12149. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12150. fclose(outfile);
  12151. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12152. }
  12153. void getKeyValue(char *keyReq)
  12154. {
  12155. int isEmpty = FALSE;
  12156. int isKnowKey = FALSE;
  12157. DEBUG_INFO("keyReq = %s\n", keyReq);
  12158. if((keyReq == NULL) || (strlen(keyReq) == 0))
  12159. isEmpty = TRUE;
  12160. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  12161. {
  12162. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  12163. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  12164. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  12165. {
  12166. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  12167. }
  12168. else
  12169. {
  12170. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  12171. }
  12172. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  12173. isKnowKey = TRUE;
  12174. }
  12175. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  12176. {
  12177. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  12178. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  12179. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  12180. {
  12181. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  12182. }
  12183. else
  12184. {
  12185. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  12186. }
  12187. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  12188. isKnowKey = TRUE;
  12189. }
  12190. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  12191. {
  12192. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  12193. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  12194. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  12195. {
  12196. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  12197. }
  12198. else
  12199. {
  12200. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  12201. }
  12202. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  12203. isKnowKey = TRUE;
  12204. }
  12205. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  12206. {
  12207. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  12208. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  12209. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  12210. {
  12211. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  12212. }
  12213. else
  12214. {
  12215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  12216. }
  12217. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  12218. isKnowKey = TRUE;
  12219. }
  12220. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  12221. {
  12222. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  12223. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  12224. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  12225. {
  12226. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  12227. }
  12228. else
  12229. {
  12230. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  12231. }
  12232. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  12233. isKnowKey = TRUE;
  12234. }
  12235. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  12236. {
  12237. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  12238. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  12239. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  12240. {
  12241. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  12242. }
  12243. else
  12244. {
  12245. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  12246. }
  12247. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  12248. isKnowKey = TRUE;
  12249. }
  12250. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  12251. {
  12252. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  12253. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  12254. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  12255. {
  12256. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  12257. }
  12258. else
  12259. {
  12260. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  12261. }
  12262. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  12263. isKnowKey = TRUE;
  12264. }
  12265. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  12266. {
  12267. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  12268. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  12269. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  12270. {
  12271. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  12272. }
  12273. else
  12274. {
  12275. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  12276. }
  12277. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  12278. isKnowKey = TRUE;
  12279. }
  12280. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  12281. {
  12282. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  12283. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  12284. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  12285. {
  12286. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  12287. }
  12288. else
  12289. {
  12290. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  12291. }
  12292. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  12293. isKnowKey = TRUE;
  12294. }
  12295. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  12296. {
  12297. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  12298. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  12299. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  12300. {
  12301. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  12302. }
  12303. else
  12304. {
  12305. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  12306. }
  12307. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  12308. isKnowKey = TRUE;
  12309. }
  12310. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  12311. {
  12312. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  12313. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  12314. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  12315. {
  12316. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  12317. }
  12318. else
  12319. {
  12320. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  12321. }
  12322. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  12323. isKnowKey = TRUE;
  12324. }
  12325. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  12326. {
  12327. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  12328. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  12329. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  12330. {
  12331. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  12332. }
  12333. else
  12334. {
  12335. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  12336. }
  12337. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  12338. isKnowKey = TRUE;
  12339. }
  12340. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  12341. {
  12342. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  12343. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  12344. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  12345. {
  12346. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  12347. }
  12348. else
  12349. {
  12350. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  12351. }
  12352. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  12353. isKnowKey = TRUE;
  12354. }
  12355. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  12356. {
  12357. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  12358. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  12359. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  12360. {
  12361. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12362. }
  12363. else
  12364. {
  12365. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12366. }
  12367. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  12368. isKnowKey = TRUE;
  12369. }
  12370. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  12371. {
  12372. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  12373. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  12374. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  12375. {
  12376. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  12377. }
  12378. else
  12379. {
  12380. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  12381. }
  12382. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  12383. isKnowKey = TRUE;
  12384. }
  12385. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  12386. {
  12387. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  12388. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  12389. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  12390. {
  12391. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12392. }
  12393. else
  12394. {
  12395. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12396. }
  12397. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  12398. isKnowKey = TRUE;
  12399. }
  12400. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  12401. {
  12402. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  12403. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  12404. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12405. {
  12406. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  12407. }
  12408. else
  12409. {
  12410. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  12411. }
  12412. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  12413. isKnowKey = TRUE;
  12414. }
  12415. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  12416. {
  12417. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  12418. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  12419. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12420. {
  12421. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  12422. }
  12423. else
  12424. {
  12425. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  12426. }
  12427. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  12428. isKnowKey = TRUE;
  12429. }
  12430. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  12431. {
  12432. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  12433. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  12434. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12435. {
  12436. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  12437. }
  12438. else
  12439. {
  12440. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  12441. }
  12442. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  12443. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  12444. isKnowKey = TRUE;
  12445. }
  12446. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  12447. {
  12448. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  12449. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  12450. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12451. {
  12452. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  12453. }
  12454. else
  12455. {
  12456. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  12457. }
  12458. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  12459. isKnowKey = TRUE;
  12460. }
  12461. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  12462. {
  12463. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  12464. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  12465. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12466. {
  12467. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  12468. }
  12469. else
  12470. {
  12471. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  12472. }
  12473. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  12474. isKnowKey = TRUE;
  12475. }
  12476. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  12477. {
  12478. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  12479. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  12480. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12481. {
  12482. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12483. }
  12484. else
  12485. {
  12486. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12487. }
  12488. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  12489. isKnowKey = TRUE;
  12490. }
  12491. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  12492. {
  12493. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  12494. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  12495. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12496. {
  12497. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  12498. }
  12499. else
  12500. {
  12501. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  12502. }
  12503. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  12504. isKnowKey = TRUE;
  12505. }
  12506. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  12507. {
  12508. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  12509. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  12510. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12511. {
  12512. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  12513. }
  12514. else
  12515. {
  12516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  12517. }
  12518. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  12519. isKnowKey = TRUE;
  12520. }
  12521. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  12522. {
  12523. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  12524. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  12525. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12526. {
  12527. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  12528. }
  12529. else
  12530. {
  12531. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  12532. }
  12533. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  12534. isKnowKey = TRUE;
  12535. }
  12536. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  12537. {
  12538. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  12539. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  12540. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12541. {
  12542. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12543. }
  12544. else
  12545. {
  12546. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12547. }
  12548. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  12549. isKnowKey = TRUE;
  12550. }
  12551. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  12552. {
  12553. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  12554. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  12555. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12556. {
  12557. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  12558. }
  12559. else
  12560. {
  12561. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  12562. }
  12563. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  12564. isKnowKey = TRUE;
  12565. }
  12566. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  12567. {
  12568. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  12569. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  12570. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12571. {
  12572. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12573. }
  12574. else
  12575. {
  12576. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12577. }
  12578. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  12579. isKnowKey = TRUE;
  12580. }
  12581. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  12582. {
  12583. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  12584. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  12585. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12586. {
  12587. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  12588. }
  12589. else
  12590. {
  12591. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  12592. }
  12593. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  12594. isKnowKey = TRUE;
  12595. }
  12596. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  12597. {
  12598. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  12599. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  12600. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12601. {
  12602. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12603. }
  12604. else
  12605. {
  12606. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12607. }
  12608. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  12609. isKnowKey = TRUE;
  12610. }
  12611. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  12612. {
  12613. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  12614. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  12615. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12616. {
  12617. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  12618. }
  12619. else
  12620. {
  12621. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  12622. }
  12623. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  12624. isKnowKey = TRUE;
  12625. }
  12626. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  12627. {
  12628. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  12629. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  12630. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12631. {
  12632. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  12633. }
  12634. else
  12635. {
  12636. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  12637. }
  12638. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  12639. isKnowKey = TRUE;
  12640. }
  12641. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  12642. {
  12643. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  12644. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  12645. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12646. {
  12647. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  12648. }
  12649. else
  12650. {
  12651. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  12652. }
  12653. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  12654. isKnowKey = TRUE;
  12655. }
  12656. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  12657. {
  12658. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  12659. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  12660. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12661. {
  12662. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  12663. }
  12664. else
  12665. {
  12666. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  12667. }
  12668. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  12669. isKnowKey = TRUE;
  12670. }
  12671. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  12672. {
  12673. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  12674. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  12675. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12676. {
  12677. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  12678. }
  12679. else
  12680. {
  12681. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  12682. }
  12683. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  12684. isKnowKey = TRUE;
  12685. }
  12686. /*
  12687. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  12688. {
  12689. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  12690. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  12691. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  12692. {
  12693. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  12694. }
  12695. else
  12696. {
  12697. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  12698. }
  12699. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  12700. isKnowKey = TRUE;
  12701. }*/
  12702. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  12703. {
  12704. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  12705. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  12706. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  12707. {
  12708. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  12709. }
  12710. else
  12711. {
  12712. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  12713. }
  12714. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  12715. isKnowKey = TRUE;
  12716. }
  12717. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  12718. {
  12719. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  12720. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  12721. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  12722. {
  12723. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  12724. }
  12725. else
  12726. {
  12727. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  12728. }
  12729. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  12730. isKnowKey = TRUE;
  12731. }
  12732. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  12733. {
  12734. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  12735. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  12736. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  12737. {
  12738. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  12739. }
  12740. else
  12741. {
  12742. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  12743. }
  12744. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  12745. isKnowKey = TRUE;
  12746. }
  12747. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  12748. {
  12749. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  12750. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  12751. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  12752. {
  12753. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  12754. }
  12755. else
  12756. {
  12757. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  12758. }
  12759. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  12760. isKnowKey = TRUE;
  12761. }
  12762. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  12763. {
  12764. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  12765. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  12766. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  12767. {
  12768. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  12769. }
  12770. else
  12771. {
  12772. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  12773. }
  12774. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  12775. isKnowKey = TRUE;
  12776. }
  12777. #if 1
  12778. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  12779. {
  12780. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  12781. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  12782. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12783. {
  12784. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  12785. }
  12786. else
  12787. {
  12788. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  12789. }
  12790. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  12791. isKnowKey = TRUE;
  12792. }
  12793. #endif
  12794. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  12795. {
  12796. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  12797. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  12798. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12799. {
  12800. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12801. }
  12802. else
  12803. {
  12804. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12805. }
  12806. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  12807. isKnowKey = TRUE;
  12808. }
  12809. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  12810. {
  12811. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  12812. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  12813. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12814. {
  12815. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12816. }
  12817. else
  12818. {
  12819. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12820. }
  12821. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  12822. isKnowKey = TRUE;
  12823. }
  12824. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  12825. {
  12826. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  12827. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  12828. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12829. {
  12830. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  12831. }
  12832. else
  12833. {
  12834. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  12835. }
  12836. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12837. isKnowKey = TRUE;
  12838. }
  12839. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  12840. {
  12841. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  12842. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  12843. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12844. {
  12845. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  12846. }
  12847. else
  12848. {
  12849. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  12850. }
  12851. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12852. isKnowKey = TRUE;
  12853. }
  12854. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  12855. {
  12856. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  12857. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  12858. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12859. {
  12860. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  12861. }
  12862. else
  12863. {
  12864. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  12865. }
  12866. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12867. isKnowKey = TRUE;
  12868. }
  12869. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  12870. {
  12871. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  12872. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  12873. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12874. {
  12875. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  12876. }
  12877. else
  12878. {
  12879. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  12880. }
  12881. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12882. isKnowKey = TRUE;
  12883. }
  12884. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  12885. {
  12886. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  12887. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  12888. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12889. {
  12890. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  12891. }
  12892. else
  12893. {
  12894. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  12895. }
  12896. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12897. isKnowKey = TRUE;
  12898. }
  12899. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  12900. {
  12901. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  12902. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  12903. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12904. {
  12905. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  12906. }
  12907. else
  12908. {
  12909. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  12910. }
  12911. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12912. isKnowKey = TRUE;
  12913. }
  12914. //=========================================================
  12915. if(!isEmpty && !isKnowKey)
  12916. {
  12917. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  12918. strcpy(unknownkey[UnknownKeynum], keyReq);
  12919. UnknownKeynum = UnknownKeynum + 1;
  12920. }
  12921. }
  12922. void processUnkownKey(void)
  12923. {
  12924. DEBUG_INFO("processUnkownKey...\n");
  12925. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  12926. for(int index=0; index < UnknownKeynum; index++)
  12927. {
  12928. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  12929. {
  12930. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  12931. }
  12932. }
  12933. }
  12934. int setKeyValue(char *key, char *value)
  12935. {
  12936. int isSuccess = NotSupported;
  12937. int check_ascii=0;
  12938. char str[256]={0};
  12939. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  12940. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  12941. {
  12942. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  12943. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  12944. {
  12945. strcpy(str, (const char*)value);
  12946. for(int i = 0; str[i]; i++){
  12947. str[i] = tolower(str[i]);
  12948. }
  12949. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12950. isSuccess = ConfigurationStatus_Accepted;
  12951. }
  12952. else
  12953. {
  12954. isSuccess = ConfigurationStatus_Rejected;
  12955. }
  12956. }
  12957. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  12958. {
  12959. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  12960. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  12961. {
  12962. strcpy(str, (const char*)value);
  12963. for(int i = 0; str[i]; i++){
  12964. str[i] = tolower(str[i]);
  12965. }
  12966. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12967. isSuccess = ConfigurationStatus_Accepted;
  12968. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  12969. }
  12970. else
  12971. {
  12972. isSuccess = ConfigurationStatus_Rejected;
  12973. }
  12974. }
  12975. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  12976. {
  12977. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].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. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  12985. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12986. isSuccess = ConfigurationStatus_Accepted;
  12987. }
  12988. else
  12989. {
  12990. isSuccess = ConfigurationStatus_Rejected;
  12991. }
  12992. }
  12993. if(strcmp(key, "BlinkRepeat") == 0)
  12994. {
  12995. //Charger.BlinkRepeat = Integer.parseInt(value);
  12996. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  12997. {
  12998. check_ascii = value[0];
  12999. if( (check_ascii < 48) || (check_ascii > 57) )
  13000. {
  13001. isSuccess = ConfigurationStatus_Rejected;
  13002. }
  13003. else
  13004. {
  13005. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  13006. isSuccess = ConfigurationStatus_Accepted;
  13007. }
  13008. }
  13009. else
  13010. {
  13011. isSuccess = ConfigurationStatus_Rejected;
  13012. }
  13013. }
  13014. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  13015. {
  13016. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  13017. {
  13018. check_ascii = value[0];
  13019. if( (check_ascii < 48) || (check_ascii > 57) )
  13020. {
  13021. isSuccess = ConfigurationStatus_Rejected;
  13022. }
  13023. else
  13024. {
  13025. if((atoi(value) == 0) || (atoi(value) >= 10))
  13026. {
  13027. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  13028. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  13029. isSuccess = ConfigurationStatus_Accepted;
  13030. }
  13031. else
  13032. isSuccess = ConfigurationStatus_Rejected;
  13033. }
  13034. }
  13035. else
  13036. {
  13037. isSuccess = ConfigurationStatus_Rejected;
  13038. }
  13039. }
  13040. if(strcmp(key, "ConnectionTimeOut") == 0 )
  13041. {
  13042. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  13043. {
  13044. check_ascii = value[0];
  13045. if( (check_ascii < 48) || (check_ascii > 57) )
  13046. {
  13047. isSuccess = ConfigurationStatus_Rejected;
  13048. }
  13049. else
  13050. {
  13051. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  13052. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  13053. isSuccess = ConfigurationStatus_Accepted;
  13054. }
  13055. }
  13056. else
  13057. {
  13058. isSuccess = ConfigurationStatus_Rejected;
  13059. }
  13060. }
  13061. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  13062. {
  13063. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  13064. {
  13065. check_ascii = value[0];
  13066. if( (check_ascii < 48) || (check_ascii > 57) )
  13067. {
  13068. isSuccess = ConfigurationStatus_Rejected;
  13069. }
  13070. else
  13071. {
  13072. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13073. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  13074. isSuccess = ConfigurationStatus_Accepted;
  13075. }
  13076. }
  13077. else
  13078. {
  13079. isSuccess = ConfigurationStatus_Rejected;
  13080. }
  13081. }
  13082. if(strcmp(key, "HeartbeatInterval") == 0)
  13083. {
  13084. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13085. {
  13086. check_ascii = value[0];
  13087. if( (check_ascii < 48) || (check_ascii > 57) )
  13088. {
  13089. isSuccess = ConfigurationStatus_Rejected;
  13090. }
  13091. else
  13092. {
  13093. if((atoi(value) == 0) || (atoi(value) >= 10))
  13094. {
  13095. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13096. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  13097. HeartBeatWaitTime = atoi(value);
  13098. isSuccess = ConfigurationStatus_Accepted;
  13099. }
  13100. else
  13101. {
  13102. isSuccess = ConfigurationStatus_Rejected;
  13103. }
  13104. }
  13105. }
  13106. else
  13107. {
  13108. isSuccess = ConfigurationStatus_Rejected;
  13109. }
  13110. }
  13111. if(strcmp(key, "LightIntensity") == 0)
  13112. {
  13113. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13114. {
  13115. check_ascii = value[0];
  13116. if( (check_ascii < 48) || (check_ascii > 57) )
  13117. {
  13118. isSuccess = ConfigurationStatus_Rejected;
  13119. }
  13120. else
  13121. {
  13122. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  13123. isSuccess = ConfigurationStatus_Accepted;
  13124. }
  13125. }
  13126. else
  13127. {
  13128. isSuccess = ConfigurationStatus_Rejected;
  13129. }
  13130. }
  13131. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  13132. {
  13133. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  13134. {
  13135. strcpy(str, (const char*)value);
  13136. for(int i = 0; str[i]; i++)
  13137. {
  13138. str[i] = tolower(str[i]);
  13139. }
  13140. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13141. isSuccess = ConfigurationStatus_Accepted;
  13142. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13143. }
  13144. else
  13145. {
  13146. isSuccess = ConfigurationStatus_Rejected;
  13147. }
  13148. }
  13149. if(strcmp(key, "LocalPreAuthorize") == 0)
  13150. {
  13151. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  13152. {
  13153. strcpy(str, (const char*)value);
  13154. for(int i = 0; str[i]; i++)
  13155. {
  13156. str[i] = tolower(str[i]);
  13157. }
  13158. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13159. isSuccess = ConfigurationStatus_Accepted;
  13160. }
  13161. else
  13162. {
  13163. isSuccess = ConfigurationStatus_Rejected;
  13164. }
  13165. }
  13166. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  13167. {
  13168. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  13169. {
  13170. check_ascii = value[0];
  13171. if( (check_ascii < 48) || (check_ascii > 57) )
  13172. {
  13173. isSuccess = ConfigurationStatus_Rejected;
  13174. }
  13175. else
  13176. {
  13177. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  13178. isSuccess = ConfigurationStatus_Accepted;
  13179. }
  13180. }
  13181. else
  13182. {
  13183. isSuccess = ConfigurationStatus_Rejected;
  13184. }
  13185. }
  13186. if(strcmp(key, "MeterValuesAlignedData") == 0)
  13187. {
  13188. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13189. {
  13190. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  13191. isSuccess = ConfigurationStatus_Accepted;
  13192. }
  13193. else
  13194. {
  13195. isSuccess = ConfigurationStatus_Rejected;
  13196. }
  13197. }
  13198. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  13199. {
  13200. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13201. {
  13202. check_ascii = value[0];
  13203. if( (check_ascii < 48) || (check_ascii > 57) )
  13204. {
  13205. isSuccess = ConfigurationStatus_Rejected;
  13206. }
  13207. else
  13208. {
  13209. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13210. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  13211. isSuccess = ConfigurationStatus_Accepted;
  13212. }
  13213. }
  13214. else
  13215. {
  13216. isSuccess = ConfigurationStatus_Rejected;
  13217. }
  13218. }
  13219. if(strcmp(key, "MeterValuesSampledData") == 0 )
  13220. {
  13221. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  13222. {
  13223. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  13224. isSuccess = ConfigurationStatus_Accepted;
  13225. }
  13226. else
  13227. {
  13228. isSuccess = ConfigurationStatus_Rejected;
  13229. }
  13230. }
  13231. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  13232. {
  13233. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  13234. {
  13235. check_ascii = value[0];
  13236. if( (check_ascii < 48) || (check_ascii > 57) )
  13237. {
  13238. isSuccess = ConfigurationStatus_Rejected;
  13239. }
  13240. else
  13241. {
  13242. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13243. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  13244. isSuccess = ConfigurationStatus_Accepted;
  13245. }
  13246. }
  13247. else
  13248. {
  13249. isSuccess = ConfigurationStatus_Rejected;
  13250. }
  13251. }
  13252. if(strcmp(key, "MeterValueSampleInterval") == 0)
  13253. {
  13254. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  13255. {
  13256. check_ascii = value[0];
  13257. if( (check_ascii < 48) || (check_ascii > 57) )
  13258. {
  13259. isSuccess = ConfigurationStatus_Rejected;
  13260. }
  13261. else
  13262. {
  13263. if((atoi(value) == 0) || (atoi(value) >= 10))
  13264. {
  13265. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13266. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  13267. isSuccess = ConfigurationStatus_Accepted;
  13268. }
  13269. else
  13270. {
  13271. isSuccess = ConfigurationStatus_Rejected;
  13272. }
  13273. }
  13274. }
  13275. else
  13276. {
  13277. isSuccess = ConfigurationStatus_Rejected;
  13278. }
  13279. }
  13280. if(strcmp(key, "MinimumStatusDuration") == 0)
  13281. {
  13282. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  13283. {
  13284. check_ascii = value[0];
  13285. if( (check_ascii < 48) || (check_ascii > 57) )
  13286. {
  13287. isSuccess = ConfigurationStatus_Rejected;
  13288. }
  13289. else
  13290. {
  13291. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  13292. {
  13293. isSuccess = ConfigurationStatus_Rejected;
  13294. }
  13295. else
  13296. {
  13297. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  13298. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  13299. server_cycle_Status = atoi(value); //StatusNotification Cycle
  13300. isSuccess = ConfigurationStatus_Accepted;
  13301. }
  13302. }
  13303. }
  13304. else
  13305. {
  13306. isSuccess = ConfigurationStatus_Rejected;
  13307. }
  13308. }
  13309. if(strcmp(key, "NumberOfConnectors") == 0)
  13310. {
  13311. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  13312. {
  13313. check_ascii = value[0];
  13314. if( (check_ascii < 48) || (check_ascii > 57) )
  13315. {
  13316. isSuccess = ConfigurationStatus_Rejected;
  13317. }
  13318. else
  13319. {
  13320. //Charger.ResetRetries = Integer.parseInt(value);
  13321. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  13322. isSuccess = ConfigurationStatus_Accepted;
  13323. }
  13324. }
  13325. else
  13326. {
  13327. isSuccess = ConfigurationStatus_Rejected;
  13328. }
  13329. }
  13330. if(strcmp(key, "ResetRetries") == 0)
  13331. {
  13332. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  13333. {
  13334. check_ascii = value[0];
  13335. if( (check_ascii < 48) || (check_ascii > 57) )
  13336. {
  13337. isSuccess = ConfigurationStatus_Rejected;
  13338. }
  13339. else
  13340. {
  13341. //Charger.ResetRetries = Integer.parseInt(value);
  13342. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  13343. isSuccess = ConfigurationStatus_Accepted;
  13344. }
  13345. }
  13346. else
  13347. {
  13348. isSuccess = ConfigurationStatus_Rejected;
  13349. }
  13350. }
  13351. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  13352. {
  13353. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  13354. {
  13355. strcpy(str, (const char*)value);
  13356. for(int i = 0; str[i]; i++)
  13357. {
  13358. str[i] = tolower(str[i]);
  13359. }
  13360. if(strcmp(str, "notapplicable")== 0)
  13361. {
  13362. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  13363. isSuccess = ConfigurationStatus_Accepted;
  13364. }
  13365. else if(strcmp(str, "unknown")== 0)
  13366. {
  13367. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  13368. isSuccess = ConfigurationStatus_Accepted;
  13369. }
  13370. else if(strcmp(str, "rst")== 0)
  13371. {
  13372. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  13373. isSuccess = ConfigurationStatus_Accepted;
  13374. }
  13375. else if(strcmp(str, "rts")== 0)
  13376. {
  13377. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  13378. isSuccess = ConfigurationStatus_Accepted;
  13379. }
  13380. else if(strcmp(str, "srt")== 0)
  13381. {
  13382. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  13383. isSuccess = ConfigurationStatus_Accepted;
  13384. }
  13385. else if(strcmp(str, "str")== 0)
  13386. {
  13387. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  13388. isSuccess = ConfigurationStatus_Accepted;
  13389. }
  13390. else if(strcmp(str, "trs")== 0)
  13391. {
  13392. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  13393. isSuccess = ConfigurationStatus_Accepted;
  13394. }
  13395. else if(strcmp(str, "tsr")== 0)
  13396. {
  13397. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  13398. isSuccess = ConfigurationStatus_Accepted;
  13399. }
  13400. else
  13401. {
  13402. isSuccess = ConfigurationStatus_Rejected;
  13403. }
  13404. }
  13405. else
  13406. {
  13407. isSuccess = ConfigurationStatus_Rejected;
  13408. }
  13409. }
  13410. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  13411. {
  13412. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].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. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  13422. isSuccess = ConfigurationStatus_Accepted;
  13423. }
  13424. }
  13425. else
  13426. {
  13427. isSuccess = ConfigurationStatus_Rejected;
  13428. }
  13429. }
  13430. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  13431. {
  13432. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  13433. {
  13434. strcpy(str, (const char*)value);
  13435. for(int i = 0; str[i]; i++)
  13436. {
  13437. str[i] = tolower(str[i]);
  13438. }
  13439. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  13440. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13441. isSuccess = ConfigurationStatus_Accepted;
  13442. }
  13443. else
  13444. {
  13445. isSuccess = ConfigurationStatus_Rejected;
  13446. }
  13447. }
  13448. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  13449. {
  13450. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  13451. {
  13452. strcpy(str, (const char*)value);
  13453. for(int i = 0; str[i]; i++)
  13454. {
  13455. str[i] = tolower(str[i]);
  13456. }
  13457. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  13458. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13459. isSuccess = ConfigurationStatus_Accepted;
  13460. }
  13461. else
  13462. {
  13463. isSuccess = ConfigurationStatus_Rejected;
  13464. }
  13465. }
  13466. if(strcmp(key, "StopTxnAlignedData") == 0)
  13467. {
  13468. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  13469. {
  13470. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  13471. isSuccess = ConfigurationStatus_Accepted;
  13472. }
  13473. else
  13474. {
  13475. isSuccess = ConfigurationStatus_Rejected;
  13476. }
  13477. }
  13478. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  13479. {
  13480. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  13481. {
  13482. check_ascii = value[0];
  13483. if( (check_ascii < 48) || (check_ascii > 57) )
  13484. {
  13485. isSuccess = ConfigurationStatus_Rejected;
  13486. }
  13487. else
  13488. {
  13489. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  13490. isSuccess = ConfigurationStatus_Accepted;
  13491. }
  13492. }
  13493. else
  13494. {
  13495. isSuccess = ConfigurationStatus_Rejected;
  13496. }
  13497. }
  13498. if(strcmp(key, "StopTxnSampledData") == 0)
  13499. {
  13500. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  13501. {
  13502. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  13503. isSuccess = ConfigurationStatus_Accepted;
  13504. }
  13505. else
  13506. {
  13507. isSuccess = ConfigurationStatus_Rejected;
  13508. }
  13509. }
  13510. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  13511. {
  13512. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  13513. {
  13514. check_ascii = value[0];
  13515. if( (check_ascii < 48) || (check_ascii > 57) )
  13516. {
  13517. isSuccess = ConfigurationStatus_Rejected;
  13518. }
  13519. else
  13520. {
  13521. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  13522. isSuccess = ConfigurationStatus_Accepted;
  13523. }
  13524. }
  13525. else
  13526. {
  13527. isSuccess = ConfigurationStatus_Rejected;
  13528. }
  13529. }
  13530. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  13531. {
  13532. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  13533. {
  13534. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  13535. isSuccess = ConfigurationStatus_Accepted;
  13536. }
  13537. else
  13538. {
  13539. isSuccess = ConfigurationStatus_Rejected;
  13540. }
  13541. }
  13542. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  13543. {
  13544. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  13545. {
  13546. check_ascii = value[0];
  13547. if( (check_ascii < 48) || (check_ascii > 57) )
  13548. {
  13549. isSuccess = ConfigurationStatus_Rejected;
  13550. }
  13551. else
  13552. {
  13553. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  13554. isSuccess = ConfigurationStatus_Accepted;
  13555. }
  13556. }
  13557. else
  13558. {
  13559. isSuccess = ConfigurationStatus_Rejected;
  13560. }
  13561. }
  13562. if(strcmp(key, "TransactionMessageAttempts") == 0)
  13563. {
  13564. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  13565. {
  13566. check_ascii = value[0];
  13567. if( (check_ascii < 48) || (check_ascii > 57) )
  13568. {
  13569. isSuccess = ConfigurationStatus_Rejected;
  13570. }
  13571. else
  13572. {
  13573. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  13574. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  13575. TransactionMessageAttemptsValue = atoi(value);
  13576. isSuccess = ConfigurationStatus_Accepted;
  13577. }
  13578. }
  13579. else
  13580. {
  13581. isSuccess = ConfigurationStatus_Rejected;
  13582. }
  13583. }
  13584. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  13585. {
  13586. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  13587. {
  13588. check_ascii = value[0];
  13589. if( (check_ascii < 48) || (check_ascii > 57) )
  13590. {
  13591. isSuccess = ConfigurationStatus_Rejected;
  13592. }
  13593. else
  13594. {
  13595. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  13596. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  13597. TransactionMessageRetryIntervalValue = atoi(value);
  13598. isSuccess = ConfigurationStatus_Accepted;
  13599. }
  13600. }
  13601. else
  13602. {
  13603. isSuccess = ConfigurationStatus_Rejected;
  13604. }
  13605. }
  13606. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  13607. {
  13608. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  13609. {
  13610. strcpy(str, (const char*)value);
  13611. for(int i = 0; str[i]; i++)
  13612. {
  13613. str[i] = tolower(str[i]);
  13614. }
  13615. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  13616. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13617. isSuccess = ConfigurationStatus_Accepted;
  13618. }
  13619. else
  13620. {
  13621. isSuccess = ConfigurationStatus_Rejected;
  13622. }
  13623. }
  13624. if(strcmp(key, "WebSocketPingInterval") == 0)
  13625. {
  13626. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  13627. {
  13628. check_ascii = value[0];
  13629. if( (check_ascii < 48) || (check_ascii > 57) )
  13630. {
  13631. isSuccess = ConfigurationStatus_Rejected;
  13632. }
  13633. else
  13634. {
  13635. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  13636. isSuccess = ConfigurationStatus_Accepted;
  13637. }
  13638. }
  13639. else
  13640. {
  13641. isSuccess = ConfigurationStatus_Rejected;
  13642. }
  13643. }
  13644. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  13645. {
  13646. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  13647. {
  13648. strcpy(str, (const char*)value);
  13649. for(int i = 0; str[i]; i++)
  13650. {
  13651. str[i] = tolower(str[i]);
  13652. }
  13653. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13654. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13655. isSuccess = ConfigurationStatus_Accepted;
  13656. }
  13657. else
  13658. {
  13659. isSuccess = ConfigurationStatus_Rejected;
  13660. }
  13661. }
  13662. if(strcmp(key, "AuthorizationKey") == 0)
  13663. {
  13664. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  13665. {
  13666. strcpy(str, (const char*)value);
  13667. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  13668. isSuccess = ConfigurationStatus_Accepted;
  13669. }
  13670. else
  13671. {
  13672. isSuccess = ConfigurationStatus_Rejected;
  13673. }
  13674. }
  13675. if(strcmp(key, "SecurityProfile") == 0)
  13676. {
  13677. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  13678. {
  13679. check_ascii = value[0];
  13680. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  13681. {
  13682. isSuccess = ConfigurationStatus_Rejected;
  13683. }
  13684. else if(check_ascii == 0x33)
  13685. {
  13686. isSuccess = NotSupported;
  13687. }
  13688. else
  13689. {
  13690. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  13691. {
  13692. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  13693. isSuccess = ConfigurationStatus_Accepted;
  13694. }
  13695. else
  13696. isSuccess = ConfigurationStatus_Rejected;
  13697. }
  13698. }
  13699. else
  13700. {
  13701. isSuccess = ConfigurationStatus_Rejected;
  13702. }
  13703. }
  13704. if(strcmp(key, "DefaultPrice") == 0)
  13705. {
  13706. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  13707. {
  13708. strcpy(str, (const char*)value);
  13709. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  13710. isSuccess = ConfigurationStatus_Accepted;
  13711. }
  13712. else
  13713. {
  13714. isSuccess = ConfigurationStatus_Rejected;
  13715. }
  13716. }
  13717. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  13718. {
  13719. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  13720. {
  13721. strcpy(str, (const char*)value);
  13722. for(int i = 0; str[i]; i++)
  13723. {
  13724. str[i] = tolower(str[i]);
  13725. }
  13726. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13727. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13728. isSuccess = ConfigurationStatus_Accepted;
  13729. }
  13730. else
  13731. {
  13732. isSuccess = ConfigurationStatus_Rejected;
  13733. }
  13734. }
  13735. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  13736. {
  13737. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  13738. {
  13739. strcpy(str, (const char*)value);
  13740. for(int i = 0; str[i]; i++)
  13741. {
  13742. str[i] = tolower(str[i]);
  13743. }
  13744. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13745. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13746. isSuccess = ConfigurationStatus_Accepted;
  13747. }
  13748. else
  13749. {
  13750. isSuccess = ConfigurationStatus_Rejected;
  13751. }
  13752. }
  13753. #if 0
  13754. //For OCPP Test Case
  13755. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  13756. {
  13757. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13758. {
  13759. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  13760. isSuccess = ConfigurationStatus_Accepted;
  13761. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13762. }
  13763. else
  13764. {
  13765. isSuccess = ConfigurationStatus_Rejected;
  13766. }
  13767. }
  13768. #endif
  13769. #if 1
  13770. if(strcmp(key, "LocalAuthListEnabled") == 0)
  13771. {
  13772. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13773. {
  13774. strcpy(str, (const char*)value);
  13775. for(int i = 0; str[i]; i++)
  13776. {
  13777. str[i] = tolower(str[i]);
  13778. }
  13779. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13780. isSuccess = ConfigurationStatus_Accepted;
  13781. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13782. }
  13783. else
  13784. {
  13785. isSuccess = ConfigurationStatus_Rejected;
  13786. }
  13787. }
  13788. #endif
  13789. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  13790. {
  13791. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  13792. {
  13793. check_ascii = value[0];
  13794. if( (check_ascii < 48) || (check_ascii > 57) )
  13795. {
  13796. isSuccess = ConfigurationStatus_Rejected;
  13797. }
  13798. else
  13799. {
  13800. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  13801. isSuccess = ConfigurationStatus_Accepted;
  13802. }
  13803. }
  13804. else
  13805. {
  13806. isSuccess = ConfigurationStatus_Rejected;
  13807. }
  13808. }
  13809. if(strcmp(key, "SendLocalListMaxLength") == 0)
  13810. {
  13811. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  13812. {
  13813. check_ascii = value[0];
  13814. if( (check_ascii < 48) || (check_ascii > 57) )
  13815. {
  13816. isSuccess = ConfigurationStatus_Rejected;
  13817. }
  13818. else
  13819. {
  13820. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  13821. isSuccess = ConfigurationStatus_Accepted;
  13822. }
  13823. }
  13824. else
  13825. {
  13826. isSuccess = ConfigurationStatus_Rejected;
  13827. }
  13828. }
  13829. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  13830. {
  13831. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  13832. {
  13833. strcpy(str, (const char*)value);
  13834. for(int i = 0; str[i]; i++)
  13835. {
  13836. str[i] = tolower(str[i]);
  13837. }
  13838. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13839. isSuccess = ConfigurationStatus_Accepted;
  13840. }
  13841. else
  13842. {
  13843. isSuccess = ConfigurationStatus_Rejected;
  13844. }
  13845. }
  13846. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  13847. {
  13848. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  13849. {
  13850. check_ascii = value[0];
  13851. if( (check_ascii < 48) || (check_ascii > 57) )
  13852. {
  13853. isSuccess = ConfigurationStatus_Rejected;
  13854. }
  13855. else
  13856. {
  13857. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  13858. isSuccess = ConfigurationStatus_Accepted;
  13859. }
  13860. }
  13861. else
  13862. {
  13863. isSuccess = ConfigurationStatus_Rejected;
  13864. }
  13865. }
  13866. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  13867. {
  13868. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  13869. {
  13870. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  13871. isSuccess = ConfigurationStatus_Accepted;
  13872. }
  13873. else
  13874. {
  13875. isSuccess = ConfigurationStatus_Rejected;
  13876. }
  13877. }
  13878. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  13879. {
  13880. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  13881. {
  13882. check_ascii = value[0];
  13883. if( (check_ascii < 48) || (check_ascii > 57) )
  13884. {
  13885. isSuccess = ConfigurationStatus_Rejected;
  13886. }
  13887. else
  13888. {
  13889. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  13890. isSuccess = ConfigurationStatus_Accepted;
  13891. }
  13892. }
  13893. else
  13894. {
  13895. isSuccess = ConfigurationStatus_Rejected;
  13896. }
  13897. }
  13898. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  13899. {
  13900. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  13901. {
  13902. strcpy(str, (const char*)value);
  13903. for(int i = 0; str[i]; i++)
  13904. {
  13905. str[i] = tolower(str[i]);
  13906. }
  13907. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13908. isSuccess = ConfigurationStatus_Accepted;
  13909. }
  13910. else
  13911. {
  13912. isSuccess = ConfigurationStatus_Rejected;
  13913. }
  13914. }
  13915. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  13916. {
  13917. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  13918. {
  13919. check_ascii = value[0];
  13920. if( (check_ascii < 48) || (check_ascii > 57) )
  13921. {
  13922. isSuccess = ConfigurationStatus_Rejected;
  13923. }
  13924. else
  13925. {
  13926. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  13927. isSuccess = ConfigurationStatus_Accepted;
  13928. }
  13929. }
  13930. else
  13931. {
  13932. isSuccess = ConfigurationStatus_Rejected;
  13933. }
  13934. }
  13935. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13936. return isSuccess;
  13937. }
  13938. int TransactionMessageAttemptsGet(void)
  13939. {
  13940. return TransactionMessageAttemptsValue;
  13941. }
  13942. int FirstHeartBeatResponse(void)
  13943. {
  13944. return FirstHeartBeat;
  13945. }
  13946. int TransactionMessageRetryIntervalGet(void)
  13947. {
  13948. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13949. }
  13950. int ReadHttpStatus(int sock)
  13951. {
  13952. //char c;
  13953. char buff[1024]="",*ptr=buff+1;
  13954. int bytes_received, status;
  13955. DEBUG_INFO("Begin Response ..\n");
  13956. while((bytes_received = recv(sock, ptr, 1, 0))){
  13957. if(bytes_received==-1){
  13958. perror("ReadHttpStatus");
  13959. exit(1);
  13960. }
  13961. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  13962. ptr++;
  13963. }
  13964. *ptr=0;
  13965. ptr=buff+1;
  13966. sscanf(ptr,"%*s %d ", &status);
  13967. DEBUG_INFO("%s\n",ptr);
  13968. DEBUG_INFO("status=%d\n",status);
  13969. DEBUG_INFO("End Response ..\n");
  13970. return (bytes_received>0)?status:0;
  13971. }
  13972. //the only filed that it parsed is 'Content-Length'
  13973. int ParseHeader(int sock)
  13974. {
  13975. //char c;
  13976. char buff[1024]="",*ptr=buff+4;
  13977. int bytes_received;
  13978. DEBUG_INFO("Begin HEADER ..\n");
  13979. while((bytes_received = recv(sock, ptr, 1, 0))){
  13980. if(bytes_received==-1){
  13981. perror("Parse Header");
  13982. exit(1);
  13983. }
  13984. if(
  13985. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  13986. (ptr[-1]=='\r') && (*ptr=='\n' )
  13987. ) break;
  13988. ptr++;
  13989. }
  13990. *ptr=0;
  13991. ptr=buff+4;
  13992. //printf("%s",ptr);
  13993. if(bytes_received){
  13994. ptr=strstr(ptr,"Content-Length:");
  13995. if(ptr){
  13996. sscanf(ptr,"%*s %d",&bytes_received);
  13997. }else
  13998. bytes_received=-1; //unknown size
  13999. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  14000. }
  14001. DEBUG_INFO("End HEADER ..\n");
  14002. return bytes_received ;
  14003. }
  14004. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  14005. {
  14006. int result = TRUE;
  14007. char rmFileCmd[100]={0};
  14008. char FilePath[100]={0};
  14009. char ftpbuf[200];
  14010. int systemresult;
  14011. //DEBUG_INFO("filename=%s\n",filename);
  14012. //DEBUG_INFO("url=%s\n",url);
  14013. sprintf(FilePath,"/mnt/%s",filename);
  14014. system("ping 8.8.8.8 &");
  14015. if((access(FilePath,F_OK))!=-1)
  14016. {
  14017. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14018. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14019. system(rmFileCmd);
  14020. }
  14021. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14022. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14023. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14024. systemresult = system(ftpbuf);
  14025. //DEBUG_INFO("systemresult=%d\n",systemresult);
  14026. if(systemresult != 0)
  14027. {
  14028. DEBUG_INFO("http DownLoad error!\n");
  14029. result = FALSE;
  14030. }
  14031. system("pkill ping");
  14032. return result;
  14033. }
  14034. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  14035. {
  14036. int result = TRUE;
  14037. char rmFileCmd[100]={0};
  14038. char FilePath[100]={0};
  14039. char ftpbuf[200];
  14040. int systemresult;
  14041. //char temp[100];
  14042. sprintf(FilePath,"/mnt/%s",filename);
  14043. system("ping 8.8.8.8 &");
  14044. if((access(FilePath,F_OK))!=-1)
  14045. {
  14046. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14047. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14048. system(rmFileCmd);
  14049. }
  14050. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14051. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14052. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  14053. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14054. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14055. systemresult = system(ftpbuf);
  14056. //DEBUG_INFO("systemresult=%d\n",systemresult);
  14057. if(systemresult != 0)
  14058. {
  14059. printf("wget error!\n");
  14060. result = FALSE;
  14061. }
  14062. system("pkill ping");
  14063. return result;
  14064. }
  14065. int httpUploadFile(char *location, char *path, char *filename,char *url)
  14066. {
  14067. char rmFileCmd[100]={0};
  14068. char FilePath[100]={0};
  14069. char buf[512];
  14070. int systemresult = 0;
  14071. //DEBUG_INFO("filename=%s\n",filename);
  14072. //DEBUG_INFO("url=%s\n",url);
  14073. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  14074. if((access(FilePath,F_OK))!=-1)
  14075. {
  14076. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14077. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14078. system(rmFileCmd);
  14079. }
  14080. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  14081. if(fp == NULL)
  14082. {
  14083. DEBUG_INFO("log is NULL\n");
  14084. return FALSE;
  14085. }
  14086. else
  14087. {
  14088. fprintf(fp, "%s\n", url);
  14089. fprintf(fp, "%s\n", filename);
  14090. fclose(fp);
  14091. }
  14092. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  14093. if(phpFP == NULL)
  14094. {
  14095. DEBUG_INFO("PHP upload fail.\n");
  14096. return FALSE;
  14097. }
  14098. else
  14099. {
  14100. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  14101. {
  14102. if(strstr(buf, "result") != NULL)
  14103. {
  14104. sscanf(buf, "result: %d", &systemresult);
  14105. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  14106. }
  14107. }
  14108. pclose(phpFP);
  14109. }
  14110. if(systemresult != 1)
  14111. {
  14112. DEBUG_INFO("HTTP upload error!\n");
  14113. return FALSE;
  14114. }
  14115. return TRUE;
  14116. }
  14117. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  14118. {
  14119. struct hostent* server;
  14120. char *IPbuffer;
  14121. char ftpbuf[200];
  14122. int systemresult;
  14123. // To retrieve host information
  14124. server = gethostbyname(location);
  14125. // To convert an Internet network
  14126. // address into ASCII string
  14127. IPbuffer = inet_ntoa(*((struct in_addr*)
  14128. server->h_addr_list[0]));
  14129. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14130. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  14131. /* format : ftpput -u username -p passwd IP target source*/
  14132. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  14133. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14134. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14135. systemresult = system(ftpbuf);
  14136. DEBUG_INFO("systemresult=%d\n",systemresult);
  14137. if(systemresult != 0)
  14138. {
  14139. DEBUG_INFO("ftpput error!\n");
  14140. return FALSE;
  14141. }
  14142. return TRUE;
  14143. }
  14144. int GetOcppServerURL()
  14145. {
  14146. int result = FALSE;
  14147. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  14148. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  14149. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  14150. struct yuarel url;
  14151. char urlStr[512];
  14152. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  14153. {
  14154. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  14155. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14156. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  14157. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  14158. if(yuarel_parse(&url, urlStr) != -1)
  14159. {
  14160. sprintf(OcppProtocol, "%s", url.scheme);
  14161. sprintf(OcppHost, "%s", url.host);
  14162. if(url.path == NULL)
  14163. OcppTempPath[0] = '\0';
  14164. else
  14165. {
  14166. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  14167. {
  14168. sprintf(OcppTempPath, "%s/", url.path);
  14169. }
  14170. else
  14171. {
  14172. sprintf(OcppTempPath, "%s", url.path);
  14173. }
  14174. }
  14175. if(url.port == 0)
  14176. {
  14177. if(strcmp(OcppProtocol, "wss") == 0)
  14178. OcppPort = 443;
  14179. else
  14180. OcppPort = 80;
  14181. }
  14182. else
  14183. OcppPort = url.port;
  14184. result = TRUE;
  14185. }
  14186. }
  14187. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  14188. {
  14189. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  14190. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14191. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  14192. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  14193. if(yuarel_parse(&url, urlStr) != -1)
  14194. {
  14195. sprintf(OcppProtocol, "%s", url.scheme);
  14196. sprintf(OcppHost, "%s", url.host);
  14197. if(url.path == NULL)
  14198. OcppTempPath[0] = '\0';
  14199. else
  14200. sprintf(OcppTempPath, "%s", url.path);
  14201. if(url.port == 0)
  14202. {
  14203. if(strcmp(OcppProtocol, "wss") == 0)
  14204. OcppPort = 443;
  14205. else
  14206. OcppPort = 80;
  14207. }
  14208. else
  14209. OcppPort = url.port;
  14210. result = TRUE;
  14211. }
  14212. }
  14213. else
  14214. {
  14215. strcpy(OcppHost,"");
  14216. }
  14217. return result;
  14218. }
  14219. int GetOcppPath()
  14220. {
  14221. int result = FALSE;
  14222. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  14223. {
  14224. if(OcppTempPath == NULL)
  14225. {
  14226. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  14227. }
  14228. else
  14229. {
  14230. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  14231. }
  14232. result = TRUE;
  14233. goto End;
  14234. }
  14235. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  14236. {
  14237. if(OcppTempPath == NULL)
  14238. {
  14239. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  14240. }
  14241. else
  14242. {
  14243. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  14244. }
  14245. result = TRUE;
  14246. goto End;
  14247. }
  14248. else
  14249. {
  14250. strcpy(OcppPath,"");
  14251. }
  14252. End:
  14253. return result;
  14254. }
  14255. int GetOcppPort()
  14256. {
  14257. return OcppPort;
  14258. }
  14259. int GetOcppConnStatus(void)
  14260. {
  14261. return ShmOCPP16Data->OcppConnStatus;
  14262. }
  14263. void SetOcppConnStatus(uint8_t status)
  14264. {
  14265. ShmOCPP16Data->OcppConnStatus = status;
  14266. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  14267. }
  14268. int GetHeartBeatWithNOResponse(void)
  14269. {
  14270. return HeartBeatWithNOResponse;
  14271. }
  14272. void SetHeartBeatWithNOResponse(void)
  14273. {
  14274. HeartBeatWithNOResponse = 0;
  14275. }
  14276. void GetStartTransactionIdTag(int gun_index)
  14277. {
  14278. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  14279. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  14280. }
  14281. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  14282. {
  14283. char ch;
  14284. FILE *fptr1;
  14285. int temptransactionId;
  14286. char str[100]={0};
  14287. temptransactionId = 0;
  14288. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  14289. {
  14290. DEBUG_INFO("IdTag is empty.\n");
  14291. return temptransactionId;
  14292. }
  14293. /*------ Read the file ----------------*/
  14294. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  14295. if (!fptr1)
  14296. {
  14297. DEBUG_INFO("QueueTransactionId file open error.\n");
  14298. //printf(" File not found or unable to open the input file!!\n");
  14299. return temptransactionId;
  14300. }
  14301. ch=fgetc(fptr1);
  14302. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  14303. rewind(fptr1);
  14304. if(ch!=EOF)
  14305. {
  14306. // printf("%c",ch);
  14307. while (fgets(str, 100, fptr1) != NULL)
  14308. {
  14309. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14310. if(str[0]=='\0')
  14311. {
  14312. break;
  14313. }
  14314. char *revbuf[8] = {0}; // Variable store string split
  14315. int num = 0;// Quantity after string split
  14316. DEBUG_INFO("Transaction queue data= %s\n", str);
  14317. splitstring(str,",",revbuf,&num); // String split
  14318. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  14319. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  14320. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  14321. DEBUG_INFO("------------------------------\n");
  14322. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  14323. {
  14324. if(isStopTransaction)
  14325. {
  14326. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  14327. {
  14328. temptransactionId = atoi(revbuf[2]);
  14329. //break;
  14330. }
  14331. }
  14332. else
  14333. {
  14334. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  14335. {
  14336. temptransactionId = atoi(revbuf[2]);
  14337. //break;
  14338. }
  14339. }
  14340. }
  14341. }
  14342. }
  14343. else
  14344. DEBUG_INFO("EOF\n");
  14345. fclose(fptr1);
  14346. /*------- End of reading ---------------*/
  14347. return temptransactionId;
  14348. }
  14349. void SetTransactionIdZero(int transactionId)
  14350. {
  14351. char ch;
  14352. FILE *fptr1, *fptr2;
  14353. int temptransactionId = 0;
  14354. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  14355. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  14356. if (!fptr1)
  14357. {
  14358. //printf(" File not found or unable to open the input file!!\n");
  14359. return ;
  14360. }
  14361. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  14362. if (!fptr2)
  14363. {
  14364. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  14365. fclose(fptr1);
  14366. return ;
  14367. }
  14368. ch=fgetc(fptr1);
  14369. rewind(fptr1);
  14370. if(ch!=EOF)
  14371. {
  14372. // copy all contents to the temporary file except the specific line
  14373. while (fgets(str, 100, fptr1) != NULL)
  14374. {
  14375. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14376. if(str[0]=='\0')
  14377. {
  14378. break;
  14379. }
  14380. char *revbuf[8] = {0};
  14381. int num = 0;
  14382. strcpy(strtemp, str);
  14383. splitstring(str,",",revbuf,&num);
  14384. if(revbuf[2][0] != '\0')
  14385. {
  14386. temptransactionId = atoi(revbuf[2]);
  14387. if(transactionId != temptransactionId)
  14388. {
  14389. fprintf(fptr2, "%s\n", strtemp);
  14390. }
  14391. }
  14392. }
  14393. }
  14394. fclose(fptr1);
  14395. fclose(fptr2);
  14396. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  14397. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  14398. /*------ Read the file ----------------*/
  14399. }
  14400. int InternetDisconnect(void)
  14401. {
  14402. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  14403. }
  14404. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  14405. void storeTempStopTransaction(int gun_index)
  14406. {
  14407. char guid[37]={0};
  14408. int tempIndex = 0;
  14409. char TempStopTransaction[256];
  14410. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  14411. DEBUG_INFO("storeTempStopTransaction...\n");
  14412. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  14413. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  14414. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  14415. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14416. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14417. {
  14418. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14419. {
  14420. tempIndex = ((gun_index==2) ? 1: 0);
  14421. }
  14422. else
  14423. {
  14424. tempIndex = gun_index;
  14425. }
  14426. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14427. {
  14428. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14429. {
  14430. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  14431. }
  14432. }// END OF CHAdeMO_QUANTITY
  14433. }
  14434. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14435. {
  14436. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14437. {
  14438. tempIndex = ((gun_index==2) ? 1: 0);
  14439. }
  14440. else
  14441. {
  14442. tempIndex = gun_index;
  14443. }
  14444. for (int index = 0; index < CCS_QUANTITY; index++)
  14445. {
  14446. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14447. {
  14448. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  14449. }
  14450. }// END OF CCS_QUANTITY
  14451. }
  14452. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14453. {
  14454. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14455. {
  14456. tempIndex = ((gun_index==2) ? 1: 0);
  14457. }
  14458. else
  14459. {
  14460. tempIndex = gun_index;
  14461. }
  14462. for (int index = 0; index < GB_QUANTITY; index++)
  14463. {
  14464. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14465. {
  14466. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  14467. }
  14468. }// END OF GB_QUANTITY
  14469. }
  14470. else if(gunType[gun_index] == GUN_TYPE_DO)
  14471. {
  14472. tempIndex = gun_index;
  14473. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14474. {
  14475. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14476. {
  14477. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  14478. }
  14479. }
  14480. }
  14481. else
  14482. {
  14483. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14484. {
  14485. tempIndex = 2;
  14486. }
  14487. else
  14488. {
  14489. tempIndex = gun_index;
  14490. }
  14491. for (int index = 0; index < AC_QUANTITY; index++)
  14492. {
  14493. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14494. {
  14495. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  14496. }
  14497. }// END OF AC_QUANTITY
  14498. }
  14499. //Stop Transaction Time
  14500. struct timeval tmnow;
  14501. struct tm *tm;
  14502. char buf[28];//, usec_buf[6];
  14503. gettimeofday(&tmnow, NULL);
  14504. time_t t;
  14505. t = time(NULL);
  14506. /*UTC time and date*/
  14507. tm = gmtime(&t);
  14508. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  14509. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  14510. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  14511. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  14512. random_uuid(guid);
  14513. /***********************************transactionData******************************************************/
  14514. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  14515. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  14516. //=================================
  14517. //1. Transaction_Begin
  14518. //=================================
  14519. //============================== Energy.Active.Import.Interval ===========================================
  14520. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  14521. {
  14522. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  14523. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  14524. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  14525. 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*/]);
  14526. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14527. 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))
  14528. {
  14529. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  14530. }
  14531. else
  14532. {
  14533. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  14534. }
  14535. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  14536. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  14537. }
  14538. //=================================
  14539. //2. Transaction_End
  14540. //=================================
  14541. //2.1====================================== Current.Import L1 ==============================================
  14542. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  14543. {
  14544. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  14545. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14546. {
  14547. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14548. {
  14549. tempIndex = ((gun_index==2) ? 1: 0);
  14550. }
  14551. else
  14552. {
  14553. tempIndex = gun_index;
  14554. }
  14555. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14556. {
  14557. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14558. {
  14559. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14560. }
  14561. }// End of for CHAdeMO_QUANTITY
  14562. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14563. }
  14564. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14565. {
  14566. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14567. {
  14568. tempIndex = ((gun_index==2) ? 1: 0);
  14569. }
  14570. else
  14571. {
  14572. tempIndex = gun_index;
  14573. }
  14574. for (int index = 0; index < CCS_QUANTITY; index++)
  14575. {
  14576. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14577. {
  14578. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14579. }
  14580. }// End of for CCS_QUANTITY
  14581. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14582. }
  14583. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14584. {
  14585. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14586. {
  14587. tempIndex = ((gun_index==2) ? 1: 0);
  14588. }
  14589. else
  14590. {
  14591. tempIndex = gun_index;
  14592. }
  14593. for (int index = 0; index < GB_QUANTITY; index++)
  14594. {
  14595. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14596. {
  14597. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14598. }
  14599. }// End of for GB_QUANTITY
  14600. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14601. }
  14602. else if(gunType[gun_index] == GUN_TYPE_DO)
  14603. {
  14604. tempIndex = gun_index;
  14605. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14606. {
  14607. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14608. {
  14609. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14610. }
  14611. }
  14612. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14613. }
  14614. else
  14615. {
  14616. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14617. {
  14618. tempIndex = 2;
  14619. }
  14620. else
  14621. {
  14622. tempIndex = gun_index;
  14623. }
  14624. for (int index = 0; index < AC_QUANTITY; index++)
  14625. {
  14626. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14627. {
  14628. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  14629. }
  14630. }// End of for AC_QUANTITY
  14631. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  14632. }
  14633. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14634. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  14635. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  14636. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  14637. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  14638. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14639. }
  14640. //2.2===================================== Energy.Active.Import.Interval ==========================================
  14641. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  14642. {
  14643. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14644. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14645. {
  14646. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14647. {
  14648. tempIndex = ((gun_index==2) ? 1: 0);
  14649. }
  14650. else
  14651. {
  14652. tempIndex = gun_index;
  14653. }
  14654. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14655. {
  14656. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14657. {
  14658. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14659. }
  14660. }// END OF CHAdeMO_QUANTITY
  14661. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14662. }
  14663. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14664. {
  14665. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14666. {
  14667. tempIndex = ((gun_index==2) ? 1: 0);
  14668. }
  14669. else
  14670. {
  14671. tempIndex = gun_index;
  14672. }
  14673. for (int index = 0; index < CCS_QUANTITY; index++)
  14674. {
  14675. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14676. {
  14677. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14678. }
  14679. }// END OF CCS_QUANTITY
  14680. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14681. }
  14682. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14683. {
  14684. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14685. {
  14686. tempIndex = ((gun_index==2) ? 1: 0);
  14687. }
  14688. else
  14689. {
  14690. tempIndex = gun_index;
  14691. }
  14692. for (int index = 0; index < GB_QUANTITY; index++)
  14693. {
  14694. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14695. {
  14696. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14697. }
  14698. }// END OF GB_QUANTITY
  14699. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14700. }
  14701. else if(gunType[gun_index] == GUN_TYPE_DO)
  14702. {
  14703. tempIndex = gun_index;
  14704. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14705. {
  14706. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14707. {
  14708. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14709. }
  14710. }
  14711. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14712. }
  14713. else
  14714. {
  14715. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14716. {
  14717. tempIndex = 2;
  14718. }
  14719. else
  14720. {
  14721. tempIndex = gun_index;
  14722. }
  14723. for (int index = 0; index < AC_QUANTITY; index++)
  14724. {
  14725. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14726. {
  14727. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14728. }
  14729. }// END OF AC_QUANTITY
  14730. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  14731. }
  14732. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14733. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  14734. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  14735. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  14736. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  14737. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  14738. }
  14739. //2.3====================================== Power.Active.Import =========================================
  14740. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  14741. {
  14742. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14743. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14744. {
  14745. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14746. {
  14747. tempIndex = ((gun_index==2) ? 1: 0);
  14748. }
  14749. else
  14750. {
  14751. tempIndex = gun_index;
  14752. }
  14753. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14754. {
  14755. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14756. {
  14757. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14758. }
  14759. } // End for CHAdeMO_QUANTITY
  14760. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14761. }
  14762. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14763. {
  14764. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14765. {
  14766. tempIndex = ((gun_index==2) ? 1: 0);
  14767. }
  14768. else
  14769. {
  14770. tempIndex = gun_index;
  14771. }
  14772. for (int index = 0; index < CCS_QUANTITY; index++)
  14773. {
  14774. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14775. {
  14776. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14777. }
  14778. } // END for CCS_QUANTITY
  14779. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14780. }
  14781. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14782. {
  14783. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14784. {
  14785. tempIndex = ((gun_index==2) ? 1: 0);
  14786. }
  14787. else
  14788. {
  14789. tempIndex = gun_index;
  14790. }
  14791. for (int index = 0; index < GB_QUANTITY; index++)
  14792. {
  14793. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14794. {
  14795. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14796. }
  14797. }// END for GB_QUANTITY
  14798. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14799. }
  14800. else if(gunType[gun_index] == GUN_TYPE_DO)
  14801. {
  14802. tempIndex = gun_index;
  14803. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14804. {
  14805. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14806. {
  14807. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14808. }
  14809. }
  14810. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14811. }
  14812. else
  14813. {
  14814. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14815. {
  14816. tempIndex = 2;
  14817. }
  14818. else
  14819. {
  14820. tempIndex = gun_index;
  14821. }
  14822. for (int index = 0; index < AC_QUANTITY; index++)
  14823. {
  14824. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14825. {
  14826. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14827. }
  14828. } // END for AC_QUANTITY
  14829. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  14830. }
  14831. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14832. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  14833. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  14834. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  14835. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  14836. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  14837. }
  14838. //2.4====================================== Voltage L1 ====================================================
  14839. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  14840. {
  14841. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14842. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14843. {
  14844. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14845. {
  14846. tempIndex = ((gun_index==2) ? 1: 0);
  14847. }
  14848. else
  14849. {
  14850. tempIndex = gun_index;
  14851. }
  14852. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14853. {
  14854. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14855. {
  14856. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14857. }
  14858. } // END OF FOR CHAdeMO_QUANTITY
  14859. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14860. }
  14861. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14862. {
  14863. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14864. {
  14865. tempIndex = ((gun_index==2) ? 1: 0);
  14866. }
  14867. else
  14868. {
  14869. tempIndex = gun_index;
  14870. }
  14871. for (int index = 0; index < CCS_QUANTITY; index++)
  14872. {
  14873. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14874. {
  14875. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14876. }
  14877. } // END OF FOR CCS_QUANTITY
  14878. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14879. }
  14880. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14881. {
  14882. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14883. {
  14884. tempIndex = ((gun_index==2) ? 1: 0);
  14885. }
  14886. else
  14887. {
  14888. tempIndex = gun_index;
  14889. }
  14890. for (int index = 0; index < GB_QUANTITY; index++)
  14891. {
  14892. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14893. {
  14894. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14895. }
  14896. } // END OF FOR GB_QUANTITY
  14897. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14898. }
  14899. else if(gunType[gun_index] == GUN_TYPE_DO)
  14900. {
  14901. tempIndex = gun_index;
  14902. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14903. {
  14904. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14905. {
  14906. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14907. }
  14908. }
  14909. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14910. }
  14911. else
  14912. {
  14913. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14914. {
  14915. tempIndex = 2;
  14916. }
  14917. else
  14918. {
  14919. tempIndex = gun_index;
  14920. }
  14921. for (int index = 0; index < AC_QUANTITY; index++)
  14922. {
  14923. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14924. {
  14925. 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
  14926. }
  14927. } // END OF FOR AC_QUANTITY
  14928. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  14929. }
  14930. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14931. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  14932. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  14933. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  14934. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  14935. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  14936. }
  14937. //2.5============================================== End SoC =========================================================
  14938. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  14939. {
  14940. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14941. 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))
  14942. {
  14943. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  14944. {
  14945. tempIndex = ((gun_index==2) ? 1: 0);
  14946. }
  14947. else
  14948. {
  14949. tempIndex = gun_index;
  14950. }
  14951. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14952. {
  14953. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14954. {
  14955. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14956. {
  14957. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  14958. }
  14959. }
  14960. }
  14961. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14962. {
  14963. for (int index = 0; index < CCS_QUANTITY; index++)
  14964. {
  14965. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14966. {
  14967. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  14968. }
  14969. }
  14970. }
  14971. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14972. {
  14973. for (int index = 0; index < GB_QUANTITY; index++)
  14974. {
  14975. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14976. {
  14977. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  14978. }
  14979. }
  14980. }
  14981. else if(gunType[gun_index] == GUN_TYPE_DO)
  14982. {
  14983. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14984. {
  14985. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14986. {
  14987. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  14988. }
  14989. }
  14990. }
  14991. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14992. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  14993. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  14994. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  14995. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  14996. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  14997. } // END FOR DC CASE
  14998. }
  14999. //2.6====================================== Current.Import L2 ==============================================
  15000. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15001. {
  15002. // AC 3 phase L2 current
  15003. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15004. {
  15005. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15006. {
  15007. tempIndex = 2;
  15008. }
  15009. else
  15010. {
  15011. tempIndex = gun_index;
  15012. }
  15013. for (int index = 0; index < AC_QUANTITY; index++)
  15014. {
  15015. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15016. {
  15017. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  15018. }
  15019. }// End of for AC_QUANTITY
  15020. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  15021. }
  15022. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15023. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  15024. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  15025. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  15026. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15027. }
  15028. //2.7====================================== Current.Import L3 ==============================================
  15029. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15030. {
  15031. // AC 3 phase L3 current
  15032. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15033. {
  15034. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15035. {
  15036. tempIndex = 2;
  15037. }
  15038. else
  15039. {
  15040. tempIndex = gun_index;
  15041. }
  15042. for (int index = 0; index < AC_QUANTITY; index++)
  15043. {
  15044. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15045. {
  15046. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  15047. }
  15048. }// End of for AC_QUANTITY
  15049. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  15050. }
  15051. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15052. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  15053. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  15054. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  15055. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15056. }
  15057. //2.9====================================== Voltage L2 ====================================================
  15058. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15059. {
  15060. // AC 3 phase L2 volatge
  15061. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15062. {
  15063. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15064. {
  15065. tempIndex = 2;
  15066. }
  15067. else
  15068. {
  15069. tempIndex = gun_index;
  15070. }
  15071. for (int index = 0; index < AC_QUANTITY; index++)
  15072. {
  15073. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15074. {
  15075. 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
  15076. }
  15077. } // END OF FOR AC_QUANTITY
  15078. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  15079. }
  15080. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15081. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  15082. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  15083. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  15084. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15085. }
  15086. //2.10====================================== Voltage L3 ====================================================
  15087. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15088. {
  15089. // AC 3 phase L3 volatge
  15090. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15091. {
  15092. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15093. {
  15094. tempIndex = 2;
  15095. }
  15096. else
  15097. {
  15098. tempIndex = gun_index;
  15099. }
  15100. for (int index = 0; index < AC_QUANTITY; index++)
  15101. {
  15102. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15103. {
  15104. 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
  15105. }
  15106. } // END OF FOR AC_QUANTITY
  15107. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  15108. }
  15109. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15110. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  15111. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  15112. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  15113. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15114. }
  15115. //====================== Start SoC ================================
  15116. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  15117. {
  15118. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15119. 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))
  15120. {
  15121. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15122. {
  15123. tempIndex = ((gun_index==2) ? 1: 0);
  15124. }
  15125. else
  15126. {
  15127. tempIndex = gun_index;
  15128. }
  15129. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15130. {
  15131. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15132. {
  15133. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15134. {
  15135. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  15136. }
  15137. }
  15138. }
  15139. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15140. {
  15141. for (int index = 0; index < CCS_QUANTITY; index++)
  15142. {
  15143. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15144. {
  15145. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  15146. }
  15147. }
  15148. }
  15149. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15150. {
  15151. for (int index = 0; index < GB_QUANTITY; index++)
  15152. {
  15153. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15154. {
  15155. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  15156. }
  15157. }
  15158. }
  15159. else if(gunType[gun_index] == GUN_TYPE_DO)
  15160. {
  15161. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15162. {
  15163. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15164. {
  15165. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  15166. }
  15167. }
  15168. }
  15169. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15170. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  15171. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15172. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  15173. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  15174. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15175. } // END FOR DC CASE
  15176. }
  15177. //======================================== Message create ==============================================
  15178. json_object *StopTransaction = json_object_new_object();
  15179. json_object *transactionDatas = json_object_new_array();
  15180. json_object *sampledValues = json_object_new_array();
  15181. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  15182. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  15183. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  15184. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  15185. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  15186. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  15187. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  15188. {
  15189. json_object *transactionData = json_object_new_object();
  15190. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  15191. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  15192. {
  15193. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  15194. {
  15195. json_object *sampledValue = json_object_new_object();
  15196. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  15197. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  15198. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  15199. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  15200. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  15201. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  15202. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  15203. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  15204. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  15205. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  15206. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  15207. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  15208. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  15209. json_object_array_add(sampledValues, sampledValue);
  15210. }
  15211. }
  15212. json_object_object_add(transactionData, "sampledValue", sampledValues);
  15213. json_object_array_add(transactionDatas, transactionData);
  15214. }
  15215. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  15216. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  15217. ,MESSAGE_TYPE_CALL
  15218. ,guid
  15219. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  15220. json_object_put(StopTransaction);
  15221. // Check File "TempStopTransaction" Exist
  15222. if((access(TempStopTransaction,F_OK))!=-1)
  15223. {
  15224. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  15225. fclose(fopen(TempStopTransaction, "w"));
  15226. }
  15227. else
  15228. {
  15229. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  15230. FILE *log = fopen(TempStopTransaction, "w+");
  15231. if(log == NULL)
  15232. {
  15233. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  15234. return ;
  15235. }
  15236. else
  15237. {
  15238. fclose(log);
  15239. }
  15240. }
  15241. //Add TempStopTransaction | Update TempStopTransaction
  15242. // open file for writing
  15243. FILE *outfile;
  15244. outfile = fopen (TempStopTransaction, "a");
  15245. //DEBUG_INFO("data = %s\n", queuedata);
  15246. fputs(queuedata, outfile);
  15247. fputs("\n", outfile);
  15248. fclose (outfile);
  15249. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15250. }
  15251. void checkTempStopTransaction(int gun_index)
  15252. {
  15253. FILE *fptr1;
  15254. char ch;
  15255. char str[QUEUE_MESSAGE_LENGTH]={0};
  15256. char guid[37]={0};
  15257. char tempdata[65]={0};
  15258. char connectorStr[2]={0};
  15259. char TempStopTransaction[256];
  15260. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  15261. fptr1 = fopen(TempStopTransaction, "r");
  15262. //TempStopTransaction格式: 槍號,StopTransaction封包
  15263. if (!fptr1)
  15264. {
  15265. //printf(" File not found or unable to open the input file!!\n");
  15266. return ;
  15267. }
  15268. ch=fgetc(fptr1);
  15269. //printf(" Now the content of the file %s is : \n",fname);
  15270. rewind(fptr1);
  15271. if(ch!=EOF)
  15272. {
  15273. // copy all contents to the temporary file except the specific line
  15274. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  15275. {
  15276. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15277. if(str[0]=='\0')
  15278. {
  15279. break;
  15280. }
  15281. //TempStopTransaction格式: 槍號,StopTransaction封包
  15282. strncpy(connectorStr, str, 1);
  15283. if(atoi(connectorStr) != (gun_index+1))
  15284. {
  15285. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  15286. fclose(fptr1);
  15287. return ;
  15288. }
  15289. //random_uuid(guid);
  15290. strncpy(guid, str+6, 36); //copy guid
  15291. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  15292. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  15293. {
  15294. //DEBUG_INFO("StopTransaction mapitem pass\n");
  15295. }
  15296. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  15297. OCPP_insert_transaction_msg(NO, str);
  15298. memset(str,0,ARRAY_SIZE(str));
  15299. }
  15300. }
  15301. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  15302. fclose(fptr1);
  15303. remove(TempStopTransaction); // remove the original file
  15304. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15305. }
  15306. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  15307. {
  15308. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  15309. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  15310. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  15311. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  15312. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  15313. }
  15314. int GetWebSocketPingInterval(void)
  15315. {
  15316. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15317. }
  15318. int GetServerSign(void)
  15319. {
  15320. return server_sign;
  15321. }
  15322. uint8_t GetOcppSecurityProfile()
  15323. {
  15324. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15325. }
  15326. void GetOcppChargerBoxId(uint8_t *data)
  15327. {
  15328. sprintf((char*)data, "%s", ShmOCPP16Data->ChargeBoxId);
  15329. }
  15330. void GetOcppSecurityPassword(uint8_t *data)
  15331. {
  15332. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15333. }
  15334. void SetOcppVersion(uint8_t *version)
  15335. {
  15336. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  15337. DEBUG_INFO("ocpp version: %s\n", version);
  15338. if(strstr((char*)version, "ocpp1.6") != NULL)
  15339. {
  15340. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  15341. }
  15342. else if(strstr((char*)version, "ocpp2.0") != NULL)
  15343. {
  15344. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  15345. system("pkill OcppBackend");
  15346. }
  15347. }
  15348. void SetServerSign(int value)
  15349. {
  15350. server_sign = value;
  15351. }
  15352. int GetBootNotificationInterval(void)
  15353. {
  15354. return BootNotificationInterval;
  15355. }
  15356. int GetInternetConn(void)
  15357. {
  15358. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  15359. }
  15360. int GetBackendConnectionTimeout(void)
  15361. {
  15362. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  15363. }
  15364. int isConnectorInitMode(int gun_index)
  15365. {
  15366. int tempIndex = 0;
  15367. int result = TRUE;
  15368. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15369. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15370. {
  15371. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15372. {
  15373. tempIndex = ((gun_index==2) ? 1: 0);
  15374. }
  15375. else
  15376. {
  15377. tempIndex = gun_index;
  15378. }
  15379. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15380. {
  15381. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  15382. {
  15383. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15384. } //end of the same index
  15385. }//end of for CHAdeMO_QUANTITY
  15386. }
  15387. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15388. {
  15389. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15390. {
  15391. tempIndex = ((gun_index==2) ? 1: 0);
  15392. }
  15393. else
  15394. {
  15395. tempIndex = gun_index;
  15396. }
  15397. for (int index = 0; index < CCS_QUANTITY; index++)
  15398. {
  15399. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15400. {
  15401. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15402. } //end of the same index
  15403. } // end of for CCS_QUANTITY
  15404. }
  15405. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15406. {
  15407. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15408. {
  15409. tempIndex = ((gun_index==2) ? 1: 0);
  15410. }
  15411. else
  15412. {
  15413. tempIndex = gun_index;
  15414. }
  15415. for (int index = 0; index < GB_QUANTITY; index++)
  15416. {
  15417. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15418. {
  15419. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15420. } //end of the same index
  15421. } // end of for GB_QUANTITY
  15422. }
  15423. else if(gunType[gun_index] == GUN_TYPE_DO)
  15424. {
  15425. tempIndex = gun_index;
  15426. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15427. {
  15428. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15429. {
  15430. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15431. } //end of the same index
  15432. }
  15433. }
  15434. else
  15435. {
  15436. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15437. {
  15438. tempIndex = 2;
  15439. }
  15440. else
  15441. {
  15442. tempIndex = gun_index;
  15443. }
  15444. for (int index = 0; index < AC_QUANTITY; index++)
  15445. {
  15446. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15447. {
  15448. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15449. }//end of the same index
  15450. }//end of for AC_QUANTITY
  15451. }
  15452. return result;
  15453. }
  15454. void refreshProcDogTimer()
  15455. {
  15456. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  15457. }
  15458. void InitialSystemValue(void)
  15459. {
  15460. int connectorIndex = 0;
  15461. //int valueASCII = 0;
  15462. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  15463. gunTotalNumber=0;
  15464. SystemInitial = 0;
  15465. localversion=0;
  15466. BootNotificationInterval = 0;
  15467. authorizeRetryTimes = 0;
  15468. GunStatusInterval = 10;
  15469. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15470. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15471. //Hear Beat
  15472. HeartBeatWithNOResponse = 0;
  15473. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  15474. FirstHeartBeat = 0;
  15475. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  15476. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  15477. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  15478. memset(statusModeChage, 0, ARRAY_SIZE(statusModeChage));
  15479. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  15480. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  15481. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  15482. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  15483. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  15484. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  15485. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  15486. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  15487. memset(gunType, 0, ARRAY_SIZE(gunType));
  15488. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  15489. {
  15490. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O')
  15491. {
  15492. // DO series
  15493. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  15494. {
  15495. SystemInitial = SystemInitial + 1;
  15496. gunTotalNumber = gunTotalNumber + 1;
  15497. gunType[connectorIndex] = GUN_TYPE_DO;
  15498. connectorIndex = connectorIndex + 1;
  15499. }
  15500. }
  15501. else
  15502. {
  15503. // DM, DW, DS series
  15504. //check connector / socket type (index: 8, 9, 10)
  15505. for(int index=7; index <10 ; index++)
  15506. {
  15507. if(index != 8)
  15508. {
  15509. // DC Connector
  15510. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  15511. {
  15512. SystemInitial = SystemInitial + 1;
  15513. gunTotalNumber = gunTotalNumber + 1;
  15514. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  15515. connectorIndex = connectorIndex + 1;
  15516. }
  15517. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  15518. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  15519. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  15520. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  15521. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  15522. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  15523. {
  15524. SystemInitial = SystemInitial + 1;
  15525. gunTotalNumber = gunTotalNumber + 1;
  15526. gunType[connectorIndex] = GUN_TYPE_CCS;
  15527. connectorIndex = connectorIndex + 1;
  15528. }
  15529. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  15530. {
  15531. SystemInitial = SystemInitial + 1;
  15532. gunTotalNumber = gunTotalNumber + 1;
  15533. gunType[connectorIndex] = GUN_TYPE_GBT;
  15534. connectorIndex = connectorIndex + 1;
  15535. }
  15536. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  15537. {
  15538. SystemInitial = SystemInitial + 1;
  15539. gunTotalNumber = gunTotalNumber + 1;
  15540. gunType[connectorIndex] = GUN_TYPE_DO;
  15541. connectorIndex = connectorIndex + 1;
  15542. }
  15543. }
  15544. else
  15545. {
  15546. // AC Connector
  15547. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  15548. {
  15549. SystemInitial = SystemInitial + 1;
  15550. gunTotalNumber = gunTotalNumber + 1;
  15551. gunType[connectorIndex] = GUN_TYPE_AC;
  15552. connectorIndex = connectorIndex + 1;
  15553. }
  15554. }
  15555. }
  15556. }
  15557. //DEBUG_INFO("DC ...\n");
  15558. }
  15559. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  15560. {
  15561. //check connector / socket type (index: 8, 9, 10)
  15562. for(int index=7; index <10 ; index++)
  15563. {
  15564. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  15565. {
  15566. SystemInitial = SystemInitial + 1;
  15567. gunTotalNumber = gunTotalNumber + 1;
  15568. gunType[connectorIndex] = GUN_TYPE_AC;
  15569. connectorIndex = connectorIndex + 1;
  15570. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  15571. }
  15572. }
  15573. }
  15574. //Status && ConnectorPlugIn Setting
  15575. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15576. {
  15577. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  15578. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  15579. }
  15580. for (int index = 0; index < CCS_QUANTITY; index++)
  15581. {
  15582. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  15583. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  15584. }
  15585. for (int index = 0; index < GB_QUANTITY; index++)
  15586. {
  15587. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  15588. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  15589. }
  15590. for (int index = 0; index < AC_QUANTITY; index++)
  15591. {
  15592. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  15593. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  15594. }
  15595. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15596. {
  15597. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  15598. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  15599. }
  15600. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  15601. {
  15602. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  15603. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  15604. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  15605. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  15606. }
  15607. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  15608. clientTime.Heartbeat=time((time_t*)NULL);
  15609. sleep(1);
  15610. }
  15611. void LWS_Send(char *str)
  15612. {
  15613. //=====================================================
  15614. // Check InternetConn 0: disconnected, 1: connected
  15615. //====================================================
  15616. if(GetOcppConnStatus() == 0)
  15617. {
  15618. DEBUG_INFO("offline now !!!\n");
  15619. return;
  15620. }
  15621. // Only disable isWebsocketSendable operation initiated by charger
  15622. if((strstr((char*)str, "\"Authorize\"") != NULL)
  15623. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  15624. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  15625. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  15626. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  15627. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  15628. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  15629. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  15630. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  15631. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  15632. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  15633. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  15634. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  15635. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  15636. {
  15637. isWebsocketSendable = 0;
  15638. }
  15639. pthread_mutex_lock(&lock_send);
  15640. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  15641. sprintf((char *)SendBuffer, "%s", str);
  15642. SendBufLen = strlen(str);
  15643. pthread_mutex_unlock(&lock_send);
  15644. lws_callback_on_writable(wsi_client);
  15645. //lws_service(context, 0);
  15646. //sleep(1);
  15647. }
  15648. void LWS_SendNow(char *str)
  15649. {
  15650. //=====================================================
  15651. // Check InternetConn 0: disconnected, 1: connected
  15652. //====================================================
  15653. if(GetOcppConnStatus() == 0)
  15654. {
  15655. DEBUG_INFO("offline now !!!\n");
  15656. return;
  15657. }
  15658. // Only disable isWebsocketSendable operation initiated by charger
  15659. if((strstr((char*)str, "\"Authorize\"") != NULL)
  15660. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  15661. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  15662. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  15663. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  15664. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  15665. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  15666. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  15667. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  15668. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  15669. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  15670. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  15671. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  15672. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  15673. {
  15674. isWebsocketSendable = 0;
  15675. }
  15676. pthread_mutex_lock(&lock_send);
  15677. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  15678. sprintf((char *)SendBuffer, "%s", str);
  15679. SendBufLen = strlen(str);
  15680. pthread_mutex_unlock(&lock_send);
  15681. lws_callback_on_writable(wsi_client);
  15682. lws_service(context, 0);
  15683. //sleep(1);
  15684. }