MessageHandler.c 765 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979
  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. break;
  2187. }
  2188. }
  2189. }
  2190. else
  2191. {
  2192. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2193. {
  2194. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2195. compositePeriodIdx++;
  2196. }
  2197. else
  2198. {
  2199. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2200. }
  2201. }
  2202. }
  2203. }
  2204. }
  2205. }
  2206. }
  2207. }
  2208. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  2209. else if(defaultTxProfile.ChargingProfileId != -1)
  2210. {
  2211. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2212. {
  2213. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  2214. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2215. (defaultTxProfile.ChargingSchedule.Duration > 0))
  2216. {
  2217. if(maxProfile.ChargingProfileId != -1)
  2218. {
  2219. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2220. {
  2221. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2222. {
  2223. if((maxProfile.ChargingSchedule.Duration > 0))
  2224. {
  2225. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2226. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2227. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  2228. }
  2229. else
  2230. {
  2231. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2232. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2233. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2234. }
  2235. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2236. {
  2237. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2238. {
  2239. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2240. compositePeriodIdx++;
  2241. }
  2242. else
  2243. {
  2244. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2245. }
  2246. }
  2247. break;
  2248. }
  2249. }
  2250. }
  2251. else
  2252. {
  2253. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2254. {
  2255. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2256. compositePeriodIdx++;
  2257. }
  2258. else
  2259. {
  2260. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2261. }
  2262. }
  2263. }
  2264. }
  2265. }
  2266. // Fill other period by MaxProfile
  2267. if(maxProfile.ChargingProfileId != -1)
  2268. {
  2269. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2270. {
  2271. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2272. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2273. (maxProfile.ChargingSchedule.Duration > 0))
  2274. {
  2275. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  2276. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2277. {
  2278. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  2279. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  2280. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2281. }
  2282. if((maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2283. {
  2284. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.Duration;
  2285. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  2286. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2287. }
  2288. if(tmpPeriod.Limit != -1)
  2289. {
  2290. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2291. {
  2292. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2293. {
  2294. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2295. compositePeriodIdx++;
  2296. }
  2297. else
  2298. {
  2299. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2300. }
  2301. }
  2302. }
  2303. }
  2304. }
  2305. }
  2306. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  2307. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2308. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  2309. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  2310. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2311. {
  2312. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2313. {
  2314. compositeProfile->ChargingProfileId = 1;
  2315. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2316. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2317. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2318. }
  2319. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2320. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2321. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2322. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2323. }
  2324. if(line)
  2325. free(line);
  2326. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  2327. }
  2328. //==========================================
  2329. // Init all share memory
  2330. //==========================================
  2331. int InitShareMemory()
  2332. {
  2333. int result = PASS;
  2334. int MeterSMId;
  2335. //creat ShmSysConfigAndInfo
  2336. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  2337. {
  2338. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  2339. result = FAIL;
  2340. }
  2341. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2342. {
  2343. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  2344. result = FAIL;
  2345. }
  2346. else
  2347. {}
  2348. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  2349. {
  2350. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  2351. result = FAIL;
  2352. }
  2353. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2354. {
  2355. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  2356. result = FAIL;
  2357. }
  2358. else
  2359. {}
  2360. //creat ShmPsuData
  2361. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  2362. {
  2363. DEBUG_ERROR("shmget ShmPsuData NG\n");
  2364. result = FAIL;
  2365. }
  2366. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2367. {
  2368. DEBUG_ERROR("shmat ShmPsuData NG\n");
  2369. result = FAIL;
  2370. }
  2371. else
  2372. {}
  2373. //creat ShmOCPP16Data
  2374. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  2375. {
  2376. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  2377. result = FAIL;
  2378. }
  2379. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2380. {
  2381. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  2382. result = FAIL;
  2383. }
  2384. else
  2385. {}
  2386. /****************************** For Initial Settings************************************************/
  2387. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  2388. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  2389. // allocate Configuration memory address
  2390. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  2391. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  2392. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  2393. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  2394. //offline MeterValue Interval
  2395. TempMeterValueInterval = 0;
  2396. return result;
  2397. }
  2398. int ProcessShareMemory()
  2399. {
  2400. if(InitShareMemory() == FAIL)
  2401. {
  2402. DEBUG_ERROR("InitShareMemory NG\n");
  2403. if(ShmStatusCodeData!=NULL)
  2404. {
  2405. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  2406. }
  2407. sleep(5);
  2408. return FAIL;
  2409. }
  2410. return PASS;
  2411. }
  2412. void CheckSystemValue(void)
  2413. {
  2414. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  2415. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  2416. char filenmae[100]={0};
  2417. char str[100]={0};
  2418. int tempIndex = 0;
  2419. //===============================
  2420. // send Heartbeat
  2421. //===============================
  2422. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2423. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  2424. {
  2425. clientTime.Heartbeat=time((time_t*)NULL);
  2426. if(server_sign == TRUE)
  2427. {
  2428. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2429. }
  2430. else
  2431. {
  2432. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  2433. }
  2434. }
  2435. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  2436. {
  2437. //parameter for test
  2438. sendHeartbeatRequest(0);
  2439. //==============================================
  2440. // Reset Waiting Time
  2441. //==============================================
  2442. HeartBeatWithNOResponse += 1;
  2443. }
  2444. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  2445. {
  2446. //==========================================
  2447. // csu trigger DataTransferReq
  2448. //==========================================
  2449. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  2450. {
  2451. sendDataTransferRequest(gun_index);
  2452. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  2453. }
  2454. //===============================
  2455. // CSU Trigger Authorize Request
  2456. //===============================
  2457. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  2458. {
  2459. sendAuthorizeRequest(0);
  2460. authorizeRetryTimes = authorizeRetryTimes + 1;
  2461. if(authorizeRetryTimes < 3)
  2462. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2463. }
  2464. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  2465. {
  2466. authorizeRetryTimes = 0;
  2467. SetOcppConnStatus(FALSE);
  2468. server_sign = FALSE;
  2469. }
  2470. else if((server_sign == FALSE) && (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0)&& (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1))
  2471. {
  2472. sendAuthorizeRequest(0);
  2473. }
  2474. //==============================================
  2475. // CSU Trigger Smart Charging Profilw
  2476. //==============================================
  2477. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  2478. {
  2479. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  2480. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  2481. }
  2482. //==============================================
  2483. // Charger start transaction
  2484. //==============================================
  2485. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2486. {
  2487. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  2488. sendStartTransactionRequest(gun_index);
  2489. clientTime.StartTransaction = time((time_t*)NULL);
  2490. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2491. storeTempStopTransaction(gun_index);
  2492. }
  2493. //==============================================
  2494. // Charger stop transaction
  2495. //==============================================
  2496. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2497. {
  2498. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2499. sendStopTransactionRequest(gun_index);
  2500. clientTime.StopTransaction = time((time_t*)NULL);
  2501. }
  2502. //==============================================
  2503. // Charger status report
  2504. //==============================================
  2505. //--- Check Mode Change ---//
  2506. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2507. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2508. {
  2509. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2510. {
  2511. tempIndex = ((gun_index==2) ? 1: 0);
  2512. }
  2513. else
  2514. {
  2515. tempIndex = gun_index;
  2516. }
  2517. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2518. {
  2519. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2520. {
  2521. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  2522. {
  2523. // Sent unplug message for California pricing logic
  2524. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  2525. {
  2526. uint8_t ts[20];
  2527. getNowDatetime(ts);
  2528. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2529. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2530. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2531. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2532. }
  2533. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2534. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2535. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2536. statusModeChage[gun_index] = TRUE;
  2537. }
  2538. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2539. {
  2540. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2541. if((access(filenmae,F_OK))!=-1)
  2542. {
  2543. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2544. sprintf(str,"rm -f %s",filenmae);
  2545. system(str);
  2546. }
  2547. }
  2548. #if 1 // for TempStopTransaction
  2549. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2550. {
  2551. checkTempStopTransaction(gun_index);
  2552. }
  2553. #endif
  2554. }
  2555. }
  2556. }
  2557. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2558. {
  2559. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2560. {
  2561. tempIndex = ((gun_index==2) ? 1: 0);
  2562. }
  2563. else
  2564. {
  2565. tempIndex = gun_index;
  2566. }
  2567. for (int index = 0; index < CCS_QUANTITY; index++)
  2568. {
  2569. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2570. {
  2571. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn != CcsPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  2572. {
  2573. // Sent unplug message for California pricing logic
  2574. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  2575. {
  2576. uint8_t ts[20];
  2577. getNowDatetime(ts);
  2578. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2579. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2580. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2581. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2582. }
  2583. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2584. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2585. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2586. statusModeChage[gun_index] = TRUE;
  2587. }
  2588. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2589. {
  2590. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2591. if((access(filenmae,F_OK))!=-1)
  2592. {
  2593. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2594. sprintf(str,"rm -f %s",filenmae);
  2595. system(str);
  2596. }
  2597. }
  2598. #if 1 // for TempStopTransaction
  2599. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2600. {
  2601. checkTempStopTransaction(gun_index);
  2602. }
  2603. #endif
  2604. }
  2605. }
  2606. }
  2607. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2608. {
  2609. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2610. {
  2611. tempIndex = ((gun_index==2) ? 1: 0);
  2612. }
  2613. else
  2614. {
  2615. tempIndex = gun_index;
  2616. }
  2617. for (int index = 0; index < GB_QUANTITY; index++)
  2618. {
  2619. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2620. {
  2621. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  2622. {
  2623. // Sent unplug message for California pricing logic
  2624. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  2625. {
  2626. uint8_t ts[20];
  2627. getNowDatetime(ts);
  2628. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2629. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2630. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2631. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2632. }
  2633. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2634. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2635. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2636. statusModeChage[gun_index] = TRUE;
  2637. }
  2638. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2639. {
  2640. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2641. if((access(filenmae,F_OK))!=-1)
  2642. {
  2643. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2644. sprintf(str,"rm -f %s",filenmae);
  2645. system(str);
  2646. }
  2647. }
  2648. #if 1 // for TempStopTransaction
  2649. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2650. {
  2651. checkTempStopTransaction(gun_index);
  2652. }
  2653. #endif
  2654. }
  2655. }
  2656. }
  2657. else if(gunType[gun_index] == GUN_TYPE_DO)
  2658. {
  2659. tempIndex = gun_index;
  2660. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2661. {
  2662. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2663. {
  2664. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  2665. {
  2666. // Sent unplug message for California pricing logic
  2667. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  2668. {
  2669. uint8_t ts[20];
  2670. getNowDatetime(ts);
  2671. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2672. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2673. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2674. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2675. }
  2676. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  2677. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  2678. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2679. statusModeChage[gun_index] = TRUE;
  2680. }
  2681. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARING))) // complete
  2682. {
  2683. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2684. if((access(filenmae,F_OK))!=-1)
  2685. {
  2686. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2687. sprintf(str,"rm -f %s",filenmae);
  2688. system(str);
  2689. }
  2690. }
  2691. #if 1 // for TempStopTransaction
  2692. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2693. {
  2694. checkTempStopTransaction(gun_index);
  2695. }
  2696. #endif
  2697. }
  2698. }
  2699. }
  2700. else
  2701. {
  2702. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2703. {
  2704. tempIndex = 2;
  2705. }
  2706. else
  2707. {
  2708. tempIndex = gun_index;
  2709. }
  2710. for (int index = 0; index < AC_QUANTITY; index++)
  2711. {
  2712. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2713. {
  2714. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  2715. {
  2716. // Sent unplug message for California pricing logic
  2717. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)
  2718. {
  2719. uint8_t ts[20];
  2720. getNowDatetime(ts);
  2721. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2722. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2723. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2724. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2725. }
  2726. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2727. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2728. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2729. statusModeChage[gun_index] = TRUE;
  2730. }
  2731. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2732. {
  2733. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2734. if((access(filenmae,F_OK))!=-1)
  2735. {
  2736. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2737. sprintf(str,"rm -f %s",filenmae);
  2738. system(str);
  2739. }
  2740. }
  2741. #if 1 // for TempStopTransaction
  2742. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2743. {
  2744. checkTempStopTransaction(gun_index);
  2745. }
  2746. #endif
  2747. }
  2748. }// END
  2749. }
  2750. if(isWebsocketSendable && (server_sign == TRUE) &&
  2751. (
  2752. (statusModeChage[gun_index] == TRUE) ||
  2753. //((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index))) ||
  2754. ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 5))
  2755. )
  2756. )
  2757. {
  2758. if(SystemInitial > 0)
  2759. SystemInitial -= 1;
  2760. sendStatusNotificationRequest(gun_index);
  2761. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2762. statusModeChage[gun_index] = FALSE;
  2763. }
  2764. //==============================================
  2765. // Meter report
  2766. //==============================================
  2767. // Trigger MeterValue
  2768. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  2769. {
  2770. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  2771. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  2772. }
  2773. // ClockAlign MeterValue
  2774. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  2775. {
  2776. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2777. {
  2778. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2779. {
  2780. tempIndex = ((gun_index==2) ? 1: 0);
  2781. }
  2782. else
  2783. {
  2784. tempIndex = gun_index;
  2785. }
  2786. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2787. {
  2788. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2789. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2790. {
  2791. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2792. {
  2793. reqClockAlignMeter[gun_index] = 1;
  2794. }
  2795. }
  2796. }// End for CHAdeMO
  2797. }
  2798. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2799. {
  2800. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2801. {
  2802. tempIndex = ((gun_index==2) ? 1: 0);
  2803. }
  2804. else
  2805. {
  2806. tempIndex = gun_index;
  2807. }
  2808. for (int index = 0; index < CCS_QUANTITY; index++)
  2809. {
  2810. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2811. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2812. {
  2813. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2814. {
  2815. reqClockAlignMeter[gun_index] = 1;
  2816. }
  2817. }
  2818. } // End for CCS
  2819. }
  2820. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2821. {
  2822. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2823. {
  2824. tempIndex = ((gun_index==2) ? 1: 0);
  2825. }
  2826. else
  2827. {
  2828. tempIndex = gun_index;
  2829. }
  2830. for (int index = 0; index < GB_QUANTITY; index++)
  2831. {
  2832. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2833. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2834. {
  2835. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2836. {
  2837. reqClockAlignMeter[gun_index] = 1;
  2838. }
  2839. }
  2840. }// End for GB
  2841. }
  2842. else if(gunType[gun_index] == GUN_TYPE_DO)
  2843. {
  2844. tempIndex = gun_index;
  2845. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2846. {
  2847. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2848. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2849. {
  2850. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_CHARGING)
  2851. {
  2852. reqClockAlignMeter[gun_index] = 1;
  2853. }
  2854. }
  2855. }
  2856. }
  2857. else
  2858. {
  2859. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2860. {
  2861. tempIndex = 2;
  2862. }
  2863. else
  2864. {
  2865. tempIndex = gun_index;
  2866. }
  2867. for (int index = 0; index < AC_QUANTITY; index++)
  2868. {
  2869. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2870. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2871. {
  2872. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2873. {
  2874. reqClockAlignMeter[gun_index] = 1;
  2875. }
  2876. }
  2877. }//End for AC
  2878. }
  2879. if(reqClockAlignMeter[gun_index] == 1)
  2880. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  2881. }
  2882. // Sample period MeterValue
  2883. if((((time((time_t*)NULL) - clientTime.MeterValues[gun_index]) > (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1))))
  2884. {
  2885. //check Transaction active
  2886. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2887. {
  2888. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2889. {
  2890. tempIndex = ((gun_index==2) ? 1: 0);
  2891. }
  2892. else
  2893. {
  2894. tempIndex = gun_index;
  2895. }
  2896. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2897. {
  2898. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2899. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2900. {
  2901. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2902. {
  2903. reqSampleMeter[gun_index] = 1;
  2904. }
  2905. }
  2906. }// End for CHAdeMO
  2907. }
  2908. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2909. {
  2910. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2911. {
  2912. tempIndex = ((gun_index==2) ? 1: 0);
  2913. }
  2914. else
  2915. {
  2916. tempIndex = gun_index;
  2917. }
  2918. for (int index = 0; index < CCS_QUANTITY; index++)
  2919. {
  2920. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2921. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2922. {
  2923. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2924. {
  2925. reqSampleMeter[gun_index] = 1;
  2926. }
  2927. }
  2928. } // End for CCS
  2929. }
  2930. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2931. {
  2932. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2933. {
  2934. tempIndex = ((gun_index==2) ? 1: 0);
  2935. }
  2936. else
  2937. {
  2938. tempIndex = gun_index;
  2939. }
  2940. for (int index = 0; index < GB_QUANTITY; index++)
  2941. {
  2942. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2943. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2944. {
  2945. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2946. {
  2947. reqSampleMeter[gun_index] = 1;
  2948. }
  2949. }
  2950. }// End for GB
  2951. }
  2952. else if(gunType[gun_index] == GUN_TYPE_DO)
  2953. {
  2954. tempIndex = gun_index;
  2955. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2956. {
  2957. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2958. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2959. {
  2960. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  2961. {
  2962. reqSampleMeter[gun_index] = 1;
  2963. }
  2964. }
  2965. }
  2966. }
  2967. else
  2968. {
  2969. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2970. {
  2971. tempIndex = 2;
  2972. }
  2973. else
  2974. {
  2975. tempIndex = gun_index;
  2976. }
  2977. for (int index = 0; index < AC_QUANTITY; index++)
  2978. {
  2979. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2980. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2981. {
  2982. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  2983. {
  2984. reqSampleMeter[gun_index] = 1;
  2985. }
  2986. }
  2987. }//End for AC
  2988. }
  2989. if(reqSampleMeter[gun_index] == 1)
  2990. {
  2991. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  2992. storeTempStopTransaction(gun_index);
  2993. }
  2994. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2995. }
  2996. //==============================================
  2997. // Check Connector reserved
  2998. //==============================================
  2999. //===============================
  3000. // Check if Reserve is expired
  3001. //===============================
  3002. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  3003. {
  3004. double diff_t;
  3005. struct tm tp;
  3006. // current time
  3007. time_t t = time(NULL);
  3008. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  3009. tp.tm_isdst = -1;
  3010. time_t utc = mktime(&tp);
  3011. diff_t = difftime(utc, t);
  3012. if(diff_t <= 0)
  3013. {
  3014. DEBUG_INFO("reserve expired.\n");
  3015. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  3016. }
  3017. }//END OF Check if Reserve is expired
  3018. //==========================================
  3019. // csu trigger FirmwareStatusNotificationReq
  3020. //==========================================
  3021. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  3022. {
  3023. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  3024. }
  3025. //==========================================
  3026. // csu trigger DiagnosticsStatusNotificationReq
  3027. //==========================================
  3028. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  3029. {
  3030. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  3031. }
  3032. //==========================================
  3033. // csu trigger CancelReservationConf
  3034. //==========================================
  3035. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  3036. {
  3037. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  3038. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  3039. }
  3040. //==========================================
  3041. // csu trigger ChangeAvailabilityConf
  3042. //==========================================
  3043. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  3044. {
  3045. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  3046. }
  3047. //==========================================
  3048. // csu trigger UnlockConnectorConf
  3049. //==========================================
  3050. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  3051. {
  3052. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  3053. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  3054. }
  3055. //==========================================
  3056. // csu trigger ReserveNowConf
  3057. //==========================================
  3058. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  3059. {
  3060. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  3061. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  3062. }
  3063. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  3064. {
  3065. sendSignCertificateRequest();
  3066. }
  3067. }
  3068. }
  3069. //==========================================
  3070. // send request routine
  3071. //==========================================
  3072. int sendAuthorizeRequest(int gun_index)
  3073. {
  3074. mtrace();
  3075. int result = FAIL;
  3076. char message[100]={0};
  3077. char guid[37];
  3078. char tempdata[65]={0};
  3079. DEBUG_INFO("sendAuthorizeRequest...\n");
  3080. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  3081. //Local Authorize
  3082. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  3083. {
  3084. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  3085. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  3086. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  3087. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  3088. result = PASS;
  3089. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3090. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3091. authorizeRetryTimes = 0;
  3092. return result;
  3093. }
  3094. else if(((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0))||
  3095. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  3096. {
  3097. // Query from cache
  3098. DEBUG_INFO("Authorize from cache.\n");
  3099. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3100. // Query from list
  3101. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3102. {
  3103. DEBUG_INFO("Authorize from list.\n");
  3104. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3105. }
  3106. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3107. {
  3108. if(strcmp(idTagQuery.idTagstr,"") == 0)
  3109. {
  3110. DEBUG_INFO("off-line Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  3111. }
  3112. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  3113. {
  3114. DEBUG_INFO("off-line Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  3115. }
  3116. DEBUG_INFO("off-line Local Authorization Fail !!!!\n");
  3117. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3118. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3119. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  3120. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  3121. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3122. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3123. authorizeRetryTimes = 0;
  3124. return result;
  3125. }
  3126. else
  3127. {
  3128. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  3129. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3130. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3131. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  3132. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  3133. else
  3134. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  3135. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  3136. result = PASS;
  3137. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3138. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3139. authorizeRetryTimes = 0;
  3140. return result;
  3141. }
  3142. }
  3143. //initialize struct Authorize
  3144. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  3145. //get data from shared memory
  3146. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3147. random_uuid(guid);
  3148. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  3149. LWS_Send(message);
  3150. sprintf(tempdata, "Authorize,%d", gun_index);
  3151. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3152. {
  3153. result = PASS;
  3154. DEBUG_INFO("Authorize mapItem pass\n");
  3155. }
  3156. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3157. return result;
  3158. }
  3159. int sendBootNotificationRequest(void)
  3160. {
  3161. mtrace();
  3162. int result = FAIL;
  3163. char message[500]={0}, payload[700]={0};
  3164. char guid[37]={0};
  3165. char tempdata[65]={0};
  3166. // Fill BootNotification fields
  3167. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  3168. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  3169. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  3170. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3171. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  3172. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  3173. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  3174. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  3175. ShmOCPP16Data->ChargeBoxId
  3176. ,ShmSysConfigAndInfo->SysConfig.ModelName
  3177. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  3178. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  3179. ,ShmOCPP16Data->BootNotification.CpFwVersion
  3180. ,ShmOCPP16Data->BootNotification.CpIccid
  3181. ,ShmOCPP16Data->BootNotification.CpImsi);
  3182. random_uuid(guid);
  3183. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  3184. LWS_Send(message);
  3185. sprintf(tempdata, "BootNotification,0");
  3186. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid,mapItem, tempdata/*(void**)(&mapItem)*//*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  3187. {
  3188. result = PASS;
  3189. }
  3190. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3191. strcpy(queuedata,message);
  3192. return result;
  3193. }
  3194. int sendDataTransferRequest(int gun_index)
  3195. {
  3196. mtrace();
  3197. char message[1000]={0};
  3198. char guid[37]={0};
  3199. char tempdata[65]={0};
  3200. int result = FAIL;
  3201. random_uuid(guid);
  3202. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  3203. MESSAGE_TYPE_CALL,
  3204. guid,
  3205. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  3206. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  3207. ShmOCPP16Data->DataTransfer[gun_index].Data);
  3208. LWS_Send(message);
  3209. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  3210. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3211. {
  3212. result = PASS;
  3213. DEBUG_INFO("DataTransfer mapItem pass\n");
  3214. }
  3215. return result;
  3216. }
  3217. int sendDiagnosticsStatusNotificationRequest(char *status)
  3218. {
  3219. mtrace();
  3220. int result = FAIL;
  3221. char message[110]={0};
  3222. char guid[37]={0};
  3223. char tempdata[65]={0};
  3224. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  3225. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  3226. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  3227. random_uuid(guid);
  3228. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  3229. LWS_SendNow(message);
  3230. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  3231. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3232. {
  3233. result = PASS;
  3234. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  3235. }
  3236. //#ifdef SystemLogMessage
  3237. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  3238. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3239. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  3240. //#endif
  3241. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  3242. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  3243. //record status
  3244. if(strcmp(status,"Idle")==0)
  3245. {
  3246. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  3247. }
  3248. else if(strcmp(status,"Uploaded")==0)
  3249. {
  3250. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  3251. }
  3252. else if(strcmp(status,"UploadFailed")==0)
  3253. {
  3254. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  3255. }
  3256. else if(strcmp(status,"Uploading")==0)
  3257. {
  3258. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  3259. }
  3260. return result;
  3261. }
  3262. int sendFirmwareStatusNotificationRequest(char *status)
  3263. {
  3264. mtrace();
  3265. int result = FAIL;
  3266. char message[110]={0};
  3267. char guid[37]={0};
  3268. char tempdata[65]={0};
  3269. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  3270. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  3271. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  3272. random_uuid(guid);
  3273. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  3274. LWS_SendNow(message);
  3275. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  3276. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  3277. {
  3278. result = PASS;
  3279. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  3280. }
  3281. //#ifdef SystemLogMessage
  3282. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  3283. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3284. //#endif
  3285. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  3286. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  3287. //record status
  3288. if(strcmp(status,"Downloaded")==0)
  3289. {
  3290. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  3291. }
  3292. else if(strcmp(status,"DownloadFailed")==0)
  3293. {
  3294. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  3295. }
  3296. else if(strcmp(status,"Downloading")==0)
  3297. {
  3298. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  3299. }
  3300. else if(strcmp(status,"Idle")==0)
  3301. {
  3302. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  3303. }
  3304. else if(strcmp(status,"InstallationFailed")==0)
  3305. {
  3306. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  3307. }
  3308. else if(strcmp(status,"Installing")==0)
  3309. {
  3310. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  3311. }
  3312. else if(strcmp(status,"Installed")==0)
  3313. {
  3314. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  3315. }
  3316. return result;
  3317. }
  3318. int sendHeartbeatRequest(int gun_index)
  3319. {
  3320. mtrace();
  3321. int result = FAIL;
  3322. char message[80]={0};
  3323. char guid[37]={0};
  3324. char tempdata[65]={0};
  3325. random_uuid(guid);
  3326. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  3327. , MESSAGE_TYPE_CALL
  3328. , guid );
  3329. LWS_Send(message);
  3330. sprintf(tempdata, "Heartbeat,%d", 0);
  3331. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid, mapItem, tempdata/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  3332. {
  3333. result = PASS;
  3334. }
  3335. return result;
  3336. }
  3337. int sendStartTransactionRequest(int gun_index)
  3338. {
  3339. mtrace();
  3340. int result = FAIL;
  3341. char message[250]={0};
  3342. char guid[37]={0};
  3343. struct timeval tmnow;
  3344. struct tm *tm;
  3345. char buf[28];//, usec_buf[6];
  3346. char tempdata[65]={0};
  3347. int tempIndex = 0;
  3348. DEBUG_INFO("sendStartTransactionRequest...\n");
  3349. gettimeofday(&tmnow, NULL);
  3350. time_t t;
  3351. t = time(NULL);
  3352. /*UTC time and date*/
  3353. tm = gmtime(&t);
  3354. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3355. #if 0 // remove temporally
  3356. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3357. strcat(buf,".");
  3358. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3359. strcat(buf,usec_buf);
  3360. #endif
  3361. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  3362. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  3363. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3364. // clear StartTransaction Response
  3365. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  3366. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  3367. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  3368. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  3369. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3370. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3371. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3372. {
  3373. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3374. {
  3375. tempIndex = ((gun_index==2) ? 1: 0);
  3376. }
  3377. else
  3378. {
  3379. tempIndex = gun_index;
  3380. }
  3381. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3382. {
  3383. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3384. {
  3385. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3386. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  3387. }
  3388. }
  3389. }
  3390. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3391. {
  3392. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3393. {
  3394. tempIndex = ((gun_index==2) ? 1: 0);
  3395. }
  3396. else
  3397. {
  3398. tempIndex = gun_index;
  3399. }
  3400. for (int index = 0; index < CCS_QUANTITY; index++)
  3401. {
  3402. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3403. {
  3404. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3405. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  3406. }
  3407. }
  3408. }
  3409. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3410. {
  3411. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3412. {
  3413. tempIndex = ((gun_index==2) ? 1: 0);
  3414. }
  3415. else
  3416. {
  3417. tempIndex = gun_index;
  3418. }
  3419. for (int index = 0; index < GB_QUANTITY; index++)
  3420. {
  3421. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3422. {
  3423. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3424. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  3425. }
  3426. }
  3427. }
  3428. else if(gunType[gun_index] == GUN_TYPE_DO)
  3429. {
  3430. tempIndex = gun_index;
  3431. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3432. {
  3433. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3434. {
  3435. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3436. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  3437. }
  3438. }
  3439. }
  3440. else
  3441. {
  3442. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3443. {
  3444. tempIndex = 2;
  3445. }
  3446. else
  3447. {
  3448. tempIndex = gun_index;
  3449. }
  3450. for (int index = 0; index < AC_QUANTITY; index++)
  3451. {
  3452. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3453. {
  3454. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3455. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  3456. }
  3457. }
  3458. }
  3459. random_uuid(guid);
  3460. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  3461. {
  3462. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  3463. , gun_index +1
  3464. , MESSAGE_TYPE_CALL
  3465. , guid
  3466. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3467. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3468. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3469. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3470. }
  3471. else
  3472. {
  3473. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  3474. , gun_index +1
  3475. , MESSAGE_TYPE_CALL
  3476. , guid
  3477. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3478. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3479. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3480. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  3481. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3482. }
  3483. #if 1
  3484. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  3485. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  3486. {
  3487. result = PASS;
  3488. }
  3489. #endif
  3490. strcpy(queuedata, message);
  3491. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3492. OCPP_insert_transaction_msg(YES, queuedata);
  3493. return result;
  3494. }
  3495. int sendStatusNotificationRequest(int gun_index)
  3496. {
  3497. mtrace();
  3498. int result = FAIL;
  3499. char message[600]={0};
  3500. char guid[37];
  3501. int currentStatus = 0;
  3502. struct timeval tmnow;
  3503. struct tm *tm;
  3504. char buf[28];//, usec_buf[6];
  3505. char tempdata[65]={0};
  3506. int tempIndex = 0;
  3507. uint8_t isStateChanged = TRUE;
  3508. DEBUG_INFO("sendStatusNotificationRequest...\n");
  3509. gettimeofday(&tmnow, NULL);
  3510. time_t t;
  3511. t = time(NULL);
  3512. /*UTC time and date*/
  3513. tm = gmtime(&t);
  3514. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3515. #if 0 // remove temporally
  3516. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3517. strcat(buf,".");
  3518. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3519. strcat(buf,usec_buf);
  3520. #endif
  3521. printf("%s",buf);
  3522. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  3523. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  3524. // it's option
  3525. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  3526. /*
  3527. enum _SYSTEM_STATUS
  3528. {
  3529. S_BOOTING = 0,
  3530. S_IDLE, = 1
  3531. S_AUTHORIZING, =2
  3532. S_REASSIGN_CHECK, =3
  3533. S_REASSIGN, =4
  3534. S_PRECHARGE, =5
  3535. S_PREPARING_FOR_EV, =6
  3536. S_PREPARING_FOR_EVSE, =7
  3537. S_CHARGING, =8
  3538. S_TERMINATING, =9
  3539. S_COMPLETE, =10
  3540. S_ALARM, =11
  3541. S_FAULT =12
  3542. }
  3543. */
  3544. //check Transaction active
  3545. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3546. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3547. {
  3548. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3549. {
  3550. tempIndex = ((gun_index==2) ? 1: 0);
  3551. }
  3552. else
  3553. {
  3554. tempIndex = gun_index;
  3555. }
  3556. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3557. {
  3558. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  3559. {
  3560. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  3561. {
  3562. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3563. {
  3564. currentStatus = Preparing; //OCPP Status: Preparing
  3565. }
  3566. else
  3567. {
  3568. currentStatus = Available; //OCPP Status: Available
  3569. }
  3570. }
  3571. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3572. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3573. ) //S_PRECHARGE
  3574. {
  3575. currentStatus = Preparing; //OCPP Status: Preparing
  3576. }
  3577. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3578. {
  3579. currentStatus = Charging; //OCPP Status: Charging
  3580. }
  3581. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3582. {
  3583. currentStatus = Finishing; //OCPP Status: Finishing
  3584. }
  3585. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3586. {
  3587. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3588. }
  3589. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  3590. {
  3591. currentStatus = Unavailable; //OCPP Status: Unavailable
  3592. }
  3593. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3594. {
  3595. currentStatus = Faulted; //OCPP Status: Faulted
  3596. }
  3597. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3598. {
  3599. currentStatus = Reserved; //OCPP Status: Reserved
  3600. }
  3601. } //end of the same index
  3602. }//end of for CHAdeMO_QUANTITY
  3603. }
  3604. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3605. {
  3606. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3607. {
  3608. tempIndex = ((gun_index==2) ? 1: 0);
  3609. }
  3610. else
  3611. {
  3612. tempIndex = gun_index;
  3613. }
  3614. for (int index = 0; index < CCS_QUANTITY; index++)
  3615. {
  3616. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3617. {
  3618. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3619. {
  3620. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3621. {
  3622. currentStatus = Preparing; //OCPP Status: Preparing
  3623. }
  3624. else
  3625. {
  3626. currentStatus = Available; //OCPP Status: Available
  3627. }
  3628. }
  3629. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3630. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3631. ) //S_PRECHARGE
  3632. {
  3633. currentStatus = Preparing; //OCPP Status: Preparing
  3634. }
  3635. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3636. {
  3637. currentStatus = Charging; //OCPP Status: Charging
  3638. }
  3639. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3640. {
  3641. currentStatus = Finishing; //OCPP Status: Finishing
  3642. }
  3643. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3644. {
  3645. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3646. }
  3647. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  3648. {
  3649. currentStatus = Unavailable; //OCPP Status : Unavailable
  3650. }
  3651. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3652. {
  3653. currentStatus = Faulted; //OCPP Status: Faulted
  3654. }
  3655. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3656. {
  3657. currentStatus = Reserved; //OCPP Status: Reserved
  3658. }
  3659. } //end of the same index
  3660. } // end of for CCS_QUANTITY
  3661. }
  3662. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3663. {
  3664. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3665. {
  3666. tempIndex = ((gun_index==2) ? 1: 0);
  3667. }
  3668. else
  3669. {
  3670. tempIndex = gun_index;
  3671. }
  3672. for (int index = 0; index < GB_QUANTITY; index++)
  3673. {
  3674. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3675. {
  3676. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3677. {
  3678. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3679. {
  3680. currentStatus = Preparing; //OCPP Status: Preparing
  3681. }
  3682. else
  3683. {
  3684. currentStatus = Available; //OCPP Status: Available
  3685. }
  3686. }
  3687. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3688. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3689. ) //S_PRECHARGE
  3690. {
  3691. currentStatus = Preparing; //OCPP Status: Preparing
  3692. }
  3693. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3694. {
  3695. currentStatus = Charging; //OCPP Status: Charging
  3696. }
  3697. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3698. {
  3699. currentStatus = Finishing; //OCPP Status: Finishing
  3700. }
  3701. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3702. {
  3703. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3704. }
  3705. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  3706. {
  3707. currentStatus = Unavailable; //OCPP Status: Unavailable
  3708. }
  3709. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3710. {
  3711. currentStatus = Faulted; //OCPP Status: Faulted
  3712. }
  3713. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3714. {
  3715. currentStatus = Reserved; //OCPP Status: Reserved
  3716. }
  3717. } //end of the same index
  3718. } // end of for GB_QUANTITY
  3719. }
  3720. else if(gunType[gun_index] == GUN_TYPE_DO)
  3721. {
  3722. tempIndex = gun_index;
  3723. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3724. {
  3725. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3726. {
  3727. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3728. {
  3729. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3730. {
  3731. currentStatus = Preparing; //OCPP Status: Preparing
  3732. }
  3733. else
  3734. {
  3735. currentStatus = Available; //OCPP Status: Available
  3736. }
  3737. }
  3738. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3739. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3740. ) //S_PRECHARGE
  3741. {
  3742. currentStatus = Preparing; //OCPP Status: Preparing
  3743. }
  3744. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3745. {
  3746. currentStatus = Charging; //OCPP Status: Charging
  3747. }
  3748. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3749. {
  3750. currentStatus = Finishing; //OCPP Status: Finishing
  3751. }
  3752. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3753. {
  3754. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3755. }
  3756. else if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  3757. {
  3758. currentStatus = Unavailable; //OCPP Status: Unavailable
  3759. }
  3760. else if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3761. {
  3762. currentStatus = Faulted; //OCPP Status: Faulted
  3763. }
  3764. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3765. {
  3766. currentStatus = Reserved; //OCPP Status: Reserved
  3767. }
  3768. } //end of the same index
  3769. }
  3770. }
  3771. else
  3772. {
  3773. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3774. {
  3775. tempIndex = 2;
  3776. }
  3777. else
  3778. {
  3779. tempIndex = gun_index;
  3780. }
  3781. for (int index = 0; index < AC_QUANTITY; index++)
  3782. {
  3783. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3784. {
  3785. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3786. {
  3787. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_C) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_D))
  3788. {
  3789. currentStatus = Preparing; //OCPP Status: Preparing
  3790. }
  3791. else
  3792. {
  3793. currentStatus = Available; //OCPP Status: Available
  3794. }
  3795. }
  3796. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  3797. {
  3798. currentStatus = Preparing; //OCPP Status: Preparing
  3799. }
  3800. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3801. {
  3802. currentStatus = Charging; //OCPP Status: Charging
  3803. }
  3804. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3805. {
  3806. currentStatus = Finishing; //OCPP Status: Finishing
  3807. }
  3808. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3809. {
  3810. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  3811. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3812. else
  3813. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  3814. }
  3815. 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
  3816. {
  3817. currentStatus = Unavailable; //OCPP Status: Unavailable
  3818. }
  3819. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3820. {
  3821. currentStatus = Faulted; //OCPP Status: Faulted
  3822. }
  3823. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3824. {
  3825. currentStatus = Reserved; //OCPP Status: Reserved
  3826. }
  3827. }//end of the same index
  3828. }//end of for AC_QUANTITY
  3829. }
  3830. //it's option
  3831. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  3832. !ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq)
  3833. {
  3834. isStateChanged = FALSE;
  3835. }
  3836. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  3837. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3838. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3839. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3840. random_uuid(guid);
  3841. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3842. , MESSAGE_TYPE_CALL
  3843. , guid
  3844. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3845. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3846. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3847. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3848. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3849. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3850. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3851. if((server_sign == TRUE) && isStateChanged)
  3852. {
  3853. LWS_Send(message);
  3854. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3855. 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*/)
  3856. {
  3857. //DEBUG_ERROR("statusNotification mapitem pass");
  3858. result = PASS;
  3859. }
  3860. }
  3861. else
  3862. {
  3863. result = PASS;
  3864. }
  3865. return result;
  3866. }
  3867. int sendStopTransactionRequest(int gun_index)
  3868. {
  3869. mtrace();
  3870. int result = FAIL;
  3871. //char message[1500]={0};
  3872. char guid[37]={0};
  3873. char tempdata[65]={0};
  3874. int tempIndex = 0;
  3875. char TempStopTransaction[256];
  3876. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  3877. //int idx_sample=0;
  3878. DEBUG_INFO("sendStopTransactionRequest \n");
  3879. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3880. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  3881. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  3882. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3883. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3884. {
  3885. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3886. {
  3887. tempIndex = ((gun_index==2) ? 1: 0);
  3888. }
  3889. else
  3890. {
  3891. tempIndex = gun_index;
  3892. }
  3893. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3894. {
  3895. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3896. {
  3897. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3898. }
  3899. }// END OF CHAdeMO_QUANTITY
  3900. }
  3901. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3902. {
  3903. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3904. {
  3905. tempIndex = ((gun_index==2) ? 1: 0);
  3906. }
  3907. else
  3908. {
  3909. tempIndex = gun_index;
  3910. }
  3911. for (int index = 0; index < CCS_QUANTITY; index++)
  3912. {
  3913. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3914. {
  3915. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3916. }
  3917. }// END OF CCS_QUANTITY
  3918. }
  3919. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3920. {
  3921. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3922. {
  3923. tempIndex = ((gun_index==2) ? 1: 0);
  3924. }
  3925. else
  3926. {
  3927. tempIndex = gun_index;
  3928. }
  3929. for (int index = 0; index < GB_QUANTITY; index++)
  3930. {
  3931. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3932. {
  3933. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3934. }
  3935. }// END OF GB_QUANTITY
  3936. }
  3937. else if(gunType[gun_index] == GUN_TYPE_DO)
  3938. {
  3939. tempIndex = gun_index;
  3940. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3941. {
  3942. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3943. {
  3944. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3945. }
  3946. }// END OF GB_QUANTITY
  3947. }
  3948. else
  3949. {
  3950. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3951. {
  3952. tempIndex = 2;
  3953. }
  3954. else
  3955. {
  3956. tempIndex = gun_index;
  3957. }
  3958. for (int index = 0; index < AC_QUANTITY; index++)
  3959. {
  3960. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3961. {
  3962. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3963. }
  3964. }// END OF AC_QUANTITY
  3965. }
  3966. //====================================== Stop Transaction Time =====================================================
  3967. struct timeval tmnow;
  3968. struct tm *tm;
  3969. char buf[28];//, usec_buf[6];
  3970. gettimeofday(&tmnow, NULL);
  3971. time_t t;
  3972. t = time(NULL);
  3973. /*UTC time and date*/
  3974. tm = gmtime(&t);
  3975. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3976. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  3977. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  3978. random_uuid(guid);
  3979. /***********************************transactionData******************************************************/
  3980. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  3981. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  3982. //=================================
  3983. // Transaction_Begin
  3984. //=================================
  3985. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  3986. {
  3987. //============================================ Energy.Active.Import.Interval ================================
  3988. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  3989. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  3990. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  3991. 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*/]);
  3992. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3993. 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))
  3994. {
  3995. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  3996. }
  3997. else
  3998. {
  3999. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  4000. }
  4001. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  4002. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4003. }
  4004. //=================================
  4005. // Transaction_End
  4006. //=================================
  4007. // ================================= Current.Import L1 ===============================================
  4008. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4009. {
  4010. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  4011. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4012. {
  4013. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4014. {
  4015. tempIndex = ((gun_index==2) ? 1: 0);
  4016. }
  4017. else
  4018. {
  4019. tempIndex = gun_index;
  4020. }
  4021. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4022. {
  4023. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4024. {
  4025. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4026. }
  4027. }// End of for CHAdeMO_QUANTITY
  4028. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4029. }
  4030. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4031. {
  4032. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4033. {
  4034. tempIndex = ((gun_index==2) ? 1: 0);
  4035. }
  4036. else
  4037. {
  4038. tempIndex = gun_index;
  4039. }
  4040. for (int index = 0; index < CCS_QUANTITY; index++)
  4041. {
  4042. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4043. {
  4044. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4045. }
  4046. }// End of for CCS_QUANTITY
  4047. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4048. }
  4049. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4050. {
  4051. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4052. {
  4053. tempIndex = ((gun_index==2) ? 1: 0);
  4054. }
  4055. else
  4056. {
  4057. tempIndex = gun_index;
  4058. }
  4059. for (int index = 0; index < GB_QUANTITY; index++)
  4060. {
  4061. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4062. {
  4063. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4064. }
  4065. }// End of for GB_QUANTITY
  4066. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4067. }
  4068. else if(gunType[gun_index] == GUN_TYPE_DO)
  4069. {
  4070. tempIndex = gun_index;
  4071. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4072. {
  4073. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4074. {
  4075. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4076. }
  4077. }
  4078. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4079. }
  4080. else
  4081. {
  4082. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4083. {
  4084. tempIndex = 2;
  4085. }
  4086. else
  4087. {
  4088. tempIndex = gun_index;
  4089. }
  4090. for (int index = 0; index < AC_QUANTITY; index++)
  4091. {
  4092. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4093. {
  4094. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  4095. }
  4096. }// End of for AC_QUANTITY
  4097. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  4098. }
  4099. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4100. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  4101. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  4102. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  4103. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4104. }
  4105. // ================================= Energy.Active.Import.Interval ==============================================
  4106. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4107. {
  4108. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4109. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4110. {
  4111. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4112. {
  4113. tempIndex = ((gun_index==2) ? 1: 0);
  4114. }
  4115. else
  4116. {
  4117. tempIndex = gun_index;
  4118. }
  4119. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4120. {
  4121. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4122. {
  4123. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4124. }
  4125. }// END OF CHAdeMO_QUANTITY
  4126. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4127. }
  4128. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4129. {
  4130. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4131. {
  4132. tempIndex = ((gun_index==2) ? 1: 0);
  4133. }
  4134. else
  4135. {
  4136. tempIndex = gun_index;
  4137. }
  4138. for (int index = 0; index < CCS_QUANTITY; index++)
  4139. {
  4140. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4141. {
  4142. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4143. }
  4144. }// END OF CCS_QUANTITY
  4145. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4146. }
  4147. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4148. {
  4149. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4150. {
  4151. tempIndex = ((gun_index==2) ? 1: 0);
  4152. }
  4153. else
  4154. {
  4155. tempIndex = gun_index;
  4156. }
  4157. for (int index = 0; index < GB_QUANTITY; index++)
  4158. {
  4159. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4160. {
  4161. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4162. }
  4163. }// END OF GB_QUANTITY
  4164. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4165. }
  4166. else if(gunType[gun_index] == GUN_TYPE_DO)
  4167. {
  4168. tempIndex = gun_index;
  4169. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4170. {
  4171. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4172. {
  4173. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4174. }
  4175. }
  4176. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4177. }
  4178. else
  4179. {
  4180. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4181. {
  4182. tempIndex = 2;
  4183. }
  4184. else
  4185. {
  4186. tempIndex = gun_index;
  4187. }
  4188. for (int index = 0; index < AC_QUANTITY; index++)
  4189. {
  4190. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4191. {
  4192. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4193. }
  4194. }// END OF AC_QUANTITY
  4195. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  4196. }
  4197. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4198. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  4199. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  4200. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  4201. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4202. }
  4203. //=================================== Power.Active.Import ==================================================
  4204. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  4205. {
  4206. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4207. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4208. {
  4209. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4210. {
  4211. tempIndex = ((gun_index==2) ? 1: 0);
  4212. }
  4213. else
  4214. {
  4215. tempIndex = gun_index;
  4216. }
  4217. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4218. {
  4219. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4220. {
  4221. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4222. }
  4223. } // End for CHAdeMO_QUANTITY
  4224. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4225. }
  4226. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4227. {
  4228. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4229. {
  4230. tempIndex = ((gun_index==2) ? 1: 0);
  4231. }
  4232. else
  4233. {
  4234. tempIndex = gun_index;
  4235. }
  4236. for (int index = 0; index < CCS_QUANTITY; index++)
  4237. {
  4238. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4239. {
  4240. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4241. }
  4242. } // END for CCS_QUANTITY
  4243. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4244. }
  4245. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4246. {
  4247. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4248. {
  4249. tempIndex = ((gun_index==2) ? 1: 0);
  4250. }
  4251. else
  4252. {
  4253. tempIndex = gun_index;
  4254. }
  4255. for (int index = 0; index < GB_QUANTITY; index++)
  4256. {
  4257. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4258. {
  4259. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4260. }
  4261. }// END for GB_QUANTITY
  4262. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4263. }
  4264. else if(gunType[gun_index] == GUN_TYPE_DO)
  4265. {
  4266. tempIndex = gun_index;
  4267. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4268. {
  4269. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4270. {
  4271. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4272. }
  4273. }
  4274. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4275. }
  4276. else
  4277. {
  4278. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4279. {
  4280. tempIndex = 2;
  4281. }
  4282. else
  4283. {
  4284. tempIndex = gun_index;
  4285. }
  4286. for (int index = 0; index < AC_QUANTITY; index++)
  4287. {
  4288. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4289. {
  4290. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4291. }
  4292. } // END for AC_QUANTITY
  4293. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  4294. }
  4295. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4296. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  4297. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  4298. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  4299. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  4300. }
  4301. //============================ Voltage L1 ====================================
  4302. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4303. {
  4304. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4305. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4306. {
  4307. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4308. {
  4309. tempIndex = ((gun_index==2) ? 1: 0);
  4310. }
  4311. else
  4312. {
  4313. tempIndex = gun_index;
  4314. }
  4315. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4316. {
  4317. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4318. {
  4319. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4320. }
  4321. } // END OF FOR CHAdeMO_QUANTITY
  4322. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4323. }
  4324. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4325. {
  4326. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4327. {
  4328. tempIndex = ((gun_index==2) ? 1: 0);
  4329. }
  4330. else
  4331. {
  4332. tempIndex = gun_index;
  4333. }
  4334. for (int index = 0; index < CCS_QUANTITY; index++)
  4335. {
  4336. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4337. {
  4338. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4339. }
  4340. } // END OF FOR CCS_QUANTITY
  4341. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4342. }
  4343. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4344. {
  4345. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4346. {
  4347. tempIndex = ((gun_index==2) ? 1: 0);
  4348. }
  4349. else
  4350. {
  4351. tempIndex = gun_index;
  4352. }
  4353. for (int index = 0; index < GB_QUANTITY; index++)
  4354. {
  4355. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4356. {
  4357. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4358. }
  4359. } // END OF FOR GB_QUANTITY
  4360. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4361. }
  4362. else if(gunType[gun_index] == GUN_TYPE_DO)
  4363. {
  4364. tempIndex = gun_index;
  4365. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4366. {
  4367. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4368. {
  4369. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4370. }
  4371. }
  4372. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4373. }
  4374. else
  4375. {
  4376. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4377. {
  4378. tempIndex = 2;
  4379. }
  4380. else
  4381. {
  4382. tempIndex = gun_index;
  4383. }
  4384. for (int index = 0; index < AC_QUANTITY; index++)
  4385. {
  4386. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4387. {
  4388. 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
  4389. }
  4390. } // END OF FOR AC_QUANTITY
  4391. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  4392. }
  4393. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4394. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  4395. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  4396. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  4397. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4398. }
  4399. //====================== End SoC ================================
  4400. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4401. {
  4402. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4403. 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))
  4404. {
  4405. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4406. {
  4407. tempIndex = ((gun_index==2) ? 1: 0);
  4408. }
  4409. else
  4410. {
  4411. tempIndex = gun_index;
  4412. }
  4413. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4414. {
  4415. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4416. {
  4417. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4418. {
  4419. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  4420. }
  4421. }
  4422. }
  4423. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4424. {
  4425. for (int index = 0; index < CCS_QUANTITY; index++)
  4426. {
  4427. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4428. {
  4429. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  4430. }
  4431. }
  4432. }
  4433. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4434. {
  4435. for (int index = 0; index < GB_QUANTITY; index++)
  4436. {
  4437. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4438. {
  4439. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  4440. }
  4441. }
  4442. }
  4443. else if(gunType[gun_index] == GUN_TYPE_DO)
  4444. {
  4445. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4446. {
  4447. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4448. {
  4449. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  4450. }
  4451. }
  4452. }
  4453. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4454. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  4455. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4456. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  4457. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  4458. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4459. } // END FOR DC CASE
  4460. }
  4461. // ================================= Current.Import L2 ===============================================
  4462. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4463. {
  4464. // AC 3 phse L2 current
  4465. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4466. {
  4467. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4468. {
  4469. tempIndex = 2;
  4470. }
  4471. else
  4472. {
  4473. tempIndex = gun_index;
  4474. }
  4475. for (int index = 0; index < AC_QUANTITY; index++)
  4476. {
  4477. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4478. {
  4479. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  4480. }
  4481. }// End of for AC_QUANTITY
  4482. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  4483. }
  4484. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4485. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  4486. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  4487. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  4488. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4489. }
  4490. // ================================= Current.Import L3 ===============================================
  4491. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4492. {
  4493. // AC 3 phse L3 current
  4494. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4495. {
  4496. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4497. {
  4498. tempIndex = 2;
  4499. }
  4500. else
  4501. {
  4502. tempIndex = gun_index;
  4503. }
  4504. for (int index = 0; index < AC_QUANTITY; index++)
  4505. {
  4506. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4507. {
  4508. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  4509. }
  4510. }// End of for AC_QUANTITY
  4511. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  4512. }
  4513. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4514. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  4515. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  4516. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  4517. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4518. }
  4519. //============================ Voltage L2 ====================================
  4520. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4521. {
  4522. // AC 3 phse L2 voltage
  4523. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4524. {
  4525. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4526. {
  4527. tempIndex = 2;
  4528. }
  4529. else
  4530. {
  4531. tempIndex = gun_index;
  4532. }
  4533. for (int index = 0; index < AC_QUANTITY; index++)
  4534. {
  4535. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4536. {
  4537. 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
  4538. }
  4539. } // END OF FOR AC_QUANTITY
  4540. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  4541. }
  4542. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4543. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  4544. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  4545. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  4546. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4547. }
  4548. //============================ Voltage L3 ====================================
  4549. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4550. {
  4551. // AC 3 phse L3 voltage
  4552. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4553. {
  4554. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4555. {
  4556. tempIndex = 2;
  4557. }
  4558. else
  4559. {
  4560. tempIndex = gun_index;
  4561. }
  4562. for (int index = 0; index < AC_QUANTITY; index++)
  4563. {
  4564. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4565. {
  4566. 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
  4567. }
  4568. } // END OF FOR AC_QUANTITY
  4569. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  4570. }
  4571. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4572. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  4573. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  4574. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  4575. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4576. }
  4577. //====================== Start SoC ================================
  4578. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4579. {
  4580. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4581. 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))
  4582. {
  4583. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4584. {
  4585. tempIndex = ((gun_index==2) ? 1: 0);
  4586. }
  4587. else
  4588. {
  4589. tempIndex = gun_index;
  4590. }
  4591. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4592. {
  4593. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4594. {
  4595. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4596. {
  4597. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  4598. }
  4599. }
  4600. }
  4601. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4602. {
  4603. for (int index = 0; index < CCS_QUANTITY; index++)
  4604. {
  4605. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4606. {
  4607. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  4608. }
  4609. }
  4610. }
  4611. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4612. {
  4613. for (int index = 0; index < GB_QUANTITY; index++)
  4614. {
  4615. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4616. {
  4617. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  4618. }
  4619. }
  4620. }
  4621. else if(gunType[gun_index] == GUN_TYPE_DO)
  4622. {
  4623. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4624. {
  4625. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4626. {
  4627. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  4628. }
  4629. }
  4630. }
  4631. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4632. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  4633. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4634. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  4635. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  4636. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4637. } // END FOR DC CASE
  4638. }
  4639. //================================================ Message create ====================================================
  4640. json_object *StopTransaction = json_object_new_object();
  4641. json_object *transactionDatas = json_object_new_array();
  4642. json_object *sampledValues = json_object_new_array();
  4643. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  4644. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  4645. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  4646. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  4647. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  4648. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  4649. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  4650. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  4651. {
  4652. json_object *transactionData = json_object_new_object();
  4653. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  4654. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  4655. {
  4656. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  4657. {
  4658. json_object *sampledValue = json_object_new_object();
  4659. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  4660. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  4661. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  4662. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  4663. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  4664. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  4665. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  4666. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  4667. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  4668. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  4669. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  4670. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  4671. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  4672. json_object_array_add(sampledValues, sampledValue);
  4673. }
  4674. }
  4675. json_object_object_add(transactionData, "sampledValue", sampledValues);
  4676. json_object_array_add(transactionDatas, transactionData);
  4677. }
  4678. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  4679. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  4680. ,MESSAGE_TYPE_CALL
  4681. ,guid
  4682. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  4683. json_object_put(StopTransaction);
  4684. #if 1 // for TempStopTransaction
  4685. //Delete TempStopTransaction
  4686. if((access(TempStopTransaction,F_OK))!=-1)
  4687. {
  4688. remove(TempStopTransaction); // remove file "TempStopTransaction"
  4689. }
  4690. #endif
  4691. #if 1
  4692. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4693. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4694. {
  4695. result = PASS;
  4696. //DEBUG_INFO("StopTransaction mapitem pass\n");
  4697. }
  4698. #endif
  4699. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4700. OCPP_insert_transaction_msg(NO, queuedata);
  4701. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4702. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  4703. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  4704. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4705. {
  4706. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  4707. }
  4708. //for test
  4709. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4710. return result;
  4711. }
  4712. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  4713. {
  4714. mtrace();
  4715. int result = FAIL;
  4716. char guid[37]={0};
  4717. char tempdata[65]={0};
  4718. int tempIndex = 0;
  4719. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4720. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4721. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  4722. //set value
  4723. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4724. 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) )?
  4725. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  4726. -1);
  4727. random_uuid(guid);
  4728. //UTC Date time
  4729. struct timeval tmnow;
  4730. struct tm *tm;
  4731. char buf[28];//, usec_buf[6];
  4732. gettimeofday(&tmnow, NULL);
  4733. time_t t;
  4734. t = time(NULL);
  4735. /*UTC time and date*/
  4736. tm = gmtime(&t);
  4737. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4738. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4739. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4740. //********************************(1)Current.Import L1************************************************/
  4741. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  4742. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  4743. (dataType == ReadingContext_Trigger))
  4744. {
  4745. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4746. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4747. {
  4748. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4749. {
  4750. tempIndex = ((gun_index==2) ? 1: 0);
  4751. }
  4752. else
  4753. {
  4754. tempIndex = gun_index;
  4755. }
  4756. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4757. {
  4758. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4759. {
  4760. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4761. }
  4762. }
  4763. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4764. }
  4765. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4766. {
  4767. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4768. {
  4769. tempIndex = ((gun_index==2) ? 1: 0);
  4770. }
  4771. else
  4772. {
  4773. tempIndex = gun_index;
  4774. }
  4775. for (int index = 0; index < CCS_QUANTITY; index++)
  4776. {
  4777. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4778. {
  4779. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4780. }
  4781. }
  4782. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4783. }
  4784. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4785. {
  4786. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4787. {
  4788. tempIndex = ((gun_index==2) ? 1: 0);
  4789. }
  4790. else
  4791. {
  4792. tempIndex = gun_index;
  4793. }
  4794. for (int index = 0; index < GB_QUANTITY; index++)
  4795. {
  4796. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4797. {
  4798. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4799. }
  4800. }
  4801. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4802. }
  4803. else if(gunType[gun_index] == GUN_TYPE_DO)
  4804. {
  4805. tempIndex = gun_index;
  4806. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4807. {
  4808. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4809. {
  4810. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  4811. }
  4812. }
  4813. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4814. }
  4815. else
  4816. {
  4817. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4818. {
  4819. tempIndex = 2;
  4820. }
  4821. else
  4822. {
  4823. tempIndex = gun_index;
  4824. }
  4825. for (int index = 0; index < AC_QUANTITY; index++)
  4826. {
  4827. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4828. {
  4829. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4830. }
  4831. }
  4832. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4833. }
  4834. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4835. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4836. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4837. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4838. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4839. }
  4840. //********************************(2)Energy.Active.Import.Register ************************************************/
  4841. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4842. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4843. (dataType == ReadingContext_Trigger))
  4844. {
  4845. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4846. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4847. {
  4848. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4849. {
  4850. tempIndex = ((gun_index==2) ? 1: 0);
  4851. }
  4852. else
  4853. {
  4854. tempIndex = gun_index;
  4855. }
  4856. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4857. {
  4858. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4859. {
  4860. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4861. }
  4862. }
  4863. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4864. }
  4865. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4866. {
  4867. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4868. {
  4869. tempIndex = ((gun_index==2) ? 1: 0);
  4870. }
  4871. else
  4872. {
  4873. tempIndex = gun_index;
  4874. }
  4875. for (int index = 0; index < CCS_QUANTITY; index++)
  4876. {
  4877. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4878. {
  4879. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4880. }
  4881. }
  4882. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4883. }
  4884. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4885. {
  4886. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4887. {
  4888. tempIndex = ((gun_index==2) ? 1: 0);
  4889. }
  4890. else
  4891. {
  4892. tempIndex = gun_index;
  4893. }
  4894. for (int index = 0; index < GB_QUANTITY; index++)
  4895. {
  4896. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4897. {
  4898. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4899. }
  4900. }
  4901. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4902. }
  4903. else if(gunType[gun_index] == GUN_TYPE_DO)
  4904. {
  4905. tempIndex = gun_index;
  4906. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4907. {
  4908. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4909. {
  4910. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  4911. }
  4912. }
  4913. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4914. }
  4915. else
  4916. {
  4917. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4918. {
  4919. tempIndex = 2;
  4920. }
  4921. else
  4922. {
  4923. tempIndex = gun_index;
  4924. }
  4925. for (int index = 0; index < AC_QUANTITY; index++)
  4926. {
  4927. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4928. {
  4929. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  4930. }
  4931. }
  4932. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4933. }
  4934. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  4935. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  4936. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  4937. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  4938. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4939. }
  4940. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  4941. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  4942. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  4943. (dataType == ReadingContext_Trigger))
  4944. {
  4945. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4946. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4947. {
  4948. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4949. {
  4950. tempIndex = ((gun_index==2) ? 1: 0);
  4951. }
  4952. else
  4953. {
  4954. tempIndex = gun_index;
  4955. }
  4956. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4957. {
  4958. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4959. {
  4960. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  4961. }
  4962. } // END OF FOR CHAdeMO_QUANTITY
  4963. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4964. }
  4965. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4966. {
  4967. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4968. {
  4969. tempIndex = ((gun_index==2) ? 1: 0);
  4970. }
  4971. else
  4972. {
  4973. tempIndex = gun_index;
  4974. }
  4975. for (int index = 0; index < CCS_QUANTITY; index++)
  4976. {
  4977. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4978. {
  4979. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  4980. }
  4981. } // END OF CCS_QUANTITY
  4982. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4983. }
  4984. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4985. {
  4986. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4987. {
  4988. tempIndex = ((gun_index==2) ? 1: 0);
  4989. }
  4990. else
  4991. {
  4992. tempIndex = gun_index;
  4993. }
  4994. for (int index = 0; index < GB_QUANTITY; index++)
  4995. {
  4996. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4997. {
  4998. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  4999. }
  5000. } // END OF GB_QUANTITY
  5001. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5002. }
  5003. else if(gunType[gun_index] == GUN_TYPE_DO)
  5004. {
  5005. tempIndex = gun_index;
  5006. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5007. {
  5008. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5009. {
  5010. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  5011. }
  5012. }
  5013. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5014. }
  5015. else
  5016. {
  5017. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5018. {
  5019. tempIndex = 2;
  5020. }
  5021. else
  5022. {
  5023. tempIndex = gun_index;
  5024. }
  5025. for (int index = 0; index < AC_QUANTITY; index++)
  5026. {
  5027. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5028. {
  5029. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  5030. }
  5031. }
  5032. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  5033. }
  5034. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  5035. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  5036. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  5037. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  5038. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5039. }
  5040. //********************************(4)Power.Active.Import************************************************/
  5041. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Power.Active.Import") != NULL)) ||
  5042. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Power.Active.Import") != NULL)) ||
  5043. (dataType == ReadingContext_Trigger))
  5044. {
  5045. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5046. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5047. {
  5048. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5049. {
  5050. tempIndex = ((gun_index==2) ? 1: 0);
  5051. }
  5052. else
  5053. {
  5054. tempIndex = gun_index;
  5055. }
  5056. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5057. {
  5058. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5059. {
  5060. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  5061. }
  5062. } // END OF FOR
  5063. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5064. }
  5065. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5066. {
  5067. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5068. {
  5069. tempIndex = ((gun_index==2) ? 1: 0);
  5070. }
  5071. else
  5072. {
  5073. tempIndex = gun_index;
  5074. }
  5075. for (int index = 0; index < CCS_QUANTITY; index++)
  5076. {
  5077. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5078. {
  5079. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  5080. }
  5081. }
  5082. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5083. }
  5084. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5085. {
  5086. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5087. {
  5088. tempIndex = ((gun_index==2) ? 1: 0);
  5089. }
  5090. else
  5091. {
  5092. tempIndex = gun_index;
  5093. }
  5094. for (int index = 0; index < GB_QUANTITY; index++)
  5095. {
  5096. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5097. {
  5098. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5099. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  5100. }
  5101. }
  5102. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5103. }
  5104. else if(gunType[gun_index] == GUN_TYPE_DO)
  5105. {
  5106. tempIndex = gun_index;
  5107. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5108. {
  5109. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5110. {
  5111. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5112. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  5113. }
  5114. }
  5115. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5116. }
  5117. else
  5118. {
  5119. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5120. {
  5121. tempIndex = 2;
  5122. }
  5123. else
  5124. {
  5125. tempIndex = gun_index;
  5126. }
  5127. for (int index = 0; index < AC_QUANTITY; index++)
  5128. {
  5129. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5130. {
  5131. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  5132. }
  5133. }
  5134. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  5135. }
  5136. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  5137. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  5138. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  5139. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  5140. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  5141. }
  5142. //***********************************************(5)VOLTAGE L1******************************************************/
  5143. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5144. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5145. (dataType == ReadingContext_Trigger))
  5146. {
  5147. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5148. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5149. {
  5150. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5151. {
  5152. tempIndex = ((gun_index==2) ? 1: 0);
  5153. }
  5154. else
  5155. {
  5156. tempIndex = gun_index;
  5157. }
  5158. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5159. {
  5160. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5161. {
  5162. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  5163. }
  5164. }
  5165. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5166. }
  5167. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5168. {
  5169. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5170. {
  5171. tempIndex = ((gun_index==2) ? 1: 0);
  5172. }
  5173. else
  5174. {
  5175. tempIndex = gun_index;
  5176. }
  5177. for (int index = 0; index < CCS_QUANTITY; index++)
  5178. {
  5179. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5180. {
  5181. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  5182. }
  5183. }
  5184. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5185. }
  5186. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5187. {
  5188. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5189. {
  5190. tempIndex = ((gun_index==2) ? 1: 0);
  5191. }
  5192. else
  5193. {
  5194. tempIndex = gun_index;
  5195. }
  5196. for (int index = 0; index < GB_QUANTITY; index++)
  5197. {
  5198. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5199. {
  5200. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  5201. }
  5202. }
  5203. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5204. }
  5205. else if(gunType[gun_index] == GUN_TYPE_DO)
  5206. {
  5207. tempIndex = gun_index;
  5208. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5209. {
  5210. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5211. {
  5212. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  5213. }
  5214. }
  5215. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5216. }
  5217. else
  5218. {
  5219. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5220. {
  5221. tempIndex = 2;
  5222. }
  5223. else
  5224. {
  5225. tempIndex = gun_index;
  5226. }
  5227. for (int index = 0; index < AC_QUANTITY; index++)
  5228. {
  5229. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5230. {
  5231. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  5232. }
  5233. }
  5234. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  5235. }
  5236. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  5237. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  5238. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  5239. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  5240. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5241. }
  5242. //***********************************************(6)SOC******************************************************/
  5243. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "SOC") != NULL)) ||
  5244. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "SOC") != NULL)) ||
  5245. (dataType == ReadingContext_Trigger))
  5246. {
  5247. 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))
  5248. {
  5249. //idx_sample=5;
  5250. //sampledValue = NULL;
  5251. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5252. {
  5253. tempIndex = ((gun_index==2) ? 1: 0);
  5254. }
  5255. else
  5256. {
  5257. tempIndex = gun_index;
  5258. }
  5259. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5260. {
  5261. //tempIndex = ((gun_index==2) ? 1: 0);
  5262. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5263. {
  5264. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5265. {
  5266. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  5267. }
  5268. }
  5269. }
  5270. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5271. {
  5272. //tempIndex = ((gun_index==2) ? 1: 0);
  5273. for (int index = 0; index < CCS_QUANTITY; index++)
  5274. {
  5275. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5276. {
  5277. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  5278. }
  5279. }
  5280. }
  5281. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5282. {
  5283. //tempIndex = ((gun_index==2) ? 1: 0);
  5284. for (int index = 0; index < GB_QUANTITY; index++)
  5285. {
  5286. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5287. {
  5288. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  5289. }
  5290. }
  5291. }
  5292. else if(gunType[gun_index] == GUN_TYPE_DO)
  5293. {
  5294. //tempIndex = ((gun_index==2) ? 1: 0);
  5295. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5296. {
  5297. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5298. {
  5299. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  5300. }
  5301. }
  5302. }
  5303. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  5304. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  5305. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  5306. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  5307. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  5308. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  5309. }
  5310. }
  5311. //********************************(7)Current.Import L2************************************************/
  5312. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5313. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5314. (dataType == ReadingContext_Trigger))
  5315. {
  5316. // Only for AC 3 phase
  5317. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5318. {
  5319. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5320. {
  5321. tempIndex = 2;
  5322. }
  5323. else
  5324. {
  5325. tempIndex = gun_index;
  5326. }
  5327. for (int index = 0; index < AC_QUANTITY; index++)
  5328. {
  5329. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5330. {
  5331. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  5332. }
  5333. }
  5334. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  5335. }
  5336. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  5337. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  5338. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  5339. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  5340. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5341. }
  5342. //********************************(8)Current.Import L3************************************************/
  5343. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5344. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5345. (dataType == ReadingContext_Trigger))
  5346. {
  5347. // Only for AC 3 phase
  5348. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5349. {
  5350. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5351. {
  5352. tempIndex = 2;
  5353. }
  5354. else
  5355. {
  5356. tempIndex = gun_index;
  5357. }
  5358. for (int index = 0; index < AC_QUANTITY; index++)
  5359. {
  5360. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5361. {
  5362. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  5363. }
  5364. }
  5365. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  5366. }
  5367. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  5368. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  5369. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  5370. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  5371. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5372. }
  5373. //***********************************************(9)VOLTAGE L2******************************************************/
  5374. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5375. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5376. (dataType == ReadingContext_Trigger))
  5377. {
  5378. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5379. {
  5380. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5381. {
  5382. tempIndex = 2;
  5383. }
  5384. else
  5385. {
  5386. tempIndex = gun_index;
  5387. }
  5388. for (int index = 0; index < AC_QUANTITY; index++)
  5389. {
  5390. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5391. {
  5392. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  5393. }
  5394. }
  5395. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  5396. }
  5397. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  5398. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  5399. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  5400. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  5401. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5402. }
  5403. //***********************************************(10)VOLTAGE L3******************************************************/
  5404. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5405. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5406. (dataType == ReadingContext_Trigger))
  5407. {
  5408. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5409. {
  5410. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5411. {
  5412. tempIndex = 2;
  5413. }
  5414. else
  5415. {
  5416. tempIndex = gun_index;
  5417. }
  5418. for (int index = 0; index < AC_QUANTITY; index++)
  5419. {
  5420. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5421. {
  5422. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  5423. }
  5424. }
  5425. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  5426. }
  5427. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  5428. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  5429. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  5430. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  5431. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5432. }
  5433. // Message create ====================================================================================================
  5434. if(TRUE)
  5435. {
  5436. json_object *MeterValueReq = json_object_new_object();
  5437. json_object *MeterValues = json_object_new_array();
  5438. json_object *sampledValues = json_object_new_array();
  5439. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  5440. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  5441. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  5442. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  5443. {
  5444. json_object *MeterValue = json_object_new_object();
  5445. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  5446. {
  5447. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  5448. {
  5449. json_object *sampledValue = json_object_new_object();
  5450. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  5451. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  5452. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  5453. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  5454. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  5455. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  5456. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  5457. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  5458. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  5459. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  5460. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  5461. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  5462. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  5463. json_object_array_add(sampledValues, sampledValue);
  5464. }
  5465. }
  5466. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  5467. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  5468. json_object_array_add(MeterValues, MeterValue);
  5469. }
  5470. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  5471. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  5472. ,gun_index + 1
  5473. ,MESSAGE_TYPE_CALL
  5474. ,guid
  5475. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  5476. json_object_put(MeterValueReq);
  5477. }
  5478. // Put request guid to hash map
  5479. sprintf(tempdata, "MeterValues,%d", (gun_index));
  5480. 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*/)
  5481. {
  5482. result = PASS;
  5483. //DEBUG_INFO("MeterValues mapitem pass\n");
  5484. }
  5485. if((dataType != ReadingContext_Trigger) &&
  5486. (dataType != ReadingContext_Sample_Clock) &&
  5487. (ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1))
  5488. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  5489. else
  5490. {
  5491. if(FirstHeartBeat)
  5492. LWS_Send(queuedata +2);
  5493. }
  5494. return result;
  5495. }
  5496. int sendLogStatusNotificationRequest(char *status)
  5497. {
  5498. mtrace();
  5499. int result = PASS;
  5500. char message[4096]={0};
  5501. char guid[37]={0};
  5502. char tempdata[128]={0};
  5503. json_object *LogStatusNotification = json_object_new_object();
  5504. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  5505. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  5506. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  5507. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  5508. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  5509. random_uuid(guid);
  5510. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  5511. json_object_put(LogStatusNotification);
  5512. LWS_Send(message);
  5513. sprintf(tempdata, "LogStatusNotification,%d", 0);
  5514. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5515. {
  5516. result = PASS;
  5517. }
  5518. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  5519. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  5520. return result;
  5521. }
  5522. int sendSecurityEventNotificationRequest()
  5523. {
  5524. mtrace();
  5525. int result = PASS;
  5526. char message[4096]={0};
  5527. char guid[37]={0};
  5528. char tempdata[128]={0};
  5529. json_object *SecurityEventNotification = json_object_new_object();
  5530. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  5531. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  5532. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  5533. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  5534. random_uuid(guid);
  5535. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  5536. json_object_put(SecurityEventNotification);
  5537. LWS_Send(message);
  5538. sprintf(tempdata, "SecurityEventNotification,0");
  5539. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5540. {
  5541. result = PASS;
  5542. }
  5543. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  5544. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  5545. return result;
  5546. }
  5547. int sendSignCertificateRequest()
  5548. {
  5549. mtrace();
  5550. int result = PASS;
  5551. char message[4096]={0};
  5552. char guid[37]={0};
  5553. char tempdata[128]={0};
  5554. json_object *SignCertificate = json_object_new_object();
  5555. DEBUG_INFO("sendSignCertificateRequest...\n");
  5556. // Read csr file content
  5557. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  5558. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  5559. char *line = NULL;
  5560. size_t len = 0;
  5561. while(getline(&line, &len, fp) != -1)
  5562. {
  5563. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  5564. {
  5565. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  5566. }
  5567. }
  5568. fclose(fp);
  5569. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  5570. random_uuid(guid);
  5571. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  5572. json_object_put(SignCertificate);
  5573. LWS_Send(message);
  5574. sprintf(tempdata, "SignCertificate,0");
  5575. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5576. {
  5577. result = PASS;
  5578. }
  5579. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  5580. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  5581. return result;
  5582. }
  5583. int sendSignedFirmwareStatusNotificationRequest(char *status)
  5584. {
  5585. mtrace();
  5586. int result = PASS;
  5587. char message[110]={0};
  5588. char guid[37]={0};
  5589. char tempdata[65]={0};
  5590. json_object *FirmwareStatusNotification = json_object_new_object();
  5591. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  5592. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  5593. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  5594. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  5595. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  5596. random_uuid(guid);
  5597. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  5598. json_object_put(FirmwareStatusNotification);
  5599. LWS_Send(message);
  5600. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  5601. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5602. {
  5603. result = PASS;
  5604. }
  5605. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  5606. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  5607. return result;
  5608. }
  5609. //==========================================
  5610. // send confirm routine
  5611. //==========================================
  5612. int sendCancelReservationConfirmation(char *uuid,char *payload)
  5613. {
  5614. mtrace();
  5615. int result = FAIL;
  5616. char message[100]={0};
  5617. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  5618. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5619. LWS_Send(message);
  5620. result = TRUE;
  5621. return result;
  5622. }
  5623. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  5624. {
  5625. mtrace();
  5626. int result = FAIL;
  5627. char message[100]={0};
  5628. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  5629. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5630. LWS_Send(message);
  5631. result = TRUE;
  5632. return result;
  5633. }
  5634. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  5635. {
  5636. mtrace();
  5637. int result = FAIL;
  5638. char message[100]={0};
  5639. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  5640. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5641. LWS_Send(message);
  5642. result = TRUE;
  5643. return result;
  5644. }
  5645. int sendClearCacheConfirmation(char *uuid,char *payload)
  5646. {
  5647. mtrace();
  5648. int result = FAIL;
  5649. char message[500]={0};
  5650. DEBUG_INFO("sendClearCacheConfirmation...\n");
  5651. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5652. LWS_Send(message);
  5653. return result;
  5654. }
  5655. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  5656. {
  5657. mtrace();
  5658. int result = FAIL;
  5659. char message[500]={0};
  5660. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  5661. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5662. LWS_Send(message);
  5663. return result;
  5664. }
  5665. int sendDataTransferConfirmation(char *uuid,char *payload)
  5666. {
  5667. mtrace();
  5668. char statusStr[20]={0};
  5669. char dataStr[10]={0};
  5670. char sstr[20]={0};
  5671. int c = 0;
  5672. char *loc;
  5673. int result = FAIL;
  5674. DEBUG_INFO("sendDataTransferConfirmation...\n");
  5675. /**********************status**************************/
  5676. loc = strstr(payload, "status");
  5677. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5678. c = 0;
  5679. while (loc[3+strlen("status")+c] != '\"')
  5680. {
  5681. sstr[c] = loc[3+strlen("status")+c];
  5682. c++;
  5683. }
  5684. sstr[c] = '\0';
  5685. strcpy(statusStr, sstr);
  5686. /**********************data**************************/
  5687. loc = strstr(payload, "data");
  5688. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5689. c = 0;
  5690. while (loc[3+strlen("data")+c] != '\"')
  5691. {
  5692. sstr[c] = loc[3+strlen("data")+c];
  5693. c++;
  5694. }
  5695. sstr[c] = '\0';
  5696. strcpy(dataStr, sstr);
  5697. return result;
  5698. }
  5699. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  5700. {
  5701. mtrace();
  5702. int result = FAIL;
  5703. char message[1000]={0};
  5704. int CompositeScheduleIndex = 0;
  5705. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  5706. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  5707. if(nPeriod == 0)
  5708. {
  5709. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  5710. {
  5711. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  5712. ,MESSAGE_TYPE_CALLRESULT
  5713. ,uuid
  5714. ,payload
  5715. ,connectorIdInt);
  5716. }
  5717. else
  5718. {
  5719. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  5720. ,MESSAGE_TYPE_CALLRESULT
  5721. ,uuid
  5722. ,payload
  5723. ,connectorIdInt
  5724. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5725. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5726. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5727. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  5728. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  5729. }
  5730. }
  5731. else
  5732. {
  5733. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  5734. ,MESSAGE_TYPE_CALLRESULT
  5735. ,uuid
  5736. ,payload
  5737. ,connectorIdInt
  5738. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5739. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5740. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5741. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  5742. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  5743. {
  5744. if (idx_sample == 0)
  5745. {
  5746. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5747. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5748. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5749. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5750. }
  5751. else
  5752. {
  5753. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5754. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5755. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5756. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5757. }
  5758. }
  5759. sprintf(message + strlen(message), "]}}]");
  5760. }
  5761. LWS_Send(message);
  5762. result = TRUE;
  5763. return result;
  5764. }
  5765. int sendGetConfigurationConfirmation(char *uuid)
  5766. {
  5767. mtrace();
  5768. int result = FAIL;
  5769. int MaxKeySupported = 0;
  5770. int sentConfigurationNumber= 0;
  5771. int sentunConfigurationNumber= 0;
  5772. char message[4000]={0};
  5773. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  5774. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  5775. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  5776. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  5777. ,MESSAGE_TYPE_CALLRESULT
  5778. ,uuid );
  5779. //configuration key
  5780. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  5781. {
  5782. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  5783. {
  5784. if (sentConfigurationNumber == 0)
  5785. {
  5786. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5787. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5788. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5789. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5790. }
  5791. else
  5792. {
  5793. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5794. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5795. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5796. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5797. }
  5798. sentConfigurationNumber = sentConfigurationNumber + 1;
  5799. }
  5800. }
  5801. sprintf(message + strlen(message), "]");
  5802. if(UnknownKeynum != 0)
  5803. {
  5804. sprintf(message + strlen(message), ",\"unknownKey\":[");
  5805. //unkown key
  5806. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  5807. {
  5808. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  5809. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  5810. if(sentunConfigurationNumber == 0)
  5811. {
  5812. sprintf(message + strlen(message), "\"%s\""
  5813. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5814. }
  5815. else
  5816. {
  5817. sprintf(message + strlen(message), ",\"%s\""
  5818. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5819. }
  5820. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  5821. }
  5822. sprintf(message + strlen(message), "]");
  5823. }
  5824. sprintf(message + strlen(message), "}]");
  5825. LWS_Send(message);
  5826. return result;
  5827. }
  5828. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  5829. {
  5830. mtrace();
  5831. int result = FAIL;
  5832. char message[400]={0};
  5833. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  5834. if(strcmp(payload,"")==0)
  5835. {
  5836. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5837. }
  5838. else
  5839. {
  5840. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5841. }
  5842. LWS_Send(message);
  5843. result = TRUE;
  5844. return result;
  5845. }
  5846. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  5847. {
  5848. mtrace();
  5849. int result = FAIL;
  5850. char message[80]={0};
  5851. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  5852. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  5853. LWS_Send(message);
  5854. result = TRUE;
  5855. return result;
  5856. }
  5857. int sendRemoteStartConfirmation(char *uuid,char *payload)
  5858. {
  5859. mtrace();
  5860. int result = FAIL;
  5861. char message[80]={0};
  5862. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  5863. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5864. LWS_Send(message);
  5865. result = TRUE;
  5866. return result;
  5867. }
  5868. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5869. {
  5870. mtrace();
  5871. int result = FAIL;
  5872. char message[80]={0};
  5873. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5874. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5875. LWS_Send(message);
  5876. result = TRUE;
  5877. return result;
  5878. }
  5879. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5880. {
  5881. mtrace();
  5882. int result = FAIL;
  5883. char message[80]={0};
  5884. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5885. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  5886. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5887. LWS_Send(message);
  5888. result = TRUE;
  5889. return result;
  5890. }
  5891. int sendResetConfirmation(char *uuid,char *payload)
  5892. {
  5893. mtrace();
  5894. int result = FAIL;
  5895. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  5896. char message[80]={0};
  5897. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  5898. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5899. LWS_Send(message);
  5900. result = TRUE;
  5901. return result;
  5902. }
  5903. int sendSendLocalListConfirmation(char *uuid,char *payload)
  5904. {
  5905. mtrace();
  5906. int result = FAIL;
  5907. char message[500]={0};
  5908. // [ 3, "1571284266109", { "status": "Accepted" } ]
  5909. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5910. LWS_Send(message);
  5911. result = TRUE;
  5912. return result;
  5913. }
  5914. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  5915. {
  5916. mtrace();
  5917. int result = FAIL;
  5918. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  5919. char message[80]={0};
  5920. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  5921. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5922. LWS_Send(message);
  5923. result = TRUE;
  5924. return result;
  5925. }
  5926. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  5927. {
  5928. mtrace();
  5929. int result = FAIL;
  5930. char message[80]={0};
  5931. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  5932. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5933. LWS_Send(message);
  5934. result = TRUE;
  5935. return result;
  5936. }
  5937. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  5938. {
  5939. mtrace();
  5940. int result = FAIL;
  5941. char message[80]={0};
  5942. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5943. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  5944. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5945. LWS_Send(message);
  5946. result = TRUE;
  5947. return result;
  5948. }
  5949. int sendUpdateFirmwareConfirmation(char *uuid)
  5950. {
  5951. mtrace();
  5952. int result = FAIL;
  5953. char message[60]={0};
  5954. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5955. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  5956. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5957. LWS_Send(message);
  5958. result = TRUE;
  5959. return result;
  5960. }
  5961. int sendCertificateSignedConfirmation(char *uuid)
  5962. {
  5963. mtrace();
  5964. int result = PASS;
  5965. char message[4096]={0};
  5966. json_object *CertificateSigned = json_object_new_object();
  5967. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  5968. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  5969. sprintf(message,"[%d,\"%s\",%s]"
  5970. ,MESSAGE_TYPE_CALLRESULT
  5971. ,uuid
  5972. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  5973. json_object_put(CertificateSigned);
  5974. LWS_Send(message);
  5975. return result;
  5976. }
  5977. int sendDeleteCertificateConfirmation(char *uuid)
  5978. {
  5979. mtrace();
  5980. int result = PASS;
  5981. char message[4096]={0};
  5982. json_object *DeleteCertificate = json_object_new_object();
  5983. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  5984. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  5985. sprintf(message,"[%d,\"%s\",%s]"
  5986. ,MESSAGE_TYPE_CALLRESULT
  5987. ,uuid
  5988. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  5989. json_object_put(DeleteCertificate);
  5990. LWS_Send(message);
  5991. return result;
  5992. }
  5993. int sendExtendedTriggerMessageConfirmation(char *uuid)
  5994. {
  5995. mtrace();
  5996. int result = PASS;
  5997. char message[4096]={0};
  5998. json_object *ExtendedTriggerMessage = json_object_new_object();
  5999. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  6000. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  6001. sprintf(message,"[%d,\"%s\",%s]"
  6002. ,MESSAGE_TYPE_CALLRESULT
  6003. ,uuid
  6004. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  6005. json_object_put(ExtendedTriggerMessage);
  6006. LWS_Send(message);
  6007. return result;
  6008. }
  6009. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  6010. {
  6011. mtrace();
  6012. int result = PASS;
  6013. char message[4096]={0};
  6014. json_object *GetInstalledCertificateIds = json_object_new_object();
  6015. json_object *certificateHashDataDatas = json_object_new_array();
  6016. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  6017. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  6018. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  6019. {
  6020. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  6021. {
  6022. json_object *certificateHashData = json_object_new_object();
  6023. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  6024. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  6025. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  6026. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  6027. json_object_array_add(certificateHashDataDatas, certificateHashData);
  6028. }
  6029. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  6030. }
  6031. else
  6032. {
  6033. json_object_put(certificateHashDataDatas);
  6034. }
  6035. sprintf(message,"[%d,\"%s\",%s]"
  6036. ,MESSAGE_TYPE_CALLRESULT
  6037. ,uuid
  6038. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  6039. json_object_put(GetInstalledCertificateIds);
  6040. LWS_Send(message);
  6041. return result;
  6042. }
  6043. int sendGetLogConfirmation(char *uuid)
  6044. {
  6045. mtrace();
  6046. int result = PASS;
  6047. char message[4096]={0};
  6048. json_object *GetLog = json_object_new_object();
  6049. DEBUG_INFO("sendGetLogConfirmation...\n");
  6050. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  6051. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  6052. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  6053. sprintf(message,"[%d,\"%s\",%s]"
  6054. ,MESSAGE_TYPE_CALLRESULT
  6055. ,uuid
  6056. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  6057. json_object_put(GetLog);
  6058. LWS_Send(message);
  6059. return result;
  6060. }
  6061. int sendInstallCertificateConfirmation(char *uuid)
  6062. {
  6063. mtrace();
  6064. int result = PASS;
  6065. char message[4096]={0};
  6066. json_object *InstallCertificate = json_object_new_object();
  6067. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  6068. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  6069. sprintf(message,"[%d,\"%s\",%s]"
  6070. ,MESSAGE_TYPE_CALLRESULT
  6071. ,uuid
  6072. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  6073. json_object_put(InstallCertificate);
  6074. LWS_Send(message);
  6075. return result;
  6076. }
  6077. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  6078. {
  6079. mtrace();
  6080. int result = PASS;
  6081. char message[4096]={0};
  6082. json_object *SignedUpdateFirmware = json_object_new_object();
  6083. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  6084. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  6085. sprintf(message,"[%d,\"%s\",%s]"
  6086. ,MESSAGE_TYPE_CALLRESULT
  6087. ,uuid
  6088. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  6089. json_object_put(SignedUpdateFirmware);
  6090. LWS_Send(message);
  6091. return result;
  6092. }
  6093. int sendUnknownConfirmation(char *uuid)
  6094. {
  6095. mtrace();
  6096. int result = PASS;
  6097. char message[256]={0};
  6098. DEBUG_INFO("sendUnknownConfirmation...\n");
  6099. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  6100. LWS_Send(message);
  6101. return result;
  6102. }
  6103. //==========================================
  6104. // Handle server request routine Start
  6105. //==========================================
  6106. int handleCancelReservationRequest(char *uuid, char *payload)
  6107. {
  6108. mtrace();
  6109. int result = FAIL;
  6110. int gunNO = 0;
  6111. int reservationIdInt = -1;
  6112. char comfirmstr[20];
  6113. DEBUG_INFO("handleCancelReservationRequest...\n");
  6114. json_object *CancelReservation;
  6115. CancelReservation = json_tokener_parse(payload);
  6116. if(!is_error(CancelReservation))
  6117. {
  6118. // Required data
  6119. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  6120. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  6121. }
  6122. json_object_put(CancelReservation);
  6123. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  6124. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6125. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  6126. if(reservationIdInt != -1)
  6127. {
  6128. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6129. //check Transaction active
  6130. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6131. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6132. {
  6133. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  6134. {
  6135. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6136. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6137. if(gunType[2] == GUN_TYPE_CHAdeMO)
  6138. {
  6139. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  6140. }
  6141. else
  6142. {
  6143. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  6144. }
  6145. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6146. goto end;
  6147. }
  6148. }
  6149. for (int index = 0; index < CCS_QUANTITY; index++)
  6150. {
  6151. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  6152. {
  6153. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6154. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6155. if(gunType[2] == GUN_TYPE_CCS)
  6156. {
  6157. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  6158. }
  6159. else
  6160. {
  6161. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  6162. }
  6163. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6164. goto end;
  6165. }
  6166. }
  6167. for (int index = 0; index < GB_QUANTITY; index++)
  6168. {
  6169. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  6170. {
  6171. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6172. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6173. if(gunType[2] == GUN_TYPE_GBT)
  6174. {
  6175. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  6176. }
  6177. else
  6178. {
  6179. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  6180. }
  6181. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6182. goto end;
  6183. }
  6184. }
  6185. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6186. {
  6187. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  6188. {
  6189. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6190. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6191. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  6192. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6193. goto end;
  6194. }
  6195. }
  6196. for (int index = 0; index < AC_QUANTITY; index++)
  6197. {
  6198. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  6199. {
  6200. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6201. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6202. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6203. {
  6204. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  6205. }
  6206. else
  6207. {
  6208. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  6209. }
  6210. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6211. goto end;
  6212. }
  6213. }
  6214. }
  6215. //The reservationId does NOT match the reservationId
  6216. sendCancelReservationConfirmation(uuid, comfirmstr);
  6217. end:
  6218. // Fill in ocpp packet uuid
  6219. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  6220. return result;
  6221. }
  6222. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  6223. {
  6224. mtrace();
  6225. int result = FAIL;
  6226. int gunIndex = 0;
  6227. char typeStr[16]={0};
  6228. char comfirmstr[20];
  6229. int specificId = FALSE;
  6230. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  6231. json_object *ChangeAvailability;
  6232. ChangeAvailability = json_tokener_parse(payload);
  6233. if(!is_error(ChangeAvailability))
  6234. {
  6235. // Required data
  6236. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  6237. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  6238. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  6239. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  6240. }
  6241. json_object_put(ChangeAvailability);
  6242. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6243. {
  6244. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  6245. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  6246. }
  6247. else if(gunIndex == 0)
  6248. {
  6249. for(int i=0; i < gunTotalNumber; i++)
  6250. {
  6251. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  6252. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  6253. }
  6254. }
  6255. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6256. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6257. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  6258. {
  6259. specificId = TRUE;
  6260. }
  6261. if(specificId == FALSE)
  6262. goto end;
  6263. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  6264. {
  6265. //----------------------gunIndex is 0 ------------------------------------------------//
  6266. if(gunIndex == 0)
  6267. {
  6268. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6269. {
  6270. for(int i=0; i < gunTotalNumber; i++)
  6271. {
  6272. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6273. {
  6274. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  6275. {
  6276. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6277. {
  6278. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6279. goto end;
  6280. }
  6281. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6282. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6283. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6284. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6285. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6286. {
  6287. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6288. goto end;
  6289. }
  6290. }
  6291. }//END FOR CHAdeMO_QUANTITY
  6292. for (int index = 0; index < CCS_QUANTITY; index++)
  6293. {
  6294. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  6295. {
  6296. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  6297. {
  6298. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6299. goto end;
  6300. }
  6301. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6302. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6303. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6304. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6305. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6306. {
  6307. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6308. goto end;
  6309. }
  6310. }
  6311. }//END FOR CCS_QUANTITY
  6312. for (int index = 0; index < GB_QUANTITY; index++)
  6313. {
  6314. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  6315. {
  6316. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6317. {
  6318. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6319. goto end;
  6320. }
  6321. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6322. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6323. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6324. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6325. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6326. {
  6327. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6328. goto end;
  6329. }
  6330. }
  6331. }// END FOR GB_QUANTITY
  6332. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6333. {
  6334. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  6335. {
  6336. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6337. {
  6338. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6339. goto end;
  6340. }
  6341. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  6342. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  6343. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  6344. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  6345. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6346. {
  6347. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6348. goto end;
  6349. }
  6350. }
  6351. }// END FOR GENERAL_GUN_QUANTITY
  6352. for (int index = 0; index < AC_QUANTITY; index++)
  6353. {
  6354. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  6355. {
  6356. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6357. {
  6358. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6359. goto end;
  6360. }
  6361. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6362. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6363. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6364. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6365. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6366. {
  6367. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6368. goto end;
  6369. }
  6370. }
  6371. }//END FOR AC_QUANTITY
  6372. }// END FOR gunTotalNumber
  6373. }
  6374. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6375. {
  6376. for(int i=0; i < gunTotalNumber; i++)
  6377. {
  6378. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6379. {
  6380. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6381. goto end;
  6382. }
  6383. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6384. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  6385. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  6386. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  6387. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6388. {
  6389. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6390. goto end;
  6391. }
  6392. }
  6393. }
  6394. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6395. goto end;
  6396. }
  6397. //----------------------gunIndex is not 0 ------------------------------------------------//
  6398. //check Transaction active
  6399. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6400. {
  6401. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  6402. {
  6403. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  6404. {
  6405. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6406. goto end;
  6407. }
  6408. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6409. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6410. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6411. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6412. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6413. {
  6414. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6415. goto end;
  6416. }
  6417. else
  6418. {
  6419. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  6420. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6421. goto end;
  6422. }
  6423. }
  6424. }//END FOR CHAdeMO_QUANTITY
  6425. for (int index = 0; index < CCS_QUANTITY; index++)
  6426. {
  6427. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  6428. {
  6429. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  6430. {
  6431. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6432. goto end;
  6433. }
  6434. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6435. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6436. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6437. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6438. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6439. {
  6440. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6441. goto end;
  6442. }
  6443. else
  6444. {
  6445. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  6446. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6447. goto end;
  6448. }
  6449. }
  6450. }//END FOR CCS_QUANTITY
  6451. for (int index = 0; index < GB_QUANTITY; index++)
  6452. {
  6453. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  6454. {
  6455. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6456. {
  6457. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6458. goto end;
  6459. }
  6460. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6461. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6462. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6463. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6464. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6465. {
  6466. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6467. goto end;
  6468. }
  6469. else
  6470. {
  6471. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  6472. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6473. goto end;
  6474. }
  6475. }
  6476. }// END FOR GB_QUANTITY
  6477. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6478. {
  6479. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  6480. {
  6481. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6482. {
  6483. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6484. goto end;
  6485. }
  6486. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  6487. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  6488. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  6489. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  6490. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6491. {
  6492. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6493. goto end;
  6494. }
  6495. else
  6496. {
  6497. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  6498. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6499. goto end;
  6500. }
  6501. }
  6502. }// END FOR GENERAL_GUN_QUANTITY
  6503. for (int index = 0; index < AC_QUANTITY; index++)
  6504. {
  6505. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  6506. {
  6507. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6508. {
  6509. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6510. goto end;
  6511. }
  6512. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6513. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6514. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6515. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6516. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6517. {
  6518. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6519. goto end;
  6520. }
  6521. else
  6522. {
  6523. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  6524. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6525. goto end;
  6526. }
  6527. }
  6528. }//END FOR AC_QUANTITY
  6529. }//END FOR AvailabilityTypeStr[Inoperative]
  6530. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  6531. {
  6532. //----------------------gunIndex is 0 ------------------------------------------------//
  6533. if(gunIndex == 0)
  6534. {
  6535. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6536. {
  6537. for(int i=0; i < gunTotalNumber; i++)
  6538. {
  6539. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6540. {
  6541. 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
  6542. {
  6543. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6544. goto end;
  6545. }
  6546. }//END FOR CHAdeMO_QUANTITY
  6547. for (int index = 0; index < CCS_QUANTITY; index++)
  6548. {
  6549. 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
  6550. {
  6551. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6552. goto end;
  6553. }
  6554. }//END FOR CCS_QUANTITY
  6555. for (int index = 0; index < GB_QUANTITY; index++)
  6556. {
  6557. 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
  6558. {
  6559. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6560. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6561. goto end;
  6562. }
  6563. }// END FOR GB_QUANTITY
  6564. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6565. {
  6566. 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
  6567. {
  6568. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6569. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6570. goto end;
  6571. }
  6572. }// END FOR GENERAL_GUN_QUANTITY
  6573. for (int index = 0; index < AC_QUANTITY; index++)
  6574. {
  6575. 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
  6576. {
  6577. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6578. goto end;
  6579. }
  6580. }//END FOR CHAdeMO_QUANTITY
  6581. }// END FOR gunTotalNumber
  6582. }
  6583. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6584. {
  6585. for(int i=0; i < gunTotalNumber; i++)
  6586. {
  6587. for (int index = 0; index < AC_QUANTITY; index++)
  6588. {
  6589. 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
  6590. {
  6591. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6592. goto end;
  6593. }
  6594. }//END FOR CHAdeMO_QUANTITY
  6595. } // END FOR gunTotalNumber
  6596. }
  6597. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6598. goto end;
  6599. }
  6600. //----------------------gunIndex is not 0 ------------------------------------------------//
  6601. //check Transaction active
  6602. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6603. {
  6604. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6605. {
  6606. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6607. goto end;
  6608. }
  6609. }//END FOR CHAdeMO_QUANTITY
  6610. for (int index = 0; index < CCS_QUANTITY; index++)
  6611. {
  6612. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6613. {
  6614. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6615. goto end;
  6616. }
  6617. }//END FOR CCS_QUANTITY
  6618. for (int index = 0; index < GB_QUANTITY; index++)
  6619. {
  6620. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6621. {
  6622. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6623. goto end;
  6624. }
  6625. }// END FOR GB_QUANTITY
  6626. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6627. {
  6628. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6629. {
  6630. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6631. goto end;
  6632. }
  6633. }// END FOR GENERAL_GUN_QUANTITY
  6634. for (int index = 0; index < AC_QUANTITY; index++)
  6635. {
  6636. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6637. {
  6638. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6639. goto end;
  6640. }
  6641. }//END FOR AC_QUANTITY
  6642. }//END FOR AvailabilityTypeStr[Operative]
  6643. end:
  6644. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6645. {
  6646. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  6647. }
  6648. else
  6649. {
  6650. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  6651. }
  6652. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6653. {
  6654. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6655. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6656. }
  6657. else if(gunIndex == 0)
  6658. {
  6659. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6660. {
  6661. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  6662. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  6663. }
  6664. }
  6665. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  6666. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6667. return result;
  6668. }
  6669. int handleChangeConfigurationRequest(char *uuid, char *payload)
  6670. {
  6671. mtrace();
  6672. int result = FAIL;
  6673. char keystr[40]={0};
  6674. char valuestr[256]={0};
  6675. char comfirmstr[20]={0};
  6676. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  6677. json_object *ChangeConfiguration;
  6678. ChangeConfiguration = json_tokener_parse(payload);
  6679. if(!is_error(ChangeConfiguration))
  6680. {
  6681. // Required data
  6682. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  6683. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  6684. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  6685. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  6686. }
  6687. json_object_put(ChangeConfiguration);
  6688. if((uuid==NULL) || (payload ==NULL) )
  6689. {
  6690. DEBUG_ERROR("Payload is null\n");
  6691. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6692. }
  6693. else
  6694. {
  6695. int status = setKeyValue(keystr, valuestr);
  6696. switch(status)
  6697. {
  6698. case ConfigurationStatus_Accepted:
  6699. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  6700. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  6701. StoreConfigurationTable();
  6702. break;
  6703. case RebootRequired:
  6704. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  6705. StoreConfigurationTable();
  6706. break;
  6707. case NotSupported:
  6708. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  6709. break;
  6710. case ConfigurationStatus_Rejected:
  6711. default:
  6712. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6713. break;
  6714. }
  6715. }
  6716. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  6717. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  6718. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6719. {
  6720. ChageWebSocketPingInterval(atoi(valuestr));
  6721. }
  6722. if((strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6723. {
  6724. SetOcppConnStatus(FALSE);
  6725. }
  6726. return result;
  6727. }
  6728. int handleClearCacheRequest(char *uuid, char *payload)
  6729. {
  6730. mtrace();
  6731. int result = FAIL;
  6732. char comfirmstr[20];
  6733. char rmFileCmd[100]={0};
  6734. struct stat stats;
  6735. DEBUG_INFO("handleClearCacheRequest...\n");
  6736. stat("/Storage/OCPP", &stats);
  6737. // Check for directory existence
  6738. if (S_ISDIR(stats.st_mode) == 1)
  6739. {}
  6740. else
  6741. {
  6742. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  6743. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  6744. system(rmFileCmd);
  6745. }
  6746. if(OCPP_cleanLocalCache())
  6747. {
  6748. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  6749. }
  6750. else
  6751. {
  6752. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  6753. }
  6754. sendClearCacheConfirmation(uuid, comfirmstr);
  6755. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6756. return result;
  6757. }
  6758. int handleClearChargingProfileRequest(char *uuid, char *payload)
  6759. {
  6760. mtrace();
  6761. int result = FAIL;
  6762. int resultRename;
  6763. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  6764. char chargingProfilePurposeStr[26]={0};
  6765. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  6766. char tempchargingProfilePurposeStr[26]={0};
  6767. char str[100]={0};
  6768. char fname[200]={0};
  6769. char comfirmstr[20]={0};
  6770. char word[1600]={0};
  6771. int clearflag = FALSE;
  6772. int chargingProfileIdIsNULL = FALSE;
  6773. int connectorIsNULL = FALSE;
  6774. int chargingProfilePurposeIsNULL = FALSE;
  6775. int stackLevelIsNULL = FALSE;
  6776. //int GotoEnd = FALSE;
  6777. FILE *fptr1, *fptr2;
  6778. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  6779. int n_chargingProfile=0;
  6780. int isEmptyFile = FALSE;
  6781. char sLineWord[1600]={0};
  6782. char chargingProfiles[10][100]={0};
  6783. int ChargeProfileCount = 0;
  6784. int ch;
  6785. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  6786. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  6787. json_object *ClearChargingProfile;
  6788. ClearChargingProfile = json_tokener_parse(payload);
  6789. if(!is_error(ClearChargingProfile))
  6790. {
  6791. // Optional data
  6792. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  6793. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  6794. else
  6795. chargingProfileIdIsNULL = TRUE;
  6796. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  6797. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  6798. else
  6799. connectorIsNULL = TRUE;
  6800. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  6801. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  6802. else
  6803. chargingProfilePurposeIsNULL = TRUE;
  6804. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  6805. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  6806. else
  6807. stackLevelIsNULL = TRUE;
  6808. }
  6809. json_object_put(ClearChargingProfile);
  6810. if(connectorIsNULL == FALSE)
  6811. {
  6812. switch(connectorIdInt)
  6813. {
  6814. case 0:
  6815. if(chargingProfilePurposeIsNULL == TRUE)
  6816. {
  6817. int l = 0;
  6818. strcpy(fname, ChargePointMaxProfile_JSON);
  6819. if((access(fname,F_OK))!=-1)
  6820. {
  6821. strcpy(chargingProfiles[l], fname);
  6822. l = l + 1;
  6823. }
  6824. strcpy(fname, TxDefaultProfile_0_JSON);
  6825. if((access(fname,F_OK))!=-1)
  6826. {
  6827. strcpy(chargingProfiles[l], fname);
  6828. l = l + 1;
  6829. }
  6830. ChargeProfileCount = l;
  6831. }
  6832. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  6833. {
  6834. strcpy(fname, ChargePointMaxProfile_JSON);
  6835. if((access(fname,F_OK))!=-1)
  6836. {
  6837. strcpy(chargingProfiles[0], fname);
  6838. ChargeProfileCount = 1;
  6839. }
  6840. }
  6841. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6842. {
  6843. strcpy(fname, TxDefaultProfile_0_JSON);
  6844. if((access(fname,F_OK))!=-1)
  6845. {
  6846. strcpy(chargingProfiles[0], fname);
  6847. ChargeProfileCount = 1;
  6848. }
  6849. }
  6850. break;
  6851. default:
  6852. if(chargingProfilePurposeIsNULL == TRUE)
  6853. {
  6854. int m = 0;
  6855. memset(fname, 0, ARRAY_SIZE(fname));
  6856. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6857. if((access(fname,F_OK))!=-1)
  6858. {
  6859. strcpy(chargingProfiles[m], fname);
  6860. m = m + 1;
  6861. }
  6862. memset(fname, 0, ARRAY_SIZE(fname));
  6863. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6864. if((access(fname,F_OK))!=-1)
  6865. {
  6866. strcpy(chargingProfiles[m], fname);
  6867. m = m + 1;
  6868. }
  6869. ChargeProfileCount = m;
  6870. }
  6871. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6872. {
  6873. //strcpy(fname, TxDefaultProfile_1_JSON);
  6874. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6875. if((access(fname,F_OK))!=-1)
  6876. {
  6877. strcpy(chargingProfiles[0], fname);
  6878. ChargeProfileCount = 1;
  6879. }
  6880. }
  6881. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  6882. {
  6883. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6884. if((access(fname,F_OK))!=-1)
  6885. {
  6886. strcpy(chargingProfiles[0], fname);
  6887. ChargeProfileCount = 1;
  6888. }
  6889. //strcpy(fname, TxProfile_1_JSON);
  6890. }
  6891. //strcpy(fname, ChargePointMaxProfile_JSON );
  6892. break;
  6893. }
  6894. }
  6895. else // Check all Charging Profiles
  6896. {
  6897. int i = 0;
  6898. char fnametemp[200]={0};
  6899. ChargeProfileCount = 0;
  6900. //Check ChargePointMaxProfile.json exit
  6901. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  6902. {
  6903. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  6904. i = i + 1;
  6905. }
  6906. //Check TxDefaultProfile_0.json exit
  6907. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  6908. {
  6909. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  6910. i = i + 1;
  6911. }
  6912. //Check TxDefaultProfile_%d.json
  6913. for(int j=1; j <= gunTotalNumber; j++)
  6914. {
  6915. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6916. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  6917. if((access(fnametemp,F_OK))!=-1)
  6918. {
  6919. strcpy(chargingProfiles[i], fnametemp);
  6920. i = i + 1;
  6921. }
  6922. }
  6923. //Check TxProfile_%d.json
  6924. for(int j=1; j <= gunTotalNumber; j++)
  6925. {
  6926. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6927. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  6928. if((access(fnametemp,F_OK))!=-1)
  6929. {
  6930. strcpy(chargingProfiles[i], fnametemp);
  6931. i = i + 1;
  6932. }
  6933. }
  6934. ChargeProfileCount = i;
  6935. }// End connectorIsNULL is TRUE
  6936. if(ChargeProfileCount == 0)
  6937. {
  6938. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6939. goto end;
  6940. }
  6941. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  6942. {
  6943. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6944. goto end;
  6945. }
  6946. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  6947. {
  6948. memset(str, 0, ARRAY_SIZE(str));
  6949. // clear temp file
  6950. sprintf(str,"rm -f %s",temp);
  6951. system(str);
  6952. for(int k=0; k < ChargeProfileCount; k++)
  6953. {
  6954. memset(str, 0, ARRAY_SIZE(str));
  6955. //clear file in C
  6956. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6957. system(str);
  6958. }
  6959. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6960. goto end;
  6961. }
  6962. else if(connectorIsNULL == TRUE)
  6963. {
  6964. for(int k=0; k < ChargeProfileCount; k++)
  6965. {
  6966. fptr1 = fopen(chargingProfiles[k], "r");
  6967. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  6968. //Check Charging Profile Count
  6969. while(fscanf(fptr1, "%s", word) != EOF)
  6970. {
  6971. //DEBUG_INFO("word=%s\n",word);
  6972. if(strstr(word, "chargingProfileId")!= NULL)
  6973. {
  6974. //DEBUG_INFO("test chargingProfileId \n");
  6975. n_chargingProfile = n_chargingProfile + 1;
  6976. //DEBUG_INFO("chargingProfileId Found\n");
  6977. }
  6978. }
  6979. rewind(fptr1);
  6980. //search Charging Profile Element
  6981. //int i= 0;
  6982. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6983. {
  6984. json_object *tmpProfilee;
  6985. tmpProfilee = json_tokener_parse(sLineWord);
  6986. if(!is_error(tmpProfilee))
  6987. {
  6988. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  6989. {
  6990. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  6991. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  6992. }
  6993. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  6994. {
  6995. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  6996. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  6997. }
  6998. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  6999. {
  7000. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7001. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7002. }
  7003. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7004. {
  7005. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7006. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7007. }
  7008. }
  7009. json_object_put(tmpProfilee);
  7010. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7011. {
  7012. //------- not write to fptr2-------//
  7013. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7014. //clearflag = TRUE;
  7015. }
  7016. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7017. {
  7018. //------- not write to fptr2-------//
  7019. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7020. }
  7021. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7022. {
  7023. //------- not write to fptr2-------//
  7024. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7025. }
  7026. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  7027. {
  7028. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7029. }
  7030. else
  7031. {
  7032. fprintf(fptr2, sLineWord);//writing data into file
  7033. }
  7034. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7035. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7036. if(clearflag == TRUE)
  7037. {
  7038. fclose(fptr1);
  7039. fclose(fptr2);
  7040. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7041. system(str);
  7042. // clear temp file
  7043. sprintf(str,"rm -f %s",temp);
  7044. system(str);
  7045. }
  7046. else
  7047. {
  7048. fclose(fptr1);
  7049. fclose(fptr2);
  7050. memset(str, 0, ARRAY_SIZE(str));
  7051. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7052. system(str);
  7053. resultRename = rename(temp, chargingProfiles[k]);
  7054. if(resultRename == 0)
  7055. {
  7056. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  7057. }
  7058. else
  7059. {
  7060. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  7061. }
  7062. if(comfirmstr[0]== 0)
  7063. {
  7064. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7065. }
  7066. //Check chargingProfile is empty file
  7067. /*------ Read the file ----------------*/
  7068. fptr1=fopen(chargingProfiles[k],"r");
  7069. ch=fgetc(fptr1);
  7070. rewind(fptr1);
  7071. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7072. if(ch!=EOF)
  7073. {
  7074. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7075. {
  7076. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7077. if(sLineWord[0]=='\0')
  7078. {
  7079. isEmptyFile = TRUE;
  7080. break;
  7081. }
  7082. else
  7083. {
  7084. isEmptyFile = FALSE;
  7085. break;
  7086. }
  7087. }
  7088. }
  7089. else
  7090. isEmptyFile = TRUE;
  7091. fclose(fptr1);
  7092. if(isEmptyFile == TRUE)
  7093. {
  7094. memset(str, 0, ARRAY_SIZE(str));
  7095. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7096. system(str);
  7097. }
  7098. }
  7099. }// End of while(int k=0; k < ChargePointCount; k++)
  7100. }
  7101. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  7102. {
  7103. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  7104. for(int k=0; k < ChargeProfileCount; k++)
  7105. {
  7106. fptr1 = fopen(chargingProfiles[k], "r");
  7107. fptr2 = fopen(temp, "w+");
  7108. //Check Charging Profile Count
  7109. while(fscanf(fptr1, "%s", word) != EOF)
  7110. {
  7111. //DEBUG_INFO("word=%s\n",word);
  7112. if(strstr(word, "chargingProfileId")!= NULL)
  7113. {
  7114. n_chargingProfile = n_chargingProfile + 1;
  7115. }
  7116. }
  7117. rewind(fptr1);
  7118. //search Charging Profile Element
  7119. //int i= 0;
  7120. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7121. {
  7122. json_object *tmpProfilee;
  7123. tmpProfilee = json_tokener_parse(sLineWord);
  7124. if(!is_error(tmpProfilee))
  7125. {
  7126. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7127. {
  7128. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7129. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7130. }
  7131. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7132. {
  7133. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7134. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7135. }
  7136. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7137. {
  7138. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7139. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7140. }
  7141. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7142. {
  7143. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7144. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7145. }
  7146. }
  7147. json_object_put(tmpProfilee);
  7148. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7149. {
  7150. //------- not write to fptr2-------//
  7151. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7152. //clearflag = TRUE;
  7153. }
  7154. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7155. {
  7156. //------- not write to fptr2-------//
  7157. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7158. }
  7159. else if(stackLevelIsNULL == TRUE)
  7160. {
  7161. //Clear Whole File
  7162. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7163. clearflag = TRUE;
  7164. break;
  7165. }
  7166. else
  7167. {
  7168. fprintf(fptr2, sLineWord);//writing data into file
  7169. }
  7170. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7171. }
  7172. if(clearflag == TRUE)
  7173. {
  7174. fclose(fptr1);
  7175. fclose(fptr2);
  7176. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7177. system(str);
  7178. // clear temp file
  7179. sprintf(str,"rm -f %s",temp);
  7180. system(str);
  7181. }
  7182. else
  7183. {
  7184. fclose(fptr1);
  7185. fclose(fptr2);
  7186. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7187. system(str);
  7188. resultRename = rename(temp, chargingProfiles[k]);
  7189. if(resultRename == 0)
  7190. {
  7191. DEBUG_INFO("File ChargingProfile renamed successfully");
  7192. }
  7193. else
  7194. {
  7195. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  7196. }
  7197. if(comfirmstr[0]== 0)
  7198. {
  7199. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7200. }
  7201. //Check chargingProfile is empty file
  7202. /*------ Read the file ----------------*/
  7203. fptr1=fopen(chargingProfiles[k],"r");
  7204. ch=fgetc(fptr1);
  7205. rewind(fptr1);
  7206. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7207. if(ch!=EOF)
  7208. {
  7209. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7210. {
  7211. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7212. if(sLineWord[0]=='\0')
  7213. {
  7214. isEmptyFile = TRUE;
  7215. break;
  7216. }
  7217. else
  7218. {
  7219. isEmptyFile = FALSE;
  7220. break;
  7221. }
  7222. }
  7223. }
  7224. else
  7225. isEmptyFile = TRUE;
  7226. fclose(fptr1);
  7227. if(isEmptyFile == TRUE)
  7228. {
  7229. memset(str, 0, ARRAY_SIZE(str));
  7230. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7231. system(str);
  7232. }
  7233. /*------- End of reading ---------------*/
  7234. }
  7235. } // while(int k=0; k < ChargeProfileCount; k++)
  7236. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  7237. end:
  7238. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  7239. {
  7240. if(connectorIdInt == 0)
  7241. {
  7242. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  7243. {
  7244. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  7245. }
  7246. }
  7247. else
  7248. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  7249. }
  7250. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  7251. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7252. return result;
  7253. }
  7254. void createFirmwareVersionByDataTransfer(void)
  7255. {
  7256. json_object *FirmwareDataTransfer = json_object_new_object();
  7257. // AC & DC model
  7258. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  7259. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  7260. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  7261. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  7262. // DC model
  7263. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O')
  7264. {
  7265. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  7266. {
  7267. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7268. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7269. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  7270. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  7271. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7272. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7273. }
  7274. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  7275. ((gunType[1] != GUN_TYPE_UNKNOWN) || (gunType[2] != GUN_TYPE_UNKNOWN) || (gunType[3] != GUN_TYPE_UNKNOWN)))
  7276. {
  7277. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  7278. }
  7279. }
  7280. else
  7281. {
  7282. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7283. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7284. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7285. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7286. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  7287. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  7288. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  7289. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  7290. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  7291. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  7292. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  7293. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  7294. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  7295. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  7296. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  7297. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  7298. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  7299. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  7300. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  7301. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  7302. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  7303. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  7304. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  7305. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  7306. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  7307. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  7308. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  7309. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  7310. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  7311. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  7312. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  7313. }
  7314. // 4G model
  7315. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  7316. {
  7317. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  7318. }
  7319. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  7320. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  7321. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  7322. json_object_put(FirmwareDataTransfer);
  7323. }
  7324. int handleDataTransferRequest(char *uuid, char *payload)
  7325. {
  7326. mtrace();
  7327. json_object *response = json_object_new_object();
  7328. int result = FAIL;
  7329. char tempvendorId[255]={0};
  7330. char tempmessageId[50]={0};
  7331. char tempdata[512]={0};
  7332. char message[2048]={0};
  7333. DEBUG_INFO("handleDataTransferRequest...\n");
  7334. if((uuid != NULL) && (payload != NULL))
  7335. {
  7336. json_object *DataTransfer;
  7337. DataTransfer = json_tokener_parse(payload);
  7338. if(!is_error(DataTransfer))
  7339. {
  7340. // Required data
  7341. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  7342. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  7343. // Optional data
  7344. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  7345. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  7346. if(json_object_object_get(DataTransfer, "data") != NULL)
  7347. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  7348. result = PASS;
  7349. }
  7350. json_object_put(DataTransfer);
  7351. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  7352. {
  7353. // Send all moudle firmware version on EVSE
  7354. createFirmwareVersionByDataTransfer();
  7355. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7356. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  7357. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7358. json_object_put(response);
  7359. }
  7360. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  7361. {
  7362. system("/usr/bin/run_tmate_restart.sh &");
  7363. }
  7364. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  7365. {
  7366. json_object *data;
  7367. data = json_tokener_parse(tempdata);
  7368. if(!is_error(data))
  7369. {
  7370. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  7371. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  7372. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  7373. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  7374. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  7375. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  7376. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  7377. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  7378. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  7379. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  7380. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7381. }
  7382. else
  7383. {
  7384. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7385. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7386. }
  7387. json_object_put(data);
  7388. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7389. json_object_put(response);
  7390. }
  7391. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  7392. {
  7393. json_object *data;
  7394. data = json_tokener_parse(tempdata);
  7395. if(!is_error(data))
  7396. {
  7397. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  7398. if(json_object_object_get(data, "idToken") != NULL)
  7399. {
  7400. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  7401. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  7402. }
  7403. if(json_object_object_get(data, "price") != NULL)
  7404. {
  7405. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  7406. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  7407. }
  7408. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7409. }
  7410. else
  7411. {
  7412. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7413. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7414. }
  7415. json_object_put(data);
  7416. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7417. json_object_put(response);
  7418. }
  7419. else if(strstr(tempmessageId, "RunningCost") != NULL)
  7420. {
  7421. json_object *data;
  7422. data = json_tokener_parse(tempdata);
  7423. if(!is_error(data))
  7424. {
  7425. if(json_object_object_get(data, "txId") != NULL)
  7426. {
  7427. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7428. for(int idx = 0;idx<gunTotalNumber;idx++)
  7429. {
  7430. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7431. {
  7432. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  7433. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7434. if(json_object_object_get(data, "description") != NULL)
  7435. {
  7436. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7437. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7438. }
  7439. }
  7440. }
  7441. }
  7442. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7443. }
  7444. else
  7445. {
  7446. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7447. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7448. }
  7449. json_object_put(data);
  7450. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7451. json_object_put(response);
  7452. }
  7453. else if(strstr(tempmessageId, "FinalCost") != NULL)
  7454. {
  7455. json_object *data;
  7456. data = json_tokener_parse(tempdata);
  7457. if(!is_error(data))
  7458. {
  7459. if(json_object_object_get(data, "txId") != NULL)
  7460. {
  7461. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7462. for(int idx = 0;idx<gunTotalNumber;idx++)
  7463. {
  7464. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7465. {
  7466. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  7467. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7468. if(json_object_object_get(data, "description") != NULL)
  7469. {
  7470. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7471. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7472. }
  7473. }
  7474. }
  7475. }
  7476. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7477. }
  7478. else
  7479. {
  7480. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7481. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7482. }
  7483. json_object_put(data);
  7484. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7485. json_object_put(response);
  7486. }
  7487. else
  7488. {
  7489. // Can not find valid message id
  7490. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  7491. }
  7492. }
  7493. else
  7494. {
  7495. // Payload is null
  7496. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  7497. }
  7498. LWS_Send(message);
  7499. return result;
  7500. }
  7501. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  7502. {
  7503. mtrace();
  7504. int result = FAIL;
  7505. int connectorIdInt, durationInt;
  7506. char chargingRateUnitStr[4]={0};
  7507. char comfirmstr[20];
  7508. int confirmPeriods = 0;
  7509. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  7510. json_object *GetCompositeSchedule;
  7511. GetCompositeSchedule = json_tokener_parse(payload);
  7512. if(!is_error(GetCompositeSchedule))
  7513. {
  7514. // Required data
  7515. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  7516. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  7517. else
  7518. connectorIdInt = -1;
  7519. if(json_object_object_get(GetCompositeSchedule, "duration"))
  7520. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  7521. else
  7522. durationInt = 86400;
  7523. // Optional data
  7524. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  7525. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  7526. }
  7527. json_object_put(GetCompositeSchedule);
  7528. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  7529. if((connectorIdInt == 0) ||
  7530. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  7531. {
  7532. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  7533. struct StructChargingProfile tmpProfile[1];
  7534. if(strstr(chargingRateUnitStr, "W") != NULL)
  7535. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  7536. else
  7537. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  7538. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7539. {
  7540. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7541. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7542. }
  7543. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  7544. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  7545. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  7546. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7547. {
  7548. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7549. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7550. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  7551. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0))
  7552. {
  7553. confirmPeriods = idx;
  7554. break;
  7555. }
  7556. }
  7557. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  7558. }
  7559. else
  7560. {
  7561. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  7562. }
  7563. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  7564. return result;
  7565. }
  7566. int handleGetConfigurationRequest(char *uuid, char *payload)
  7567. {
  7568. mtrace();
  7569. int result = FAIL;
  7570. int MaxKeySupported = 0;
  7571. int n_keys = 0;
  7572. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  7573. DEBUG_INFO("handleGetConfigurationRequest...\n");
  7574. json_object *GetConfiguration;
  7575. GetConfiguration = json_tokener_parse(payload);
  7576. if(!is_error(GetConfiguration))
  7577. {
  7578. // Optional data
  7579. if(json_object_object_get(GetConfiguration, "key") != NULL)
  7580. {
  7581. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  7582. {
  7583. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  7584. n_keys = idx + 1;
  7585. }
  7586. }
  7587. }
  7588. json_object_put(GetConfiguration);
  7589. UnknownKeynum = 0;
  7590. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  7591. MaxKeySupported = GetConfigurationMaxKeysNUM;
  7592. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  7593. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  7594. if(n_keys != 0)
  7595. {
  7596. for(int i=0;i<n_keys;i++)
  7597. {
  7598. getKeyValue(requestKey[i]);
  7599. }
  7600. }
  7601. else
  7602. {
  7603. DEBUG_INFO("There is no key in Message, get all configuration\n");
  7604. getKeyValue("");
  7605. }
  7606. processUnkownKey();
  7607. sendGetConfigurationConfirmation(uuid);
  7608. return result;
  7609. }
  7610. static char fnamePlusPath[100]={0};
  7611. static char fnamePWithNoPath[60]={0};
  7612. void checkUploadLog(void)
  7613. {
  7614. FILE *fp;
  7615. /* Open the command for reading. */
  7616. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  7617. if (fp == NULL) {
  7618. printf("Failed to run command\n" );
  7619. exit(1);
  7620. }
  7621. int ftppathlen = 0;
  7622. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  7623. int i = 0;
  7624. /* Read the output a line at a time - output it. */
  7625. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  7626. if(i==0)
  7627. {
  7628. ftppathlen = strlen(fnamePlusPath);
  7629. printf("%s\n", fnamePlusPath);
  7630. fnamePlusPath[ftppathlen]='\0';
  7631. break;
  7632. }
  7633. i= i+1;
  7634. }
  7635. /* close */
  7636. pclose(fp);
  7637. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  7638. {
  7639. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  7640. {
  7641. fnamePlusPath[k]='\0';
  7642. }
  7643. }
  7644. i=1;
  7645. //char fname[60]={0};
  7646. while(i < ftppathlen)
  7647. {
  7648. int len=ftppathlen-i;
  7649. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  7650. {
  7651. printf("compare '/' all right\n");
  7652. break;
  7653. }
  7654. i=i+1;
  7655. }
  7656. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  7657. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  7658. fnamePWithNoPath[i+1] = '\0';
  7659. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  7660. {
  7661. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  7662. {
  7663. fnamePWithNoPath[j]='\0';
  7664. }
  7665. }
  7666. FILE* fp1 = fopen(fnamePlusPath, "r");
  7667. if (fp1)
  7668. {
  7669. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  7670. // file exists
  7671. fclose(fp1);
  7672. }
  7673. else
  7674. {
  7675. // file doesn't exist
  7676. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  7677. }
  7678. }
  7679. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  7680. {
  7681. mtrace();
  7682. int result = FAIL;
  7683. time_t CurrentTime;
  7684. struct tm *tm;
  7685. pthread_t th_Status;
  7686. CurrentTime = time(NULL);
  7687. tm = localtime(&CurrentTime);
  7688. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  7689. 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);
  7690. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  7691. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  7692. return result;
  7693. }
  7694. void* GetDiagnosticsProcess(void* data)
  7695. {
  7696. pthread_detach(pthread_self());
  7697. mtrace();
  7698. int retriesInt=0, retryIntervalInt=0;
  7699. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  7700. 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};
  7701. int port=0;
  7702. int isSuccess = FALSE;
  7703. char ftpbuf[200]={0};
  7704. char cmdBuf[2048];
  7705. struct tm *tmNow;
  7706. time_t CurrentTime;
  7707. struct tm tmStart;
  7708. struct tm tmStop;
  7709. CurrentTime = time(NULL);
  7710. tmNow=localtime(&CurrentTime);
  7711. uint16_t targetYear, targetMonth;
  7712. json_object *GetDiagnostics;
  7713. DEBUG_INFO("GetDiagnosticsProcess...\n");
  7714. GetDiagnostics = json_tokener_parse(data);
  7715. if(!is_error(GetDiagnostics))
  7716. {
  7717. // Required data
  7718. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  7719. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  7720. // Optional data
  7721. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  7722. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  7723. else
  7724. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  7725. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  7726. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  7727. else
  7728. retryIntervalInt = 30;
  7729. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  7730. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  7731. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  7732. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  7733. }
  7734. json_object_put(GetDiagnostics);
  7735. // Pack log to compress file
  7736. 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) &&
  7737. (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))
  7738. {
  7739. // Pack system log
  7740. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  7741. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  7742. targetYear = tmStart.tm_year;
  7743. targetMonth = tmStart.tm_mon;
  7744. do
  7745. {
  7746. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7747. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7748. if(targetMonth+1>=13)
  7749. {
  7750. targetYear += 1;
  7751. targetMonth = 1;
  7752. }
  7753. else
  7754. {
  7755. targetMonth += 1;
  7756. }
  7757. }while((targetYear < (tmNow->tm_year+1900)) ||
  7758. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  7759. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  7760. system(cmdBuf);
  7761. // Pack charging & event log
  7762. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  7763. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  7764. targetYear = tmStart.tm_year;
  7765. targetMonth = tmStart.tm_mon;
  7766. do
  7767. {
  7768. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7769. if(targetMonth+1>=13)
  7770. {
  7771. targetYear += 1;
  7772. targetMonth = 1;
  7773. }
  7774. else
  7775. {
  7776. targetMonth += 1;
  7777. }
  7778. }while((targetYear < (tmNow->tm_year+1900)) ||
  7779. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  7780. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  7781. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  7782. system(cmdBuf);
  7783. // Combine log file
  7784. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  7785. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  7786. }
  7787. else
  7788. {
  7789. system("exec /root/logPackTools 'log' 6");
  7790. }
  7791. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  7792. system(cmdBuf);
  7793. checkUploadLog();
  7794. //****************location*******************/
  7795. if(strcmp(locationstr,"")==0)
  7796. {
  7797. DEBUG_INFO("location is <Empty>!\n");
  7798. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7799. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7800. goto end;
  7801. }
  7802. memset(protocol, 0, ARRAY_SIZE(protocol));
  7803. memset(user, 0, ARRAY_SIZE(user) );
  7804. memset(password, 0, ARRAY_SIZE(password));
  7805. memset(host, 0, ARRAY_SIZE(host));
  7806. memset(path, 0, ARRAY_SIZE(path));
  7807. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  7808. memset(host1, 0, ARRAY_SIZE(host1));
  7809. memset(path1, 0, ARRAY_SIZE(path1));
  7810. /*location: ftp://user:password@host:port/path*/
  7811. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  7812. if((access(fnamePlusPath,F_OK))!=-1)
  7813. {
  7814. DEBUG_INFO("fnamePlusPath exist.\n");
  7815. }
  7816. else
  7817. {
  7818. DEBUG_INFO("fnamePlusPath not exist!\n");
  7819. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7820. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7821. goto end;
  7822. }
  7823. if(strchr(locationstr,'@')==NULL)
  7824. {
  7825. sscanf(locationstr,
  7826. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  7827. protocol, host, &port, path);
  7828. strcpy(user,"anonymous");
  7829. strcpy(password,"");
  7830. }
  7831. else
  7832. {
  7833. //DEBUG_INFO("pch=%s\n", pch);
  7834. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  7835. protocol, user, password, host, &port, path);
  7836. }
  7837. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  7838. {
  7839. DEBUG_INFO("protocol is not ftp/http ! \n");
  7840. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7841. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7842. goto end;
  7843. }
  7844. if(strncmp(locationstr,"http", 4) == 0)
  7845. {
  7846. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  7847. sprintf(ftppath,"/%s", path);
  7848. do
  7849. {
  7850. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  7851. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7852. sleep(3);
  7853. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  7854. if(!isSuccess)
  7855. {
  7856. DEBUG_INFO("Diagnostics fail.\n");
  7857. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7858. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7859. sleep(retryIntervalInt);
  7860. }
  7861. else
  7862. {
  7863. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  7864. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  7865. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7866. }
  7867. retriesInt--;
  7868. }while((isSuccess == 0)&&(retriesInt >= 0));
  7869. }
  7870. else
  7871. {
  7872. sscanf(host,"%[^/]%s",host1, path1);
  7873. if(strlen(path) > 0)
  7874. sprintf(ftppath,"/%s", path);
  7875. else
  7876. sprintf(ftppath,"/%s", path1);
  7877. int ftppathlen=strlen(ftppath);
  7878. int i=1;
  7879. char filenametemp[50];
  7880. while(i < ftppathlen)
  7881. {
  7882. int len=ftppathlen-i;
  7883. if(ftppath[len]== 47) // '/' ascll code: 47
  7884. {
  7885. DEBUG_INFO("find '/' all right\n");
  7886. break;
  7887. }
  7888. i=i+1;
  7889. }
  7890. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  7891. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  7892. filenametemp[i+1] = 0;
  7893. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  7894. if(port == 0)
  7895. port = 21;
  7896. do
  7897. {
  7898. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  7899. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7900. sleep(3);
  7901. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  7902. if(!isSuccess)
  7903. {
  7904. DEBUG_INFO("Diagnostics fail.\n");
  7905. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7906. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7907. sleep(retryIntervalInt);
  7908. }
  7909. else
  7910. {
  7911. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  7912. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  7913. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7914. }
  7915. retriesInt--;
  7916. }while((!isSuccess)&&(retriesInt >= 0));
  7917. }
  7918. end:
  7919. system("rm -f /mnt/*");
  7920. sleep(5);
  7921. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  7922. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7923. pthread_exit(NULL);
  7924. }
  7925. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  7926. {
  7927. mtrace();
  7928. int result = FAIL;
  7929. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  7930. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  7931. {
  7932. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  7933. localversion = -1;
  7934. }
  7935. else
  7936. {
  7937. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  7938. OCPP_getListVerion();
  7939. }
  7940. //from db.OCPP_getListVerion
  7941. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  7942. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  7943. sendGetLocalListVersionConfirmation(uuid,"");
  7944. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  7945. return result;
  7946. }
  7947. int handleRemoteStartRequest(char *uuid, char *payload)
  7948. {
  7949. mtrace();
  7950. int result = FAIL;
  7951. int connectorIdInt=0;
  7952. int tempIndex = 0;
  7953. int connectorIdIsNULL, chargingProfileIsNULL;
  7954. char comfirmstr[20]={0};
  7955. char cmdBuf[512];
  7956. json_object *RemoteStartTransaction;
  7957. FILE *fp;
  7958. DEBUG_INFO("handleRemoteStartRequest ...\n");
  7959. if(server_pending == TRUE)
  7960. {
  7961. return 0;
  7962. }
  7963. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  7964. RemoteStartTransaction = json_tokener_parse(payload);
  7965. if(!is_error(RemoteStartTransaction))
  7966. {
  7967. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  7968. {
  7969. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  7970. if(connectorIdInt <= gunTotalNumber)
  7971. {
  7972. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  7973. // Required data
  7974. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  7975. // Optional data
  7976. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  7977. {
  7978. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  7979. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  7980. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  7981. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  7982. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  7983. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  7984. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  7985. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  7986. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  7987. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  7988. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  7989. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  7990. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  7991. {
  7992. 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")));
  7993. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  7994. 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"));
  7995. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  7996. 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"));
  7997. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  7998. 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")));
  7999. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  8000. {
  8001. 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++)
  8002. {
  8003. 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"));
  8004. 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"));
  8005. 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)
  8006. 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"));
  8007. }
  8008. }
  8009. }
  8010. }
  8011. else
  8012. chargingProfileIsNULL = TRUE;
  8013. }
  8014. }
  8015. else
  8016. connectorIdIsNULL = TRUE;
  8017. }
  8018. else
  8019. connectorIdIsNULL = TRUE;
  8020. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  8021. {
  8022. DEBUG_WARN("Connector id is NULL\n.");
  8023. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8024. goto end;
  8025. }
  8026. /*
  8027. enum _SYSTEM_STATUS
  8028. {
  8029. S_BOOTING = 0,
  8030. S_IDLE, = 1
  8031. S_AUTHORIZING, = 2
  8032. S_REASSIGN_CHECK, = 3
  8033. S_REASSIGN, = 4
  8034. S_PRECHARGE, = 5
  8035. S_PREPARING_FOR_EV, = 6
  8036. S_PREPARING_FOR_EVSE, = 7
  8037. S_CHARGING, = 8
  8038. S_TERMINATING, = 9
  8039. S_COMPLETE, = 10
  8040. S_ALARM, = 11
  8041. S_FAULT = 12
  8042. }
  8043. */
  8044. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  8045. {
  8046. //check Transaction active
  8047. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8048. {
  8049. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8050. {
  8051. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8052. }
  8053. else
  8054. {
  8055. tempIndex = connectorIdInt -1;
  8056. }
  8057. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8058. {
  8059. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  8060. {
  8061. 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))
  8062. {
  8063. //Reserved
  8064. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8065. }
  8066. 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))
  8067. {
  8068. //Reserved
  8069. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8070. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8071. goto end;
  8072. }
  8073. else
  8074. {
  8075. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8076. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  8077. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  8078. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  8079. {
  8080. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  8081. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8082. goto end;
  8083. }
  8084. }//END FOR ELSE
  8085. }
  8086. }// END FOR CHAdeMO_QUANTITY
  8087. }
  8088. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8089. {
  8090. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8091. {
  8092. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8093. }
  8094. else
  8095. {
  8096. tempIndex = connectorIdInt -1;
  8097. }
  8098. for (int index = 0; index < CCS_QUANTITY; index++)
  8099. {
  8100. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8101. {
  8102. 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))
  8103. {
  8104. //Reserved
  8105. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8106. }
  8107. 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))
  8108. {
  8109. //Reserved
  8110. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8111. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8112. goto end;
  8113. }
  8114. else
  8115. {
  8116. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8117. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8118. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8119. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8120. {
  8121. DEBUG_WARN("CCS connector not allow start\n.");
  8122. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8123. goto end;
  8124. }
  8125. }// END FOR ELSE
  8126. }
  8127. }// END FOR CCS_QUANTITY
  8128. }
  8129. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8130. {
  8131. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8132. {
  8133. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8134. }
  8135. else
  8136. {
  8137. tempIndex = connectorIdInt -1;
  8138. }
  8139. for (int index = 0; index < GB_QUANTITY; index++)
  8140. {
  8141. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  8142. {
  8143. 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))
  8144. {
  8145. //Reserved
  8146. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8147. }
  8148. 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))
  8149. {
  8150. //Reserved
  8151. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8152. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8153. goto end;
  8154. }
  8155. else
  8156. {
  8157. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8158. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8159. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8160. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8161. {
  8162. DEBUG_WARN("GB connector not allow start\n.");
  8163. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8164. goto end;
  8165. }
  8166. }// END FOR ELSE
  8167. }
  8168. } // END FOR GB_QUANTITY
  8169. }
  8170. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8171. {
  8172. tempIndex = connectorIdInt -1;
  8173. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8174. {
  8175. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  8176. {
  8177. 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))
  8178. {
  8179. //Reserved
  8180. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8181. }
  8182. 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))
  8183. {
  8184. //Reserved
  8185. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8186. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8187. goto end;
  8188. }
  8189. else
  8190. {
  8191. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8192. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8193. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8194. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8195. {
  8196. DEBUG_WARN("GB connector not allow start\n.");
  8197. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8198. goto end;
  8199. }
  8200. }// END FOR ELSE
  8201. }
  8202. } // END FOR GB_QUANTITY
  8203. }
  8204. else
  8205. {
  8206. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8207. {
  8208. tempIndex = 2;
  8209. }
  8210. else
  8211. {
  8212. tempIndex = connectorIdInt -1;
  8213. }
  8214. for (int index = 0; index < AC_QUANTITY; index++)
  8215. {
  8216. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  8217. {
  8218. 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))
  8219. {
  8220. //Reserved
  8221. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8222. }
  8223. 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))
  8224. {
  8225. //Reserved
  8226. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8227. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8228. goto end;
  8229. }
  8230. else
  8231. {
  8232. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8233. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8234. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8235. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8236. {
  8237. DEBUG_WARN("AC connector not allow start\n.");
  8238. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8239. goto end;
  8240. }
  8241. }//END FOR ELSE
  8242. }
  8243. }// END FOR AC_QUANTITY
  8244. }
  8245. if(chargingProfileIsNULL == FALSE)
  8246. {
  8247. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8248. {
  8249. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  8250. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8251. //memset idTag
  8252. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  8253. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8254. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  8255. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8256. // Save profile to file
  8257. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8258. system(cmdBuf);
  8259. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8260. fp = fopen(cmdBuf, "w");
  8261. 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));
  8262. fclose(fp);
  8263. }
  8264. else
  8265. {
  8266. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  8267. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8268. }
  8269. }
  8270. else
  8271. {
  8272. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  8273. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8274. //memset idTag
  8275. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  8276. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8277. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  8278. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8279. }
  8280. }
  8281. else
  8282. {
  8283. DEBUG_WARN("Connector id over\n.");
  8284. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8285. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  8286. }
  8287. end:
  8288. json_object_put(RemoteStartTransaction);
  8289. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  8290. {
  8291. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  8292. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  8293. }
  8294. //OCPP send RemoteStartConfirmation by first.
  8295. sendRemoteStartConfirmation(uuid, comfirmstr);
  8296. return result;
  8297. }
  8298. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  8299. {
  8300. mtrace();
  8301. int result = FAIL;
  8302. int match = FALSE;
  8303. int GunNO = 0;
  8304. int tempIndex = 0;
  8305. int transactionIdInt=0;
  8306. int transactionIdIsNULL= TRUE;
  8307. char comfirmstr[20];
  8308. json_object *RemoteStopTransaction;
  8309. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  8310. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  8311. if(server_pending == TRUE)
  8312. {
  8313. return 0;
  8314. }
  8315. RemoteStopTransaction = json_tokener_parse(payload);
  8316. if(!is_error(RemoteStopTransaction))
  8317. {
  8318. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  8319. {
  8320. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  8321. transactionIdIsNULL = FALSE;
  8322. }
  8323. }
  8324. json_object_put(RemoteStopTransaction);
  8325. if(transactionIdIsNULL == FALSE)
  8326. {
  8327. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  8328. {
  8329. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  8330. {
  8331. //check Transaction active
  8332. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  8333. {
  8334. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8335. {
  8336. tempIndex = ((gun_index==2) ? 1: 0);
  8337. }
  8338. else
  8339. {
  8340. tempIndex = gun_index;
  8341. }
  8342. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8343. {
  8344. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8345. {
  8346. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8347. {
  8348. match = TRUE;
  8349. GunNO = gun_index;
  8350. }
  8351. }
  8352. }// END FOR CHAdeMO_QUANTITY
  8353. }
  8354. else if(gunType[gun_index] == GUN_TYPE_CCS)
  8355. {
  8356. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8357. {
  8358. tempIndex = ((gun_index==2) ? 1: 0);
  8359. }
  8360. else
  8361. {
  8362. tempIndex = gun_index;
  8363. }
  8364. for (int index = 0; index < CCS_QUANTITY; index++)
  8365. {
  8366. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8367. {
  8368. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8369. {
  8370. match = TRUE;
  8371. GunNO = gun_index;
  8372. }
  8373. }
  8374. }// END FOR CCS_QUANTITY
  8375. }
  8376. else if(gunType[gun_index] == GUN_TYPE_GBT)
  8377. {
  8378. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8379. {
  8380. tempIndex = ((gun_index==2) ? 1: 0);
  8381. }
  8382. else
  8383. {
  8384. tempIndex = gun_index;
  8385. }
  8386. for (int index = 0; index < GB_QUANTITY; index++)
  8387. {
  8388. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8389. {
  8390. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8391. {
  8392. match = TRUE;
  8393. GunNO = gun_index;
  8394. }
  8395. }
  8396. }// END FOR GB_QUANTITY
  8397. }
  8398. else if(gunType[gun_index] == GUN_TYPE_DO)
  8399. {
  8400. tempIndex = gun_index;
  8401. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8402. {
  8403. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8404. {
  8405. 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
  8406. {
  8407. match = TRUE;
  8408. GunNO = gun_index;
  8409. }
  8410. }
  8411. }// END FOR GB_QUANTITY
  8412. }
  8413. else
  8414. {
  8415. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8416. {
  8417. tempIndex = 2;
  8418. }
  8419. else
  8420. {
  8421. tempIndex = gun_index;
  8422. }
  8423. for (int index = 0; index < AC_QUANTITY; index++)
  8424. {
  8425. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8426. {
  8427. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8428. {
  8429. match = TRUE;
  8430. GunNO = gun_index;
  8431. }
  8432. }
  8433. }// END FOR CHAdeMO_QUANTITY
  8434. } // END FOR AC ELSE
  8435. }// CHECK IF ResponseTransactionId == transactionIdInt
  8436. }//END FOR
  8437. if( match == TRUE)
  8438. {
  8439. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  8440. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8441. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  8442. }
  8443. else
  8444. {
  8445. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8446. }
  8447. }
  8448. else
  8449. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8450. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  8451. return result;
  8452. }
  8453. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  8454. {
  8455. mtrace();
  8456. int result = FAIL;
  8457. int connectorIdInt=0, reservationIdInt=0;
  8458. int tempIndex = 0;
  8459. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  8460. char comfirmstr[20]={0};
  8461. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  8462. int c = 0;
  8463. char *loc;
  8464. //char *ptr;
  8465. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  8466. strcpy(sstrtemp, stringtrimspace(payload));
  8467. //***(1)connectorId ****/
  8468. c=0;
  8469. loc = strstr(sstrtemp, "connectorId");
  8470. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8471. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  8472. {
  8473. sstr[c] = loc[strlen("connectorId")+2+c];
  8474. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8475. c++;
  8476. }
  8477. sstr[c] = '\0';
  8478. connectorIdInt = atoi(sstr);
  8479. //***(2)expiryDate ****/
  8480. loc = strstr(sstrtemp, "expiryDate");
  8481. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8482. c = 0;
  8483. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  8484. {
  8485. sstr[c] = loc[3+strlen("expiryDate")+c];
  8486. c++;
  8487. }
  8488. sstr[c] = '\0';
  8489. strcpy(expiryDatestr, sstr);
  8490. //***(3)idTag ****/
  8491. loc = strstr(sstrtemp, "idTag");
  8492. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8493. c = 0;
  8494. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  8495. {
  8496. sstr[c] = loc[3+strlen("idTag")+c];
  8497. c++;
  8498. }
  8499. sstr[c] = '\0';
  8500. strcpy(idTagstr, sstr);
  8501. //***(4)parentIdTag ****/
  8502. loc = strstr(sstrtemp, "parentIdTag");
  8503. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8504. c = 0;
  8505. if(loc == NULL)
  8506. {
  8507. strcpy(parentIdTagstr, "");
  8508. }
  8509. else
  8510. {
  8511. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8512. {
  8513. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8514. c++;
  8515. }
  8516. sstr[c] = '\0';
  8517. strcpy(parentIdTagstr, sstr);
  8518. }
  8519. //***(5)reservationId ****/
  8520. c=0;
  8521. loc = strstr(sstrtemp, "reservationId");
  8522. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8523. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  8524. {
  8525. sstr[c] = loc[strlen("reservationId")+2+c];
  8526. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8527. c++;
  8528. }
  8529. sstr[c] = '\0';
  8530. reservationIdInt = atoi(sstr);
  8531. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8532. /*
  8533. enum SYSTEM_STATUS
  8534. {
  8535. SYS_MODE_BOOTING = 0,
  8536. SYS_MODE_IDLE = 1,
  8537. SYS_MODE_AUTHORIZING = 2,
  8538. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  8539. SYS_MODE_REASSIGN = 4,
  8540. SYS_MODE_PREPARING = 5,
  8541. SYS_MODE_PREPARE_FOR_EV = 6,
  8542. SYS_MODE_PREPARE_FOR_EVSE = 7,
  8543. SYS_MODE_CHARGING = 8,
  8544. SYS_MODE_TERMINATING = 9,
  8545. SYS_MODE_COMPLETE = 10,
  8546. SYS_MODE_ALARM = 11,
  8547. SYS_MODE_FAULT = 12,
  8548. SYS_MODE_RESERVATION = 13,
  8549. SYS_MODE_BOOKING = 14,
  8550. SYS_MODE_MAINTAIN = 15,
  8551. SYS_MODE_DEBUG = 16,
  8552. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  8553. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  8554. SYS_MODE_UPDATE = 19
  8555. };
  8556. */
  8557. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  8558. {
  8559. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8560. goto end;
  8561. }
  8562. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  8563. {
  8564. //check Transaction active
  8565. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8566. {
  8567. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8568. {
  8569. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8570. }
  8571. else
  8572. {
  8573. tempIndex = connectorIdInt -1;
  8574. }
  8575. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8576. {
  8577. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8578. {
  8579. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  8580. {
  8581. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8582. {
  8583. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8584. {
  8585. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8586. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8587. }
  8588. 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'))
  8589. {
  8590. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8591. }
  8592. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8593. {
  8594. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8595. }
  8596. else
  8597. {
  8598. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8599. }
  8600. }
  8601. 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
  8602. {
  8603. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8604. }
  8605. }
  8606. else
  8607. {
  8608. //replace reservation
  8609. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8610. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8611. }
  8612. }
  8613. } // END FOR CHAdeMO_QUANTITY
  8614. }
  8615. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8616. {
  8617. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8618. {
  8619. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8620. }
  8621. else
  8622. {
  8623. tempIndex = connectorIdInt -1;
  8624. }
  8625. for (int index = 0; index < CCS_QUANTITY; index++)
  8626. {
  8627. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8628. {
  8629. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8630. {
  8631. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8632. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8633. {
  8634. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8635. {
  8636. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8637. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8638. }
  8639. 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'))
  8640. {
  8641. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8642. }
  8643. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  8644. {
  8645. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8646. }
  8647. else
  8648. {
  8649. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8650. }
  8651. }
  8652. 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
  8653. {
  8654. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8655. }
  8656. }
  8657. else
  8658. {
  8659. //replace reservation
  8660. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8661. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8662. }
  8663. }
  8664. } // END FOR CCS_QUANTITY
  8665. }
  8666. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8667. {
  8668. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8669. {
  8670. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8671. }
  8672. else
  8673. {
  8674. tempIndex = connectorIdInt -1;
  8675. }
  8676. for (int index = 0; index < GB_QUANTITY; index++)
  8677. {
  8678. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8679. {
  8680. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8681. {
  8682. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8683. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  8684. {
  8685. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8686. {
  8687. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8688. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8689. }
  8690. 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'))
  8691. {
  8692. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8693. }
  8694. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8695. {
  8696. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8697. }
  8698. else
  8699. {
  8700. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8701. }
  8702. }
  8703. 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
  8704. {
  8705. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8706. }
  8707. }
  8708. else
  8709. {
  8710. //replace reservation
  8711. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8712. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8713. }
  8714. }
  8715. }// END FOR GB_QUANTITY
  8716. }
  8717. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8718. {
  8719. tempIndex = connectorIdInt -1;
  8720. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8721. {
  8722. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8723. {
  8724. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  8725. {
  8726. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8727. 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
  8728. {
  8729. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8730. {
  8731. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8732. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8733. }
  8734. 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'))
  8735. {
  8736. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8737. }
  8738. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8739. {
  8740. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8741. }
  8742. else
  8743. {
  8744. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8745. }
  8746. }
  8747. 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
  8748. {
  8749. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8750. }
  8751. }
  8752. else
  8753. {
  8754. //replace reservation
  8755. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8756. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8757. }
  8758. }
  8759. }// END FOR GB_QUANTITY
  8760. }
  8761. else
  8762. {
  8763. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8764. {
  8765. tempIndex = 2;
  8766. }
  8767. else
  8768. {
  8769. tempIndex = (connectorIdInt -1);
  8770. }
  8771. for (int index = 0; index < AC_QUANTITY; index++)
  8772. {
  8773. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8774. {
  8775. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  8776. {
  8777. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  8778. {
  8779. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8780. {
  8781. 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))
  8782. {
  8783. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8784. }
  8785. else
  8786. {
  8787. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8788. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8789. }
  8790. }
  8791. 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'))
  8792. {
  8793. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8794. }
  8795. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8796. {
  8797. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8798. }
  8799. else
  8800. {
  8801. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8802. }
  8803. }
  8804. 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
  8805. {
  8806. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8807. }
  8808. }
  8809. else
  8810. {
  8811. //replace reservation
  8812. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8813. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8814. }
  8815. }
  8816. } // END FOR AC_QUANTITY
  8817. }
  8818. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8819. }
  8820. else if(connectorIdInt == 0)
  8821. {
  8822. //check Transaction active
  8823. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8824. {
  8825. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  8826. {
  8827. 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'))
  8828. {
  8829. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8830. goto end;
  8831. }
  8832. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8833. {
  8834. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8835. goto end;
  8836. }
  8837. 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
  8838. {
  8839. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8840. goto end;
  8841. }
  8842. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8843. {
  8844. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8845. goto end;
  8846. }
  8847. }
  8848. }// END FOR CHAdeMO_QUANTITY
  8849. for (int index = 0; index < CCS_QUANTITY; index++)
  8850. {
  8851. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8852. {
  8853. 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'))
  8854. {
  8855. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8856. goto end;
  8857. }
  8858. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  8859. {
  8860. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8861. goto end;
  8862. }
  8863. 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
  8864. {
  8865. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8866. goto end;
  8867. }
  8868. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8869. {
  8870. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8871. goto end;
  8872. }
  8873. }
  8874. } // END FOR CCS_QUANTITY
  8875. for (int index = 0; index < GB_QUANTITY; index++)
  8876. {
  8877. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8878. {
  8879. 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'))
  8880. {
  8881. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8882. goto end;
  8883. }
  8884. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8885. {
  8886. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8887. goto end;
  8888. }
  8889. 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
  8890. {
  8891. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8892. goto end;
  8893. }
  8894. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8895. {
  8896. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8897. goto end;
  8898. }
  8899. }
  8900. } // END FOR GB_QUANTITY
  8901. for (int index = 0; index < AC_QUANTITY; index++)
  8902. {
  8903. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  8904. {
  8905. 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'))
  8906. {
  8907. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8908. goto end;
  8909. }
  8910. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8911. {
  8912. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8913. goto end;
  8914. }
  8915. 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
  8916. {
  8917. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8918. goto end;
  8919. }
  8920. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8921. {
  8922. 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))
  8923. {
  8924. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8925. goto end;
  8926. }
  8927. }
  8928. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8929. {
  8930. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8931. goto end;
  8932. }
  8933. }
  8934. }// END FOR AC_QUANTITY
  8935. //The connectorId is 0
  8936. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  8937. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8938. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  8939. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  8940. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  8941. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  8942. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  8943. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  8944. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  8945. result = TRUE;
  8946. return result;
  8947. }
  8948. else
  8949. {
  8950. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8951. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8952. }
  8953. if(strcmp(comfirmstr,"Accepted") == 0)
  8954. {
  8955. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  8956. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  8957. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  8958. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  8959. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  8960. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  8961. result = TRUE;
  8962. return result;
  8963. }
  8964. end:
  8965. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  8966. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  8967. return result;
  8968. }
  8969. int handleResetRequest(char *uuid, char *payload)
  8970. {
  8971. mtrace();
  8972. int result = FAIL;
  8973. char sstr[10]={0},sstrtemp[30]={ 0 };
  8974. char typestr[10]={0};
  8975. char comfirmstr[20]={0};
  8976. int c = 0;
  8977. char *loc;
  8978. DEBUG_INFO("handleResetRequest...\n");
  8979. strcpy(sstrtemp, stringtrimspace(payload));
  8980. loc = strstr(sstrtemp, "type");
  8981. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8982. c = 0;
  8983. while (loc[3+strlen("type")+c] != '\"')
  8984. {
  8985. sstr[c] = loc[3+strlen("type")+c];
  8986. c++;
  8987. }
  8988. sstr[c] = '\0';
  8989. strcpy(typestr,sstr);
  8990. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  8991. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  8992. {
  8993. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  8994. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  8995. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  8996. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  8997. }
  8998. else
  8999. {
  9000. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  9001. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  9002. result = PASS;
  9003. }
  9004. sendResetConfirmation(uuid, comfirmstr);
  9005. return result;
  9006. }
  9007. int handleSendLocalListRequest(char *uuid, char *payload)
  9008. {
  9009. mtrace();
  9010. int result = FAIL;
  9011. int listVersionInt;
  9012. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  9013. char listsearch[]="listVersion";
  9014. char updateTypesearch[]="updateType";
  9015. char localAuthorizationListsearch[]="localAuthorizationList";
  9016. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  9017. char CardList[500][160]={0};
  9018. char updateTypestr[15]={0};
  9019. char idTagstr[20]={0};
  9020. char parentIdTag[20]={0};
  9021. char expiryDate[30]={0};
  9022. char idTagstatus[16]={0};
  9023. int c = 0;
  9024. int i = 0;
  9025. char *delim1 = "}";
  9026. char * pch;
  9027. char *loc;
  9028. //char *ptr;
  9029. char comfirmstr[20];
  9030. //int n_localAuthorizations = 0;
  9031. int checkState_Faulted = FALSE;
  9032. DEBUG_INFO("handleSendLocalListRequest...\n");
  9033. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  9034. {
  9035. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9036. goto end;
  9037. }
  9038. //check Charge Point state
  9039. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9040. {
  9041. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9042. {
  9043. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9044. }
  9045. }
  9046. for (int index = 0; index < CCS_QUANTITY; index++)
  9047. {
  9048. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9049. {
  9050. checkState_Faulted = TRUE; //OCPP Status
  9051. }
  9052. }
  9053. for (int index = 0; index < GB_QUANTITY; index++)
  9054. {
  9055. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9056. {
  9057. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9058. }
  9059. }
  9060. //check Charge Point state
  9061. for (int index = 0; index < AC_QUANTITY; index++)
  9062. {
  9063. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9064. {
  9065. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9066. }
  9067. }
  9068. if(checkState_Faulted == TRUE)
  9069. {
  9070. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9071. goto end;
  9072. }
  9073. //Filter payload space
  9074. strcpy(sstrtemp, stringtrimspace(payload));
  9075. //listVersion
  9076. c = 0;
  9077. loc = strstr(sstrtemp, listsearch);
  9078. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  9079. {
  9080. sstr[c] = loc[strlen("listVersion")+2+c];
  9081. c++;
  9082. }
  9083. sstr[c] = '\0';
  9084. listVersionInt = atoi(sstr);
  9085. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  9086. //updateType
  9087. loc = strstr(sstrtemp, updateTypesearch);
  9088. c = 0;
  9089. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  9090. {
  9091. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  9092. c++;
  9093. }
  9094. sstr[c] = '\0';
  9095. strcpy(updateTypestr, sstr);
  9096. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  9097. //localAuthorizationList
  9098. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9099. loc = strstr(sstrtemp, localAuthorizationListsearch);
  9100. if(loc != NULL) // localAuthorizationList is not NULL
  9101. {
  9102. //Check UpdateType
  9103. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  9104. {
  9105. //Local list full update
  9106. printf("Local list full update.\n");
  9107. OCPP_getListVerion();
  9108. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  9109. {
  9110. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9111. goto end;
  9112. }
  9113. OCPP_cleanLocalList();
  9114. }
  9115. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  9116. {
  9117. //Local list different update
  9118. printf("Local list different update.\n");
  9119. OCPP_getListVerion();
  9120. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  9121. {
  9122. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  9123. goto end;
  9124. }
  9125. }
  9126. else
  9127. {
  9128. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9129. goto end;
  9130. }
  9131. c = 0;
  9132. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  9133. {
  9134. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  9135. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9136. c++;
  9137. }
  9138. sstr[c] = '\0';
  9139. //DEBUG_INFO("sstr=%s\n", sstr);
  9140. //parsing strings to words
  9141. i = 0;
  9142. pch = strtok(sstr,delim1);
  9143. while (pch != NULL)
  9144. {
  9145. strcpy(CardList[i], pch);
  9146. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  9147. pch = strtok (NULL, delim1);
  9148. i = i + 1;
  9149. }
  9150. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  9151. //local Authorizations List Numbers
  9152. //n_localAuthorizations = i;
  9153. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  9154. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  9155. c= 0;
  9156. while(c < i) // i is CardList Number
  9157. {
  9158. //Search "IdToken"
  9159. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9160. loc = strstr(CardList[c], "idTag");
  9161. int j = 0;
  9162. while (loc[3+strlen("idTag")+j] != '\"')
  9163. {
  9164. sstr[j] = loc[3+strlen("idTag")+j];
  9165. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9166. j++;
  9167. }
  9168. sstr[j] = '\0';
  9169. strcpy(idTagstr, sstr);
  9170. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  9171. //Search "expiryDate"
  9172. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9173. loc = strstr(CardList[c], "expiryDate");
  9174. j = 0;
  9175. if(loc != NULL)
  9176. {
  9177. while (loc[3+strlen("expiryDate")+j] != '\"')
  9178. {
  9179. sstr[j] = loc[3+strlen("expiryDate")+j];
  9180. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9181. j++;
  9182. }
  9183. sstr[j] = '\0';
  9184. strcpy(expiryDate, sstr);
  9185. }
  9186. else
  9187. {
  9188. strcpy(expiryDate, "");
  9189. }
  9190. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  9191. //Search "parentIdTag"
  9192. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9193. loc = strstr(CardList[c], "parentIdTag");
  9194. j = 0;
  9195. if(loc != NULL)
  9196. {
  9197. while (loc[3+strlen("parentIdTag")+j] != '\"')
  9198. {
  9199. sstr[j] = loc[3+strlen("parentIdTag")+j];
  9200. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9201. j++;
  9202. }
  9203. sstr[j] = '\0';
  9204. strcpy(parentIdTag, sstr);
  9205. }
  9206. else
  9207. {
  9208. strcpy(parentIdTag, "");
  9209. }
  9210. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  9211. //Search "status"
  9212. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9213. loc = strstr(CardList[c], "status");
  9214. j = 0;
  9215. while (loc[3+strlen("status")+j] != '\"')
  9216. {
  9217. sstr[j] = loc[3+strlen("status")+j];
  9218. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9219. j++;
  9220. }
  9221. sstr[j] = '\0';
  9222. strcpy(idTagstatus, sstr);
  9223. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  9224. OCPP_getIdTagFromLocalList(idTagstr);
  9225. //OCPP_getIdTagFromLocalList("test"); For Test
  9226. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  9227. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  9228. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  9229. {
  9230. //Local list full update
  9231. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  9232. // update list
  9233. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  9234. //DEBUG_INFO("Local list full update. 1\n");
  9235. //OCPP_get_TableAuthlocalAllData();
  9236. //DEBUG_INFO("Local list full update. 2\n");
  9237. }
  9238. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  9239. {
  9240. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  9241. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  9242. }
  9243. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  9244. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  9245. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  9246. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  9247. c++;
  9248. }
  9249. }
  9250. else
  9251. {
  9252. //Check UpdateType
  9253. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  9254. {
  9255. //Local list full update
  9256. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  9257. OCPP_cleanLocalList();
  9258. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9259. goto end;
  9260. }
  9261. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  9262. {
  9263. //Local list different update
  9264. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  9265. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9266. goto end;
  9267. }
  9268. }
  9269. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9270. end:
  9271. sendSendLocalListConfirmation(uuid, comfirmstr);
  9272. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  9273. return result;
  9274. }
  9275. #define MAX 200
  9276. int handleSetChargingProfileRequest(char *uuid, char *payload)
  9277. {
  9278. mtrace();
  9279. int result = FAIL;
  9280. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  9281. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  9282. char chargingProfilePurposeStr[30]={0};
  9283. char chargingProfileKindStr[16]={0};
  9284. char recurrencyKindStr[10]={0};
  9285. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  9286. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  9287. int chargingSchedulePeriodCount = 0;
  9288. char comfirmstr[20]={0};
  9289. int meet= FALSE;
  9290. FILE *fptr1;
  9291. char filename[MAX]={0};
  9292. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  9293. char rmFileCmd[50]={0};
  9294. char tempchargingProfilePurposeStr[30]={0};
  9295. char word[1600]={0};
  9296. int n_chargingProfile = 0;
  9297. json_object *SetChargingProfile;
  9298. DEBUG_INFO("handleSetChargingProfileRequest\n");
  9299. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  9300. SetChargingProfile = json_tokener_parse(payload);
  9301. if(!is_error(SetChargingProfile))
  9302. {
  9303. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  9304. {
  9305. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  9306. if(connectorIdInt == 0)
  9307. {
  9308. memset(&ShmOCPP16Data->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  9309. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  9310. }
  9311. else
  9312. {
  9313. memset(&ShmOCPP16Data->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  9314. ShmOCPP16Data->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  9315. }
  9316. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  9317. }
  9318. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  9319. {
  9320. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  9321. {
  9322. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  9323. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9324. {
  9325. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  9326. }
  9327. else
  9328. {
  9329. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  9330. }
  9331. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  9332. }
  9333. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  9334. {
  9335. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  9336. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9337. {
  9338. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  9339. }
  9340. else
  9341. {
  9342. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  9343. }
  9344. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  9345. }
  9346. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9347. {
  9348. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  9349. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9350. {
  9351. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  9352. }
  9353. else
  9354. {
  9355. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  9356. }
  9357. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  9358. }
  9359. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  9360. {
  9361. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  9362. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9363. {
  9364. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  9365. }
  9366. else
  9367. {
  9368. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  9369. }
  9370. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  9371. }
  9372. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  9373. {
  9374. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  9375. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9376. {
  9377. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  9378. }
  9379. else
  9380. {
  9381. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  9382. }
  9383. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  9384. }
  9385. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  9386. {
  9387. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  9388. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9389. {
  9390. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9391. }
  9392. else
  9393. {
  9394. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9395. }
  9396. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  9397. }
  9398. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  9399. {
  9400. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  9401. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9402. {
  9403. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  9404. }
  9405. else
  9406. {
  9407. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  9408. }
  9409. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  9410. }
  9411. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  9412. {
  9413. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  9414. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9415. {
  9416. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  9417. }
  9418. else
  9419. {
  9420. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  9421. }
  9422. //DEBUG_INFO("validToStr: %s\n", validToStr);
  9423. }
  9424. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  9425. {
  9426. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  9427. {
  9428. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  9429. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9430. {
  9431. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9432. }
  9433. else
  9434. {
  9435. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9436. }
  9437. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  9438. }
  9439. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  9440. {
  9441. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  9442. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9443. {
  9444. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9445. }
  9446. else
  9447. {
  9448. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9449. }
  9450. //DEBUG_INFO("durationInt: %d\n", durationInt);
  9451. }
  9452. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  9453. {
  9454. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  9455. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9456. {
  9457. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9458. }
  9459. else
  9460. {
  9461. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9462. }
  9463. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  9464. }
  9465. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  9466. {
  9467. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  9468. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9469. {
  9470. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9471. }
  9472. else
  9473. {
  9474. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9475. }
  9476. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  9477. }
  9478. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9479. {
  9480. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  9481. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  9482. if(chargingSchedulePeriodCount <= 10)
  9483. {
  9484. 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++)
  9485. {
  9486. 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)
  9487. {
  9488. 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"));
  9489. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9490. {
  9491. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9492. }
  9493. else
  9494. {
  9495. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9496. }
  9497. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  9498. }
  9499. 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)
  9500. {
  9501. 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"));
  9502. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9503. {
  9504. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9505. }
  9506. else
  9507. {
  9508. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9509. }
  9510. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  9511. }
  9512. 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)
  9513. {
  9514. 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"));
  9515. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9516. {
  9517. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9518. }
  9519. else
  9520. {
  9521. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9522. }
  9523. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  9524. }
  9525. }
  9526. }
  9527. }
  9528. }
  9529. }
  9530. }
  9531. json_object_put(SetChargingProfile);
  9532. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  9533. {
  9534. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9535. goto end;
  9536. }
  9537. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  9538. {
  9539. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  9540. if(connectorIdInt != 0)
  9541. {
  9542. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9543. goto end;
  9544. }
  9545. strcpy(filename, ChargePointMaxProfile_JSON );
  9546. fptr1 = fopen(filename, "r");
  9547. if (!fptr1)
  9548. {
  9549. //file not exist
  9550. DEBUG_INFO("Unable to open the input file!!\n");
  9551. fptr1 = fopen(filename, "w+");
  9552. }
  9553. else
  9554. {
  9555. //Check Charging Profile Count
  9556. while(fscanf(fptr1, "%s", word) != EOF)
  9557. {
  9558. //DEBUG_INFO("word=%s\n",word);
  9559. if(strstr(word, "chargingProfileId")!= NULL)
  9560. {
  9561. //DEBUG_INFO("test chargingProfileId \n");
  9562. n_chargingProfile = n_chargingProfile + 1;
  9563. //DEBUG_INFO("chargingProfileId Found\n");
  9564. }
  9565. }
  9566. }
  9567. fclose(fptr1);
  9568. }
  9569. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  9570. {
  9571. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  9572. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9573. {
  9574. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9575. goto end;
  9576. }
  9577. memset(filename, 0, ARRAY_SIZE(filename));
  9578. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9579. fptr1 = fopen(filename, "r");
  9580. if (!fptr1)
  9581. {
  9582. //file not exist
  9583. //DEBUG_INFO("Unable to open the input file!!\n");
  9584. fptr1 = fopen(filename, "w+");
  9585. }
  9586. else
  9587. {
  9588. //Check Charging Profile Count
  9589. while(fscanf(fptr1, "%s", word) != EOF)
  9590. {
  9591. //DEBUG_INFO("word=%s\n",word);
  9592. if(strstr(word, "chargingProfileId")!= NULL)
  9593. {
  9594. //DEBUG_INFO("test chargingProfileId \n");
  9595. n_chargingProfile = n_chargingProfile + 1;
  9596. //DEBUG_INFO("chargingProfileId Found\n");
  9597. }
  9598. }
  9599. }
  9600. fclose(fptr1);
  9601. }
  9602. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9603. {
  9604. //printf("set chargingProfile 1-4\n");
  9605. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  9606. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  9607. if(connectorIdInt == 0)
  9608. {
  9609. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9610. goto end;
  9611. }
  9612. int tempIndex = 0;
  9613. //check Transaction active
  9614. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9615. {
  9616. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9617. {
  9618. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9619. }
  9620. else
  9621. {
  9622. tempIndex = connectorIdInt -1;
  9623. }
  9624. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9625. {
  9626. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9627. {
  9628. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9629. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9630. {
  9631. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9632. {
  9633. meet = TRUE;
  9634. break;
  9635. }
  9636. }
  9637. }
  9638. }
  9639. }
  9640. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9641. {
  9642. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9643. {
  9644. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9645. }
  9646. else
  9647. {
  9648. tempIndex = connectorIdInt -1;
  9649. }
  9650. for (int index = 0; index < CCS_QUANTITY; index++)
  9651. {
  9652. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9653. {
  9654. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9655. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9656. {
  9657. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9658. {
  9659. meet = TRUE;
  9660. break;
  9661. }
  9662. }
  9663. }
  9664. }
  9665. }
  9666. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9667. {
  9668. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9669. {
  9670. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9671. }
  9672. else
  9673. {
  9674. tempIndex = connectorIdInt -1;
  9675. }
  9676. for (int index = 0; index < GB_QUANTITY; index++)
  9677. {
  9678. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9679. {
  9680. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9681. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9682. {
  9683. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9684. {
  9685. meet = TRUE;
  9686. break;
  9687. }
  9688. }
  9689. }
  9690. }
  9691. }
  9692. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9693. {
  9694. tempIndex = connectorIdInt -1;
  9695. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9696. {
  9697. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9698. {
  9699. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  9700. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9701. {
  9702. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9703. {
  9704. meet = TRUE;
  9705. break;
  9706. }
  9707. }
  9708. }
  9709. }
  9710. }
  9711. else
  9712. {
  9713. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9714. {
  9715. tempIndex = 2;
  9716. }
  9717. else
  9718. {
  9719. tempIndex = (connectorIdInt -1);
  9720. }
  9721. for (int index = 0; index < AC_QUANTITY; index++)
  9722. {
  9723. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9724. {
  9725. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9726. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9727. {
  9728. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9729. {
  9730. meet = TRUE;
  9731. break;
  9732. }
  9733. }
  9734. }
  9735. }
  9736. }
  9737. //check Transaction active
  9738. if(meet == FALSE)
  9739. {
  9740. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9741. goto end;
  9742. }
  9743. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9744. {
  9745. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9746. goto end;
  9747. }
  9748. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9749. fptr1 = fopen(filename, "r");
  9750. if (!fptr1)
  9751. {
  9752. //file not exist
  9753. DEBUG_INFO("Unable to open the input file!!\n");
  9754. fptr1 = fopen(filename, "w+");
  9755. }
  9756. else
  9757. {
  9758. //Check Charging Profile Count
  9759. while(fscanf(fptr1, "%s", word) != EOF)
  9760. {
  9761. //DEBUG_INFO("word=%s\n",word);
  9762. if(strstr(word, "chargingProfileId")!= NULL)
  9763. {
  9764. //DEBUG_INFO("test chargingProfileId \n");
  9765. n_chargingProfile = n_chargingProfile + 1;
  9766. //DEBUG_INFO("chargingProfileId Found\n");
  9767. }
  9768. }
  9769. }
  9770. fclose(fptr1);
  9771. }
  9772. // Check ChargeProfileMaxStackLevel
  9773. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  9774. {
  9775. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9776. goto end;
  9777. }
  9778. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9779. {
  9780. int i = 0;
  9781. char fnametemp[200]={0};
  9782. n_chargingProfile = 0;
  9783. //Check ChargePointMaxProfile.json exit
  9784. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9785. {
  9786. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  9787. //Check Charging Profile Count
  9788. while(fscanf(fptr1, "%s", word) != EOF)
  9789. {
  9790. //DEBUG_INFO("word=%s\n",word);
  9791. if(strstr(word, "chargingProfileId")!= NULL)
  9792. {
  9793. //DEBUG_INFO("test chargingProfileId \n");
  9794. n_chargingProfile = n_chargingProfile + 1;
  9795. i = i + 1;
  9796. //DEBUG_INFO("chargingProfileId Found\n");
  9797. }
  9798. memset(word, 0, ARRAY_SIZE(word));
  9799. }
  9800. fclose(fptr1);
  9801. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  9802. }
  9803. //Check TxDefaultProfile_0.json exit
  9804. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9805. {
  9806. i = 0;
  9807. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  9808. //Check Charging Profile Count
  9809. while(fscanf(fptr1, "%s", word) != EOF)
  9810. {
  9811. //DEBUG_INFO("word=%s\n",word);
  9812. if(strstr(word, "chargingProfileId")!= NULL)
  9813. {
  9814. //DEBUG_INFO("test chargingProfileId \n");
  9815. n_chargingProfile = n_chargingProfile + 1;
  9816. i = i + 1;
  9817. //DEBUG_INFO("chargingProfileId Found\n");
  9818. }
  9819. memset(word, 0, ARRAY_SIZE(word));
  9820. }
  9821. fclose(fptr1);
  9822. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  9823. }
  9824. //Check TxDefaultProfile_%d.json
  9825. for(int j=1; j <= gunTotalNumber; j++)
  9826. {
  9827. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9828. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9829. if((access(fnametemp,F_OK))!=-1)
  9830. {
  9831. i = 0;
  9832. fptr1 = fopen(fnametemp, "r");
  9833. //Check Charging Profile Count
  9834. while(fscanf(fptr1, "%s", word) != EOF)
  9835. {
  9836. //DEBUG_INFO("word=%s\n",word);
  9837. if(strstr(word, "chargingProfileId")!= NULL)
  9838. {
  9839. //DEBUG_INFO("test chargingProfileId \n");
  9840. n_chargingProfile = n_chargingProfile + 1;
  9841. i = i + 1;
  9842. //DEBUG_INFO("chargingProfileId Found\n");
  9843. }
  9844. memset(word, 0, ARRAY_SIZE(word));
  9845. }
  9846. fclose(fptr1);
  9847. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9848. }
  9849. }
  9850. //Check TxProfile_%d.json
  9851. for(int j=1; j <= gunTotalNumber; j++)
  9852. {
  9853. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9854. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9855. if((access(fnametemp,F_OK))!=-1)
  9856. {
  9857. i = 0;
  9858. fptr1 = fopen(fnametemp, "r");
  9859. //Check Charging Profile Count
  9860. while(fscanf(fptr1, "%s", word) != EOF)
  9861. {
  9862. //DEBUG_INFO("word=%s\n",word);
  9863. if(strstr(word, "chargingProfileId")!= NULL)
  9864. {
  9865. //DEBUG_INFO("test chargingProfileId \n");
  9866. n_chargingProfile = n_chargingProfile + 1;
  9867. i = i + 1;
  9868. //DEBUG_INFO("chargingProfileId Found\n");
  9869. }
  9870. memset(word, 0, ARRAY_SIZE(word));
  9871. }
  9872. fclose(fptr1);
  9873. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9874. }
  9875. }
  9876. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  9877. {
  9878. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9879. goto end;
  9880. }
  9881. }
  9882. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9883. //**********************************Write to File********************************************************/
  9884. FILE *infile;
  9885. FILE *outfile;
  9886. infile = fopen (filename, "r");
  9887. outfile = fopen (tempfile, "w");
  9888. int d =0;
  9889. d = fgetc(infile);
  9890. rewind(infile);
  9891. if(d == EOF)
  9892. {
  9893. // Profile is empty
  9894. fprintf(outfile,"%s\n",payload);
  9895. fclose(infile);
  9896. fclose(outfile);
  9897. sprintf(rmFileCmd,"rm -f %s",filename);
  9898. system(rmFileCmd);
  9899. rename(tempfile, filename);
  9900. }
  9901. else
  9902. {
  9903. // Profile is not empty
  9904. char buf[2048]={0};
  9905. int ChargingProfileAdded = FALSE;
  9906. while (fgets(buf, sizeof(buf), infile) != NULL)
  9907. {
  9908. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9909. json_object *tmpChargingProfile;
  9910. tmpChargingProfile = json_tokener_parse(buf);
  9911. if(!is_error(SetChargingProfile))
  9912. {
  9913. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  9914. {
  9915. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  9916. }
  9917. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  9918. {
  9919. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  9920. {
  9921. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  9922. }
  9923. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  9924. {
  9925. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  9926. }
  9927. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9928. {
  9929. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  9930. }
  9931. }
  9932. }
  9933. json_object_put(tmpChargingProfile);
  9934. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  9935. {
  9936. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9937. {
  9938. //DEBUG_INFO("update set chargingProfile to file -0\n");
  9939. if(ChargingProfileAdded == FALSE)
  9940. {
  9941. fprintf(outfile,"%s\n",payload);
  9942. ChargingProfileAdded = TRUE;
  9943. }
  9944. }
  9945. else
  9946. {
  9947. if(tempstackLevelInt < stackLevelInt)
  9948. {
  9949. if(ChargingProfileAdded == FALSE)
  9950. {
  9951. fprintf(outfile,"%s\n",buf);
  9952. fprintf(outfile,"%s\n",payload);
  9953. ChargingProfileAdded = TRUE;
  9954. }
  9955. else
  9956. {
  9957. fprintf(outfile,"%s\n",buf);
  9958. }
  9959. }
  9960. else
  9961. {
  9962. if(ChargingProfileAdded == FALSE)
  9963. {
  9964. fprintf(outfile,"%s\n",buf);
  9965. fprintf(outfile,"%s\n",payload);
  9966. ChargingProfileAdded = TRUE;
  9967. }
  9968. else
  9969. {
  9970. fprintf(outfile,"%s\n",buf);
  9971. }
  9972. }
  9973. }
  9974. }
  9975. else
  9976. {
  9977. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9978. {
  9979. if(ChargingProfileAdded == FALSE)
  9980. {
  9981. fprintf(outfile,"%s\n",buf);
  9982. fprintf(outfile,"%s\n",payload);
  9983. ChargingProfileAdded = TRUE;
  9984. }
  9985. else
  9986. {
  9987. fprintf(outfile,"%s\n",buf);
  9988. }
  9989. }
  9990. else if(tempstackLevelInt < stackLevelInt)
  9991. {
  9992. if(ChargingProfileAdded == FALSE)
  9993. {
  9994. fprintf(outfile,"%s\n",buf);
  9995. fprintf(outfile,"%s\n",payload);
  9996. ChargingProfileAdded = TRUE;
  9997. }
  9998. else
  9999. {
  10000. fprintf(outfile,"%s\n",buf);
  10001. }
  10002. }
  10003. else
  10004. {
  10005. if(ChargingProfileAdded == FALSE)
  10006. {
  10007. fprintf(outfile,"%s\n",buf);
  10008. fprintf(outfile,"%s\n",payload);
  10009. ChargingProfileAdded = TRUE;
  10010. }
  10011. else
  10012. {
  10013. fprintf(outfile,"%s\n",buf);
  10014. }
  10015. }
  10016. }
  10017. } // end of while loop
  10018. fclose(infile);
  10019. fclose(outfile);
  10020. sprintf(rmFileCmd,"rm -f %s",filename);
  10021. system(rmFileCmd);
  10022. rename(tempfile, filename);
  10023. }
  10024. sleep(1);
  10025. result = TRUE;
  10026. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  10027. end:
  10028. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  10029. {
  10030. if(connectorIdInt == 0)
  10031. {
  10032. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  10033. {
  10034. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  10035. }
  10036. }
  10037. else
  10038. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  10039. }
  10040. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  10041. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10042. return result;
  10043. }
  10044. int handleTriggerMessageRequest(char *uuid, char *payload)
  10045. {
  10046. mtrace();
  10047. int result = FAIL;
  10048. int connectorIdIsNULL = FALSE;
  10049. int connectorIdInt =0;
  10050. char sstr[40]={0},sstrtemp[100]={ 0 };
  10051. char requestedMessagestr[40]={0};
  10052. char comfirmstr[20]={0};
  10053. int c = 0;
  10054. char *loc;
  10055. DEBUG_INFO("handleTriggerMessageRequest\n");
  10056. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  10057. strcpy(sstrtemp, stringtrimspace(payload));
  10058. c = 0;
  10059. loc = strstr(sstrtemp, "requestedMessage");
  10060. while (loc[3+strlen("requestedMessage")+c] != '\"')
  10061. {
  10062. sstr[c] = loc[3+strlen("requestedMessage")+c];
  10063. c++;
  10064. }
  10065. sstr[c] = '\0';
  10066. strcpy(requestedMessagestr, sstr);
  10067. c = 0;
  10068. loc = strstr(sstrtemp, "connectorId");
  10069. if(loc == NULL)
  10070. {
  10071. connectorIdIsNULL = TRUE;
  10072. }
  10073. else
  10074. {
  10075. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10076. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  10077. {
  10078. sstr[c] = loc[strlen("connectorId")+2+c];
  10079. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10080. c++;
  10081. }
  10082. sstr[c] = '\0';
  10083. connectorIdInt = atoi(sstr);
  10084. }
  10085. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  10086. {
  10087. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  10088. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  10089. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  10090. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  10091. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  10092. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  10093. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  10094. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  10095. {
  10096. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  10097. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10098. return TRUE;
  10099. }
  10100. else
  10101. {
  10102. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  10103. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10104. }
  10105. }
  10106. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  10107. {
  10108. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  10109. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10110. return TRUE;
  10111. }
  10112. //==========================
  10113. // Trigger message
  10114. //==========================
  10115. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  10116. {
  10117. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  10118. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  10119. {
  10120. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  10121. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  10122. }
  10123. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10124. }
  10125. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  10126. {
  10127. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  10128. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10129. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10130. }
  10131. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  10132. {
  10133. //sendBootNotificationRequest();
  10134. server_sign = FALSE;
  10135. }
  10136. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  10137. {
  10138. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  10139. }
  10140. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  10141. {
  10142. if(connectorIdIsNULL == FALSE)
  10143. {
  10144. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  10145. {
  10146. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  10147. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  10148. }
  10149. }
  10150. else
  10151. {
  10152. for(int idx=0;idx< gunTotalNumber;idx++)
  10153. {
  10154. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  10155. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  10156. }
  10157. }
  10158. }
  10159. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  10160. {
  10161. if(connectorIdIsNULL == FALSE)
  10162. {
  10163. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  10164. {
  10165. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  10166. cpinitateMsg.bits[connectorIdInt -1].StatusNotificationReq = 1;
  10167. }
  10168. }
  10169. else
  10170. {
  10171. for(int idx=0;idx< gunTotalNumber;idx++)
  10172. {
  10173. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  10174. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  10175. }
  10176. }
  10177. }
  10178. return result;
  10179. }
  10180. int handleUnlockConnectorRequest(char *uuid, char *payload)
  10181. {
  10182. mtrace();
  10183. int result = FAIL;
  10184. int connectorIdInt =0;
  10185. char comfirmstr[20]={0};
  10186. int tempIndex = 0;
  10187. json_object *UnlockConnector;
  10188. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  10189. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  10190. UnlockConnector = json_tokener_parse(payload);
  10191. if(!is_error(UnlockConnector))
  10192. {
  10193. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  10194. {
  10195. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  10196. }
  10197. }
  10198. json_object_put(UnlockConnector);
  10199. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  10200. if(gunTotalNumber == 0)
  10201. {
  10202. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10203. goto end;
  10204. }
  10205. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  10206. {
  10207. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10208. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10209. goto end;
  10210. }
  10211. else
  10212. {
  10213. //check Transaction active
  10214. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  10215. {
  10216. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10217. {
  10218. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10219. }
  10220. else
  10221. {
  10222. tempIndex = connectorIdInt -1;
  10223. }
  10224. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10225. {
  10226. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10227. {
  10228. //stop Transaction
  10229. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10230. }
  10231. }
  10232. }
  10233. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  10234. {
  10235. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10236. {
  10237. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10238. }
  10239. else
  10240. {
  10241. tempIndex = connectorIdInt -1;
  10242. }
  10243. for (int index = 0; index < CCS_QUANTITY; index++)
  10244. {
  10245. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10246. {
  10247. //stop Transaction
  10248. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10249. }
  10250. }
  10251. }
  10252. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  10253. {
  10254. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10255. {
  10256. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10257. }
  10258. else
  10259. {
  10260. tempIndex = connectorIdInt -1;
  10261. }
  10262. for (int index = 0; index < GB_QUANTITY; index++)
  10263. {
  10264. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  10265. {
  10266. //stop Transaction
  10267. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10268. }
  10269. }
  10270. }
  10271. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  10272. {
  10273. tempIndex = connectorIdInt -1;
  10274. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10275. {
  10276. 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)))
  10277. {
  10278. //stop Transaction
  10279. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10280. }
  10281. }
  10282. }
  10283. else
  10284. {
  10285. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10286. {
  10287. tempIndex = 2;
  10288. }
  10289. else
  10290. {
  10291. tempIndex = connectorIdInt-1;
  10292. }
  10293. for (int index = 0; index < AC_QUANTITY; index++)
  10294. {
  10295. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10296. {
  10297. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10298. }
  10299. }
  10300. }
  10301. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  10302. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  10303. result = TRUE;
  10304. return result;
  10305. }
  10306. end:
  10307. //json_object_put(obj); --- remove temporally
  10308. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  10309. return result;
  10310. }
  10311. static char UpdateFirmwarepayloadData[300]={0};
  10312. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  10313. {
  10314. mtrace();
  10315. int result = FAIL;
  10316. pthread_t t;
  10317. sendUpdateFirmwareConfirmation(uuid);
  10318. memset(UpdateFirmwarepayloadData, 0, 300);
  10319. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  10320. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  10321. ////pthread_join(t, NULL); //
  10322. //pthread_detach(t);
  10323. //sendUpdateFirmwareConfirmation(uuid);
  10324. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  10325. return result;
  10326. }
  10327. void *UpdateFirmwareProcess(void *data)
  10328. {
  10329. pthread_detach(pthread_self());
  10330. mtrace();
  10331. int retriesInt =0, retryIntervalInt=0;
  10332. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  10333. int port=0;
  10334. char locationstr[512]={0}, retrieveDatestr[36]={0};
  10335. int isSuccess = 0;
  10336. char ftpbuf[512];
  10337. char temp[100];
  10338. char * pch;
  10339. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  10340. json_object *UpdateFirmware;
  10341. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  10342. if(!is_error(UpdateFirmware))
  10343. {
  10344. // Required data
  10345. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  10346. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  10347. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  10348. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  10349. // Optional data
  10350. if(json_object_object_get(UpdateFirmware, "retries"))
  10351. {
  10352. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  10353. }
  10354. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  10355. {
  10356. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  10357. }
  10358. }
  10359. json_object_put(UpdateFirmware);
  10360. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10361. memset(path, 0, ARRAY_SIZE(path));
  10362. // Wait retrieveData
  10363. if(strlen(retrieveDatestr) > 10)
  10364. {
  10365. do
  10366. {
  10367. sleep(1);
  10368. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  10369. }
  10370. // Ready to download
  10371. system("rm -f /mnt/*");
  10372. if(strncmp(locationstr,"http", 4) == 0)
  10373. {
  10374. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10375. sprintf(ftppath,"/%s", path);
  10376. DEBUG_INFO("locationstr: %s\n", locationstr);
  10377. DEBUG_INFO("protocol: %s\n",protocol);
  10378. DEBUG_INFO("host: %s\n",host);
  10379. DEBUG_INFO("path: %s\n",path);
  10380. DEBUG_INFO("ftppath: %s\n",ftppath);
  10381. int ftppathlen=strlen(ftppath);
  10382. int i=1;
  10383. char filenametemp[50];
  10384. while(i < ftppathlen)
  10385. {
  10386. int len=ftppathlen-i;
  10387. if(ftppath[len]== 47) // '/' ascll code: 47
  10388. {
  10389. DEBUG_INFO("compare '/' all right\n");
  10390. break;
  10391. }
  10392. i=i+1;
  10393. }
  10394. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10395. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10396. filenametemp[i+1] = 0;
  10397. do
  10398. {
  10399. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  10400. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10401. sleep(1);
  10402. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  10403. if(!isSuccess)
  10404. {
  10405. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10406. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10407. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  10408. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10409. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10410. }
  10411. else
  10412. {
  10413. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10414. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10415. }
  10416. retriesInt--;
  10417. }while((isSuccess == 0)&&(retriesInt >= 0));
  10418. }
  10419. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  10420. {
  10421. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  10422. memset(temp, 0, ARRAY_SIZE(temp));
  10423. //DEBUG_INFO("locationstr=%s\n",locationstr);
  10424. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  10425. int ftppathlen=strlen(ftpbuf);
  10426. int i=1;
  10427. char filenametemp[50];
  10428. while(i < ftppathlen)
  10429. {
  10430. int len=ftppathlen-i;
  10431. if(ftpbuf[len]== 47) // '/' ascll code: 47
  10432. {
  10433. DEBUG_INFO(" compare '/' all right\n");
  10434. break;
  10435. }
  10436. i=i+1;
  10437. }
  10438. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10439. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  10440. filenametemp[i+1] = 0;
  10441. strncpy(temp, ftpbuf, ftppathlen-i+1);
  10442. pch=strchr(temp,'@');
  10443. if(pch==NULL)
  10444. {
  10445. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10446. protocol, host, &port, path);
  10447. strcpy(user,"anonymous");
  10448. strcpy(password,"");
  10449. }
  10450. else
  10451. {
  10452. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10453. protocol, user, password, host, &port, path);
  10454. }
  10455. sscanf(host,"%[^/]%s",host1, path1);
  10456. sprintf(ftppath,"%s", path1);
  10457. //DEBUG_INFO("protocol =%s\n",protocol);
  10458. //DEBUG_INFO("user =%s\n",user);
  10459. //DEBUG_INFO("password =%s\n",password);
  10460. //DEBUG_INFO("host1 =%s\n",host1);
  10461. //DEBUG_INFO("port =%d\n",port);
  10462. //DEBUG_INFO("path1 =%s\n",path1);
  10463. //DEBUG_INFO("ftppath=%s\n",ftppath);
  10464. //ftpFile(host, user, password, port, ftppath, fname);
  10465. //download firmware pthred
  10466. if(port == 0)
  10467. {
  10468. port = 21;
  10469. }
  10470. do
  10471. {
  10472. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  10473. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10474. sleep(1);
  10475. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  10476. if(!isSuccess)
  10477. {
  10478. //BulldogUtil.sleepMs(interval*1000);
  10479. DEBUG_INFO("Update firmware request and download file fail.\n");
  10480. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10481. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10482. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  10483. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10484. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10485. }
  10486. else
  10487. {
  10488. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10489. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10490. }
  10491. retriesInt--;
  10492. }while((!isSuccess)&&(retriesInt >= 0));
  10493. }
  10494. else
  10495. {
  10496. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10497. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10498. sleep(1);
  10499. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10500. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10501. }
  10502. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  10503. pthread_exit(NULL);
  10504. }
  10505. int handleCertificateSignedRequest(char *uuid, char *payload)
  10506. {
  10507. mtrace();
  10508. int result = PASS;
  10509. json_object *CertificateSigned;
  10510. DEBUG_INFO("handleCertificateSignedRequest...\n");
  10511. CertificateSigned = json_tokener_parse(payload);
  10512. if(!is_error(CertificateSigned))
  10513. {
  10514. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  10515. }
  10516. json_object_put(CertificateSigned);
  10517. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  10518. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  10519. fclose(fp);
  10520. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10521. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  10522. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  10523. sendCertificateSignedConfirmation(uuid);
  10524. return result;
  10525. }
  10526. int handleDeleteCertificateRequest(char *uuid, char *payload)
  10527. {
  10528. mtrace();
  10529. int result = PASS;
  10530. json_object *DeleteCertificate;
  10531. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  10532. DeleteCertificate = json_tokener_parse(payload);
  10533. if(!is_error(DeleteCertificate))
  10534. {
  10535. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  10536. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  10537. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  10538. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  10539. }
  10540. json_object_put(DeleteCertificate);
  10541. /*
  10542. * TODO: Delete certificateSigned process
  10543. */
  10544. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  10545. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  10546. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  10547. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  10548. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  10549. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  10550. sendDeleteCertificateConfirmation(uuid);
  10551. return result;
  10552. }
  10553. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  10554. {
  10555. mtrace();
  10556. int result = PASS;
  10557. json_object *ExtendedTriggerMessage;
  10558. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  10559. ExtendedTriggerMessage = json_tokener_parse(payload);
  10560. if(!is_error(ExtendedTriggerMessage))
  10561. {
  10562. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  10563. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  10564. {
  10565. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  10566. }
  10567. else
  10568. {
  10569. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  10570. }
  10571. }
  10572. json_object_put(ExtendedTriggerMessage);
  10573. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  10574. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  10575. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  10576. {
  10577. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  10578. }
  10579. else
  10580. {
  10581. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  10582. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  10583. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  10584. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  10585. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  10586. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  10587. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  10588. {
  10589. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  10590. }
  10591. else
  10592. {
  10593. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  10594. }
  10595. }
  10596. sendExtendedTriggerMessageConfirmation(uuid);
  10597. //==========================
  10598. // Trigger message
  10599. //==========================
  10600. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  10601. {
  10602. //sendBootNotificationRequest();
  10603. server_sign = FALSE;
  10604. }
  10605. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  10606. {
  10607. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  10608. }
  10609. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  10610. {
  10611. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  10612. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  10613. {
  10614. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  10615. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  10616. }
  10617. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10618. }
  10619. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  10620. {
  10621. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  10622. }
  10623. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  10624. {
  10625. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  10626. {
  10627. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  10628. }
  10629. else
  10630. {
  10631. for(int idx=0;idx< gunTotalNumber;idx++)
  10632. {
  10633. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  10634. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  10635. }
  10636. }
  10637. }
  10638. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  10639. {
  10640. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  10641. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  10642. {
  10643. 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\" &");
  10644. }
  10645. }
  10646. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  10647. {
  10648. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  10649. {
  10650. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  10651. }
  10652. else
  10653. {
  10654. for(int idx=0;idx< gunTotalNumber;idx++)
  10655. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  10656. }
  10657. }
  10658. return result;
  10659. }
  10660. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  10661. {
  10662. mtrace();
  10663. int result = PASS;
  10664. json_object *GetInstalledCertificateIds;
  10665. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  10666. GetInstalledCertificateIds = json_tokener_parse(payload);
  10667. if(!is_error(GetInstalledCertificateIds))
  10668. {
  10669. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  10670. }
  10671. json_object_put(GetInstalledCertificateIds);
  10672. /*
  10673. * TODO: Return installed certificate process
  10674. */
  10675. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  10676. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  10677. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  10678. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  10679. sendGetInstalledCertificateIdsConfirmation(uuid);
  10680. return result;
  10681. }
  10682. int handleGetLogRequest(char *uuid, char *payload)
  10683. {
  10684. mtrace();
  10685. int result = PASS;
  10686. json_object *GetLog;
  10687. DEBUG_INFO("handleGetLogRequest...\n");
  10688. GetLog = json_tokener_parse(payload);
  10689. if(!is_error(GetLog))
  10690. {
  10691. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  10692. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  10693. if(json_object_object_get(GetLog, "retries") != NULL)
  10694. {
  10695. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  10696. }
  10697. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  10698. {
  10699. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  10700. }
  10701. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  10702. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  10703. {
  10704. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  10705. }
  10706. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  10707. {
  10708. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  10709. }
  10710. }
  10711. json_object_put(GetLog);
  10712. /*
  10713. * TODO: Upload log process
  10714. */
  10715. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  10716. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  10717. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  10718. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  10719. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  10720. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  10721. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  10722. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  10723. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  10724. sendGetLogConfirmation(uuid);
  10725. return result;
  10726. }
  10727. int handleInstallCertificateRequest(char *uuid, char *payload)
  10728. {
  10729. mtrace();
  10730. int result = PASS;
  10731. json_object *InstallCertificate;
  10732. DEBUG_INFO("handleInstallCertificateRequest...\n");
  10733. InstallCertificate = json_tokener_parse(payload);
  10734. if(!is_error(InstallCertificate))
  10735. {
  10736. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  10737. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  10738. /*
  10739. * TODO: Install certificate process
  10740. */
  10741. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  10742. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  10743. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  10744. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  10745. sendInstallCertificateConfirmation(uuid);
  10746. }
  10747. json_object_put(InstallCertificate);
  10748. return result;
  10749. }
  10750. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  10751. {
  10752. mtrace();
  10753. int result = PASS;
  10754. json_object *SignedUpdateFirmware;
  10755. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  10756. SignedUpdateFirmware = json_tokener_parse(payload);
  10757. if(!is_error(SignedUpdateFirmware))
  10758. {
  10759. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  10760. {
  10761. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  10762. }
  10763. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  10764. {
  10765. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  10766. }
  10767. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  10768. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  10769. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  10770. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  10771. {
  10772. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  10773. }
  10774. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  10775. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  10776. }
  10777. json_object_put(SignedUpdateFirmware);
  10778. /*
  10779. * TODO: Upgrade firmware process
  10780. */
  10781. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  10782. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  10783. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  10784. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  10785. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  10786. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  10787. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  10788. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  10789. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  10790. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  10791. sendInstallCertificateConfirmation(uuid);
  10792. return result;
  10793. }
  10794. int handleUnknownRequest(char *uuid, char *payload)
  10795. {
  10796. mtrace();
  10797. int result = PASS;
  10798. DEBUG_INFO("handleUnknownRequest...\n");
  10799. sendUnknownConfirmation(uuid);
  10800. result = PASS;
  10801. return result;
  10802. }
  10803. //==========================================
  10804. // Handle server response routine
  10805. //==========================================
  10806. void handleAuthorizeResponse(char *payload, int gun_index)
  10807. {
  10808. mtrace();
  10809. char expiryDatestr[30]={0};
  10810. char parentIdTagstr[20]={0};
  10811. char statusstr[20]={0};
  10812. int expiryDateISNULL=FALSE;
  10813. int parentIdTagISNULL=FALSE;
  10814. DEBUG_INFO("handleAuthorizeResponse...\n");
  10815. json_object *Authorize;
  10816. Authorize = json_tokener_parse(payload);
  10817. if(!is_error(Authorize))
  10818. {
  10819. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  10820. {
  10821. // Required data
  10822. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  10823. // Optional data
  10824. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  10825. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  10826. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  10827. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  10828. }
  10829. }
  10830. json_object_put(Authorize);
  10831. if(expiryDateISNULL == FALSE)
  10832. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  10833. if(parentIdTagISNULL == FALSE)
  10834. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  10835. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  10836. //Update idTag information to authorization cache if supproted
  10837. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  10838. {
  10839. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  10840. }
  10841. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  10842. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  10843. authorizeRetryTimes = 0;
  10844. }
  10845. void handleBootNotificationResponse(char *payload, int gun_index)
  10846. {
  10847. mtrace();
  10848. char statusStr[12]={0};
  10849. char currentTimeStr[30]={0};
  10850. int intervalInt = 0;
  10851. DEBUG_INFO("handleBootNotificationResponse...\n");
  10852. json_object *BootNotification;
  10853. BootNotification = json_tokener_parse(payload);
  10854. if(!is_error(BootNotification))
  10855. {
  10856. // Required data
  10857. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  10858. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  10859. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  10860. }
  10861. json_object_put(BootNotification);
  10862. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10863. BootNotificationInterval = intervalInt;
  10864. HeartBeatWaitTime = intervalInt;
  10865. //write back to ShmOCPP16Data->BootNotification
  10866. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  10867. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10868. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  10869. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  10870. {
  10871. server_sign = TRUE;
  10872. server_pending =FALSE;
  10873. }
  10874. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  10875. {
  10876. server_pending = TRUE;
  10877. }
  10878. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  10879. srand(time(NULL));
  10880. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  10881. SetOcppConnStatus(TRUE);
  10882. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  10883. }
  10884. void handleDataTransferResponse(char *payload, int gun_index)
  10885. {
  10886. char sstr[160]={0};//sstr[200]={ 0 };
  10887. int c = 0;
  10888. char *loc;
  10889. DEBUG_INFO("handleDataTransferResponse ...\n");
  10890. loc = strstr(payload, "status");
  10891. printf("loc=%s\n",loc);
  10892. c = 0;
  10893. while (loc[3+strlen("status")+c] != '\"')
  10894. {
  10895. sstr[c] = loc[3+strlen("status")+c];
  10896. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10897. c++;
  10898. }
  10899. sstr[c] = '\0';
  10900. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  10901. }
  10902. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  10903. {
  10904. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  10905. //struct json_object *obj;
  10906. // obj = json_tokener_parse(payload);
  10907. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  10908. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  10909. //No fields are defined.
  10910. }
  10911. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  10912. {
  10913. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  10914. //struct json_object *obj;
  10915. // obj = json_tokener_parse(payload);
  10916. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  10917. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  10918. //No fields are defined.
  10919. }
  10920. void handleHeartbeatResponse(char *payload, int gun_index)
  10921. {
  10922. mtrace();
  10923. DEBUG_INFO("handleHeartbeatResponse...\n");
  10924. json_object *Heartbeat;
  10925. Heartbeat = json_tokener_parse(payload);
  10926. if(!is_error(Heartbeat))
  10927. {
  10928. // Required data
  10929. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  10930. }
  10931. json_object_put(Heartbeat);
  10932. if(FirstHeartBeat == 0)
  10933. {
  10934. FirstHeartBeat = 1;
  10935. DEBUG_INFO("FirstHeartBeat \n");
  10936. }
  10937. HeartBeatWithNOResponse = 0;
  10938. clientTime.Heartbeat=time((time_t*)NULL);
  10939. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  10940. }
  10941. void handleMeterValuesResponse(char *payload, int gun_index)
  10942. {
  10943. mtrace();
  10944. DEBUG_INFO("handleMeterValuesResponse...\n");
  10945. }
  10946. void handleStartTransactionResponse(char *payload, int gun_index)
  10947. {
  10948. mtrace();
  10949. //int transactionIdInt = 0;
  10950. FILE *outfile;
  10951. char data[100]={0};
  10952. DEBUG_INFO("handleStartTransactionResponse...\n");
  10953. json_object *StartTransaction;
  10954. StartTransaction = json_tokener_parse(payload);
  10955. if(!is_error(StartTransaction))
  10956. {
  10957. // Required data
  10958. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  10959. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  10960. // Optional data
  10961. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  10962. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  10963. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  10964. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  10965. }
  10966. json_object_put(StartTransaction);
  10967. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  10968. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  10969. //-----------Start : write to the Queue TransactionId file -----------------//
  10970. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  10971. {}
  10972. else
  10973. {
  10974. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  10975. if(log == NULL)
  10976. {
  10977. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  10978. return ;
  10979. }
  10980. else
  10981. {
  10982. fclose(log);
  10983. }
  10984. }
  10985. // open file for writing
  10986. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  10987. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  10988. {
  10989. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  10990. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  10991. fputs(data, outfile);
  10992. fclose (outfile);
  10993. }
  10994. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10995. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10996. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  10997. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  10998. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10999. }
  11000. void handleStatusNotificationResponse(char *payload, int gun_index)
  11001. {
  11002. mtrace();
  11003. DEBUG_INFO("handleStatusNotificationResponse...\n");
  11004. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  11005. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  11006. }
  11007. void handleStopTransactionnResponse(char *payload, int gun_index)
  11008. {
  11009. mtrace();
  11010. DEBUG_INFO("handleStopTransactionnResponse...\n");
  11011. json_object *StopTransaction;
  11012. StopTransaction = json_tokener_parse(payload);
  11013. if(!is_error(StopTransaction))
  11014. {
  11015. // Optional data
  11016. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  11017. {
  11018. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  11019. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  11020. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  11021. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11022. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  11023. }
  11024. }
  11025. json_object_put(StopTransaction);
  11026. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  11027. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  11028. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11029. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11030. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  11031. }
  11032. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  11033. {
  11034. mtrace();
  11035. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  11036. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  11037. }
  11038. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  11039. {
  11040. mtrace();
  11041. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  11042. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  11043. }
  11044. void handleSignCertificateResponse(char *payload, int gun_index)
  11045. {
  11046. mtrace();
  11047. DEBUG_INFO("handleSignCertificateResponse...\n");
  11048. json_object *SignCertificate;
  11049. SignCertificate = json_tokener_parse(payload);
  11050. if(!is_error(SignCertificate))
  11051. {
  11052. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  11053. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  11054. }
  11055. json_object_put(SignCertificate);
  11056. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  11057. }
  11058. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11059. {
  11060. mtrace();
  11061. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  11062. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  11063. }
  11064. //==========================================
  11065. // Handle Error routine
  11066. //==========================================
  11067. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  11068. {
  11069. mtrace();
  11070. #ifdef SystemLogMessage
  11071. DEBUG_INFO("errorCode: %s\n", errorCode);
  11072. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  11073. DEBUG_INFO("errorDetails: %s\n", payload);
  11074. #endif
  11075. }
  11076. //===============================================
  11077. // Common routine
  11078. //===============================================
  11079. int initialConfigurationTable(void)
  11080. {
  11081. //clock_t start_t, end_t, total_t;
  11082. FILE *fp;
  11083. FILE *outfile;
  11084. char str[512]={0};
  11085. char sstr[256]={0};
  11086. int c = 0;
  11087. char *loc;
  11088. int confVersion = 2;
  11089. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  11090. //start_t = clock();
  11091. //printf("Starting of the program, start_t = %ld\n", start_t);
  11092. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  11093. // Check configuration file size is correct
  11094. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  11095. {
  11096. struct stat st;
  11097. stat("/Storage/OCPP/OCPPConfiguration", &st);
  11098. if(st.st_size < 3100)
  11099. {
  11100. system("rm -f /Storage/OCPP/OCPPConfiguration");
  11101. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  11102. }
  11103. }
  11104. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  11105. {
  11106. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  11107. if(outfile == NULL)
  11108. {
  11109. DEBUG_INFO("Error opening file\n");
  11110. return FALSE;
  11111. }
  11112. /*Core Profile*/
  11113. //AllowOfflineTxForUnknownId
  11114. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11115. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11116. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  11117. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11118. //AuthorizationCacheEnabled
  11119. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11120. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11121. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11122. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11123. //AuthorizeRemoteTxRequests
  11124. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11125. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11126. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  11127. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11128. //BlinkRepeat
  11129. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11130. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11131. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11132. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11133. //ClockAlignedDataInterval
  11134. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11135. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11136. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11137. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11138. //ConnectionTimeOut
  11139. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11140. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11141. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11142. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11143. //GetConfigurationMaxKeys
  11144. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11145. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11146. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  11147. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11148. // HeartbeatInterval
  11149. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11150. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11151. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  11152. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11153. // LightIntensity
  11154. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11155. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11156. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11157. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11158. // LocalAuthorizeOffline
  11159. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  11160. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  11161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  11162. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11163. // LocalPreAuthorize
  11164. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  11165. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  11166. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  11167. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  11168. // MaxEnergyOnInvalidId
  11169. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  11170. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  11171. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  11172. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  11173. // MeterValuesAlignedData
  11174. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  11175. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  11176. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11177. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11178. else
  11179. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11180. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  11181. // MeterValuesAlignedDataMaxLength
  11182. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  11183. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  11184. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11185. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  11186. else
  11187. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "9" );
  11188. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  11189. // MeterValuesSampledData
  11190. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  11191. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  11192. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11193. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11194. else
  11195. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11196. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  11197. // MeterValuesSampledDataMaxLength
  11198. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  11199. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  11200. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11201. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  11202. else
  11203. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "9" );
  11204. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  11205. // MeterValueSampleInterval
  11206. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  11207. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  11208. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  11209. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  11210. // MinimumStatusDuration
  11211. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  11212. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  11213. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  11214. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  11215. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  11216. // NumberOfConnectors
  11217. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  11218. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  11219. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11220. {
  11221. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  11222. }
  11223. else
  11224. {
  11225. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  11226. }
  11227. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  11228. // ResetRetries
  11229. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  11230. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  11231. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  11232. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  11233. // ConnectorPhaseRotation
  11234. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  11235. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  11236. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  11237. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  11238. // ConnectorPhaseRotationMaxLength
  11239. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  11240. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  11241. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  11242. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  11243. // StopTransactionOnEVSideDisconnect
  11244. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  11245. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  11246. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  11247. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  11248. // StopTransactionOnInvalidId
  11249. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  11250. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  11251. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  11252. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  11253. // StopTxnAlignedData
  11254. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  11255. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  11256. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  11257. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  11258. // StopTxnAlignedDataMaxLength
  11259. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  11260. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  11261. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  11262. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  11263. // StopTxnSampledData
  11264. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  11265. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  11266. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11267. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11268. else
  11269. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11270. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  11271. // StopTxnSampledDataMaxLength
  11272. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  11273. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  11274. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11275. {
  11276. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  11277. }
  11278. else
  11279. {
  11280. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  11281. }
  11282. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  11283. // SupportedFeatureProfiles
  11284. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  11285. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  11286. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  11287. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  11288. // SupportedFeatureProfilesMaxLength
  11289. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  11290. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  11291. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  11292. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  11293. // TransactionMessageAttempts
  11294. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  11295. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  11296. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  11297. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11298. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11299. // TransactionMessageRetryInterval
  11300. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  11301. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  11302. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  11303. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11304. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11305. // UnlockConnectorOnEVSideDisconnect
  11306. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  11307. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  11308. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  11309. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  11310. // WebSocketPingInterval
  11311. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  11312. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  11313. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  11314. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  11315. // QueueOffLineStartTransactionMessage
  11316. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  11317. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  11318. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  11319. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  11320. // AuthorizationKey
  11321. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  11322. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  11323. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "" );
  11324. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  11325. // SecurityProfile
  11326. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  11327. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  11328. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "0" );
  11329. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  11330. // DefaultPrice
  11331. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  11332. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  11333. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  11334. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  11335. // CustomDisplayCostAndPrice
  11336. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  11337. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  11338. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  11339. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  11340. // CustomIdleFeeAfterStop
  11341. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  11342. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  11343. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  11344. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  11345. // Configuration Version
  11346. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  11347. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  11348. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  11349. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  11350. //* Local Auth List Management Profile*/
  11351. #if 0
  11352. //For OCTT Test Case
  11353. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11354. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  11355. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11356. #endif
  11357. #if 1
  11358. //LocalAuthListEnabled
  11359. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11360. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  11361. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11362. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11363. #endif
  11364. //LocalAuthListMaxLength
  11365. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  11366. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  11367. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  11368. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  11369. //SendLocalListMaxLength
  11370. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  11371. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  11372. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  11373. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  11374. //ReserveConnectorZeroSupported
  11375. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  11376. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  11377. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  11378. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11379. //* Smart Charging Profile */
  11380. //ChargeProfileMaxStackLevel
  11381. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  11382. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  11383. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  11384. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11385. // ChargingScheduleAllowedChargingRateUnit
  11386. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  11387. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  11388. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  11389. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11390. // ChargingScheduleMaxPeriods
  11391. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  11392. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  11393. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  11394. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11395. // ConnectorSwitch3to1PhaseSupported
  11396. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11397. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11398. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  11399. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11400. // MaxChargingProfilesInstalled
  11401. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11402. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11403. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  11404. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11405. fclose(outfile);
  11406. }
  11407. else
  11408. {
  11409. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  11410. char keystr[60]={0};
  11411. char readonlystr[10]={0};
  11412. char valuestr[256]={0};
  11413. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  11414. if(fp == NULL) {
  11415. DEBUG_INFO("Error opening file");
  11416. return FALSE;
  11417. }
  11418. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  11419. {
  11420. //DEBUG_INFO("Get Configuration \n");
  11421. if(strlen(str) > 0)
  11422. {
  11423. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  11424. //*************************key*********************************/
  11425. if(strstr(str, "key") != NULL)
  11426. {
  11427. loc = strstr(str, "key");
  11428. c = 0;
  11429. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11430. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  11431. {
  11432. sstr[c] = loc[strlen("key")+3+c];
  11433. c++;
  11434. }
  11435. sstr[c] = '\0';
  11436. strcpy(keystr,sstr);
  11437. }
  11438. //*************************readonly*********************************/
  11439. if(strstr(str, "readonly") != NULL)
  11440. {
  11441. loc = strstr(str, "readonly");
  11442. c = 0;
  11443. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11444. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  11445. {
  11446. sstr[c] = loc[strlen("readonly")+2+c];
  11447. c++;
  11448. }
  11449. sstr[c] = '\0';
  11450. strcpy(readonlystr,sstr);
  11451. }
  11452. //*************************value*********************************/
  11453. if(strstr(str, "value") != NULL)
  11454. {
  11455. loc = strstr(str, "value");
  11456. c = 0;
  11457. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11458. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  11459. {
  11460. sstr[c] = loc[strlen("value")+3+c];
  11461. c++;
  11462. }
  11463. sstr[c] = '\0';
  11464. strcpy(valuestr,sstr);
  11465. }
  11466. // DEBUG_INFO("keystr=%s\n",keystr);
  11467. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  11468. // DEBUG_INFO("valuestr=%s\n",valuestr);
  11469. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  11470. {
  11471. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11472. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11473. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  11474. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  11475. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  11476. }
  11477. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  11478. {
  11479. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11480. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11481. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  11482. }
  11483. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  11484. {
  11485. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11486. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  11487. }
  11488. if(strcmp(keystr, "BlinkRepeat") == 0)
  11489. {
  11490. //Charger.BlinkRepeat = Integer.parseInt(value);
  11491. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11492. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  11493. }
  11494. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  11495. {
  11496. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11497. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  11498. }
  11499. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  11500. {
  11501. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11502. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  11503. }
  11504. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  11505. {
  11506. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11507. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  11508. }
  11509. if(strcmp(keystr, "HeartbeatInterval") == 0)
  11510. {
  11511. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11512. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  11513. HeartBeatWaitTime = atoi(valuestr);
  11514. }
  11515. if(strcmp(keystr, "LightIntensity") == 0)
  11516. {
  11517. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11518. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  11519. }
  11520. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  11521. {
  11522. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11523. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  11524. }
  11525. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  11526. {
  11527. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11528. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  11529. }
  11530. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  11531. {
  11532. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11533. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  11534. }
  11535. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  11536. {
  11537. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11538. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  11539. }
  11540. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  11541. {
  11542. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11543. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  11544. }
  11545. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  11546. {
  11547. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11548. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  11549. }
  11550. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  11551. {
  11552. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11553. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  11554. }
  11555. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  11556. {
  11557. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11558. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  11559. }
  11560. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  11561. {
  11562. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11563. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  11564. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  11565. }
  11566. if(strcmp(keystr, "NumberOfConnectors") == 0)
  11567. {
  11568. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11569. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  11570. }
  11571. if(strcmp(keystr, "ResetRetries") == 0)
  11572. {
  11573. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11574. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  11575. }
  11576. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  11577. {
  11578. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11579. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  11580. }
  11581. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  11582. {
  11583. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11584. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  11585. }
  11586. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  11587. {
  11588. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11589. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  11590. }
  11591. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  11592. {
  11593. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11594. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  11595. }
  11596. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  11597. {
  11598. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11599. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  11600. }
  11601. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  11602. {
  11603. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11604. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  11605. }
  11606. if(strcmp(keystr, "StopTxnSampledData") == 0)
  11607. {
  11608. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11609. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  11610. }
  11611. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  11612. {
  11613. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11614. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  11615. }
  11616. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  11617. {
  11618. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11619. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  11620. }
  11621. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  11622. {
  11623. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11624. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  11625. }
  11626. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  11627. {
  11628. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11629. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  11630. TransactionMessageAttemptsValue = atoi(valuestr);
  11631. }
  11632. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  11633. {
  11634. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11635. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  11636. TransactionMessageRetryIntervalValue = atoi(valuestr);
  11637. }
  11638. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  11639. {
  11640. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11641. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  11642. }
  11643. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  11644. {
  11645. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11646. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  11647. }
  11648. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  11649. {
  11650. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11651. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  11652. }
  11653. if(strcmp(keystr, "AuthorizationKey") == 0)
  11654. {
  11655. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11656. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  11657. }
  11658. if(strcmp(keystr, "SecurityProfile") == 0)
  11659. {
  11660. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11661. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  11662. }
  11663. if(strcmp(keystr, "DefaultPrice") == 0)
  11664. {
  11665. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11666. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  11667. }
  11668. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  11669. {
  11670. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11671. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  11672. }
  11673. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  11674. {
  11675. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11676. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  11677. }
  11678. if(strcmp(keystr, "ConfigurationVersion") == 0)
  11679. {
  11680. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11681. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  11682. }
  11683. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  11684. {
  11685. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11686. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  11687. }
  11688. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  11689. {
  11690. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11691. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  11692. }
  11693. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  11694. {
  11695. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11696. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  11697. }
  11698. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  11699. {
  11700. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11701. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  11702. }
  11703. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  11704. {
  11705. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11706. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  11707. }
  11708. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  11709. {
  11710. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11711. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  11712. }
  11713. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  11714. {
  11715. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11716. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  11717. }
  11718. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  11719. {
  11720. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11721. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  11722. }
  11723. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  11724. {
  11725. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11726. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  11727. }
  11728. }
  11729. }
  11730. fclose(fp);
  11731. }
  11732. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  11733. {
  11734. return PASS;
  11735. }
  11736. else
  11737. {
  11738. return FAIL;
  11739. }
  11740. }
  11741. void StoreConfigurationTable(void)
  11742. {
  11743. FILE *outfile;
  11744. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  11745. if(outfile == NULL)
  11746. {
  11747. DEBUG_INFO("Error opening file");
  11748. return ;
  11749. }
  11750. /*Core Profile*/
  11751. //AllowOfflineTxForUnknownId
  11752. /*
  11753. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11754. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  11755. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11756. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  11757. */
  11758. //DEBUG_INFO("data=%s\n",data);
  11759. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11760. //AuthorizationCacheEnabled
  11761. /*
  11762. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11763. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11764. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11765. */
  11766. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11767. //AuthorizeRemoteTxRequests
  11768. /*
  11769. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11770. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11771. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  11772. */
  11773. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11774. //BlinkRepeat
  11775. /*
  11776. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11777. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11778. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11779. */
  11780. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11781. //ClockAlignedDataInterval
  11782. /*
  11783. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11784. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11785. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11786. */
  11787. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11788. //ConnectionTimeOut
  11789. /*
  11790. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11791. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11792. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11793. */
  11794. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11795. //GetConfigurationMaxKeys
  11796. /*
  11797. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11798. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11799. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  11800. */
  11801. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11802. // HeartbeatInterval
  11803. /*
  11804. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11805. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11806. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  11807. */
  11808. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11809. // LightIntensity
  11810. /*
  11811. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11812. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11813. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11814. */
  11815. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11816. // LocalAuthorizeOffline
  11817. /*
  11818. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  11819. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  11820. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  11821. */
  11822. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11823. // LocalPreAuthorize
  11824. /*
  11825. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  11826. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  11827. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  11828. */
  11829. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  11830. // MaxEnergyOnInvalidId
  11831. /*
  11832. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  11833. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  11834. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  11835. */
  11836. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  11837. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  11838. // MeterValuesAlignedData
  11839. /*
  11840. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  11841. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  11842. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  11843. */
  11844. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  11845. // MeterValuesAlignedDataMaxLength
  11846. /*
  11847. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  11848. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  11849. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  11850. */
  11851. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  11852. // MeterValuesSampledData
  11853. /*
  11854. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  11855. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  11856. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  11857. */
  11858. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  11859. // MeterValuesSampledDataMaxLength
  11860. /*
  11861. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  11862. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  11863. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  11864. */
  11865. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  11866. // MeterValueSampleInterval
  11867. /*
  11868. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  11869. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  11870. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  11871. */
  11872. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  11873. // MinimumStatusDuration
  11874. /*
  11875. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  11876. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  11877. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  11878. */
  11879. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  11880. // NumberOfConnectors
  11881. /*
  11882. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  11883. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  11884. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11885. {
  11886. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  11887. }
  11888. else
  11889. {
  11890. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  11891. }
  11892. */
  11893. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  11894. // ResetRetries
  11895. /*
  11896. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  11897. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  11898. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  11899. */
  11900. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  11901. // ConnectorPhaseRotation
  11902. /*
  11903. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  11904. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  11905. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  11906. */
  11907. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  11908. // ConnectorPhaseRotationMaxLength
  11909. /*
  11910. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  11911. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  11912. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  11913. */
  11914. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  11915. // StopTransactionOnEVSideDisconnect
  11916. /*
  11917. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  11918. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  11919. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  11920. */
  11921. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  11922. // StopTransactionOnInvalidId
  11923. /*
  11924. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  11925. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  11926. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  11927. */
  11928. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  11929. // StopTxnAlignedData
  11930. /*
  11931. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  11932. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  11933. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  11934. */
  11935. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  11936. // StopTxnAlignedDataMaxLength
  11937. /*
  11938. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  11939. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  11940. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  11941. */
  11942. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  11943. // StopTxnSampledData
  11944. /*
  11945. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  11946. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  11947. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  11948. */
  11949. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  11950. // StopTxnSampledDataMaxLength
  11951. /*
  11952. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  11953. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  11954. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  11955. */
  11956. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  11957. // SupportedFeatureProfiles
  11958. /*
  11959. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  11960. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  11961. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  11962. */
  11963. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  11964. // SupportedFeatureProfilesMaxLength
  11965. /*
  11966. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  11967. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  11968. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  11969. */
  11970. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  11971. // TransactionMessageAttempts
  11972. /*
  11973. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  11974. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  11975. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  11976. */
  11977. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11978. // TransactionMessageRetryInterval
  11979. /*
  11980. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  11981. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  11982. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  11983. */
  11984. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11985. // UnlockConnectorOnEVSideDisconnect
  11986. /*
  11987. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  11988. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  11989. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  11990. */
  11991. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  11992. // WebSocketPingInterval
  11993. /*
  11994. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  11995. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  11996. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  11997. */
  11998. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  11999. // QueueOffLineStartTransactionMessage
  12000. /*
  12001. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  12002. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  12003. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  12004. */
  12005. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  12006. // AuthorizationKey
  12007. /*
  12008. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12009. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12010. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  12011. */
  12012. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12013. // SecurityProfile
  12014. /*
  12015. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12016. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12017. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  12018. */
  12019. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12020. // DefaultPrice
  12021. /*
  12022. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12023. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12024. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12025. */
  12026. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12027. // CustomDisplayCostAndPrice
  12028. /*
  12029. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12030. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12031. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12032. */
  12033. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12034. // CustomIdleFeeAfterStop
  12035. /*
  12036. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12037. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12038. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12039. */
  12040. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12041. // ConfigurationVersion
  12042. /*
  12043. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  12044. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12045. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  12046. */
  12047. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12048. //* Local Auth List Management Profile*/
  12049. //LocalAuthListEnabled
  12050. /*
  12051. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12052. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12053. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12054. */
  12055. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12056. //LocalAuthListMaxLength
  12057. /*
  12058. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12059. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12060. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  12061. */
  12062. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12063. //SendLocalListMaxLength
  12064. /*
  12065. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12066. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12067. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  12068. */
  12069. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12070. //ReserveConnectorZeroSupported
  12071. /*
  12072. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12073. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12074. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12075. */
  12076. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12077. //* Smart Charging Profile */
  12078. //ChargeProfileMaxStackLevel
  12079. /*
  12080. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12081. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12082. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12083. */
  12084. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12085. // ChargingScheduleAllowedChargingRateUnit
  12086. /*
  12087. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12088. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12089. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  12090. */
  12091. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12092. // ChargingScheduleMaxPeriods
  12093. /*
  12094. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12095. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12096. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12097. */
  12098. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12099. // ConnectorSwitch3to1PhaseSupported
  12100. /*
  12101. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  12102. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  12103. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  12104. */
  12105. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12106. // MaxChargingProfilesInstalled
  12107. /*
  12108. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  12109. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  12110. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  12111. */
  12112. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12113. fclose(outfile);
  12114. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12115. }
  12116. void getKeyValue(char *keyReq)
  12117. {
  12118. int isEmpty = FALSE;
  12119. int isKnowKey = FALSE;
  12120. DEBUG_INFO("keyReq = %s\n", keyReq);
  12121. if((keyReq == NULL) || (strlen(keyReq) == 0))
  12122. isEmpty = TRUE;
  12123. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  12124. {
  12125. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  12126. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  12127. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  12128. {
  12129. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  12130. }
  12131. else
  12132. {
  12133. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  12134. }
  12135. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  12136. isKnowKey = TRUE;
  12137. }
  12138. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  12139. {
  12140. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  12141. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  12142. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  12143. {
  12144. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  12145. }
  12146. else
  12147. {
  12148. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  12149. }
  12150. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  12151. isKnowKey = TRUE;
  12152. }
  12153. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  12154. {
  12155. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  12156. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  12157. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  12158. {
  12159. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  12160. }
  12161. else
  12162. {
  12163. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  12164. }
  12165. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  12166. isKnowKey = TRUE;
  12167. }
  12168. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  12169. {
  12170. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  12171. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  12172. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  12173. {
  12174. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  12175. }
  12176. else
  12177. {
  12178. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  12179. }
  12180. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  12181. isKnowKey = TRUE;
  12182. }
  12183. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  12184. {
  12185. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  12186. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  12187. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  12188. {
  12189. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  12190. }
  12191. else
  12192. {
  12193. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  12194. }
  12195. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  12196. isKnowKey = TRUE;
  12197. }
  12198. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  12199. {
  12200. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  12201. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  12202. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  12203. {
  12204. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  12205. }
  12206. else
  12207. {
  12208. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  12209. }
  12210. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  12211. isKnowKey = TRUE;
  12212. }
  12213. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  12214. {
  12215. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  12216. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  12217. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  12218. {
  12219. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  12220. }
  12221. else
  12222. {
  12223. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  12224. }
  12225. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  12226. isKnowKey = TRUE;
  12227. }
  12228. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  12229. {
  12230. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  12231. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  12232. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  12233. {
  12234. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  12235. }
  12236. else
  12237. {
  12238. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  12239. }
  12240. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  12241. isKnowKey = TRUE;
  12242. }
  12243. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  12244. {
  12245. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  12246. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  12247. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  12248. {
  12249. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  12250. }
  12251. else
  12252. {
  12253. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  12254. }
  12255. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  12256. isKnowKey = TRUE;
  12257. }
  12258. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  12259. {
  12260. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  12261. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  12262. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  12263. {
  12264. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  12265. }
  12266. else
  12267. {
  12268. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  12269. }
  12270. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  12271. isKnowKey = TRUE;
  12272. }
  12273. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  12274. {
  12275. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  12276. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  12277. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  12278. {
  12279. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  12280. }
  12281. else
  12282. {
  12283. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  12284. }
  12285. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  12286. isKnowKey = TRUE;
  12287. }
  12288. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  12289. {
  12290. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  12291. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  12292. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  12293. {
  12294. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  12295. }
  12296. else
  12297. {
  12298. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  12299. }
  12300. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  12301. isKnowKey = TRUE;
  12302. }
  12303. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  12304. {
  12305. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  12306. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  12307. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  12308. {
  12309. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  12310. }
  12311. else
  12312. {
  12313. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  12314. }
  12315. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  12316. isKnowKey = TRUE;
  12317. }
  12318. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  12319. {
  12320. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  12321. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  12322. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  12323. {
  12324. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12325. }
  12326. else
  12327. {
  12328. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12329. }
  12330. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  12331. isKnowKey = TRUE;
  12332. }
  12333. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  12334. {
  12335. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  12336. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  12337. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  12338. {
  12339. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  12340. }
  12341. else
  12342. {
  12343. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  12344. }
  12345. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  12346. isKnowKey = TRUE;
  12347. }
  12348. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  12349. {
  12350. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  12351. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  12352. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  12353. {
  12354. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12355. }
  12356. else
  12357. {
  12358. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12359. }
  12360. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  12361. isKnowKey = TRUE;
  12362. }
  12363. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  12364. {
  12365. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  12366. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  12367. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12368. {
  12369. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  12370. }
  12371. else
  12372. {
  12373. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  12374. }
  12375. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  12376. isKnowKey = TRUE;
  12377. }
  12378. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  12379. {
  12380. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  12381. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  12382. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12383. {
  12384. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  12385. }
  12386. else
  12387. {
  12388. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  12389. }
  12390. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  12391. isKnowKey = TRUE;
  12392. }
  12393. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  12394. {
  12395. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  12396. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  12397. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12398. {
  12399. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  12400. }
  12401. else
  12402. {
  12403. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  12404. }
  12405. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  12406. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  12407. isKnowKey = TRUE;
  12408. }
  12409. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  12410. {
  12411. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  12412. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  12413. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12414. {
  12415. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  12416. }
  12417. else
  12418. {
  12419. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  12420. }
  12421. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  12422. isKnowKey = TRUE;
  12423. }
  12424. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  12425. {
  12426. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  12427. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  12428. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12429. {
  12430. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  12431. }
  12432. else
  12433. {
  12434. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  12435. }
  12436. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  12437. isKnowKey = TRUE;
  12438. }
  12439. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  12440. {
  12441. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  12442. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  12443. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12444. {
  12445. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12446. }
  12447. else
  12448. {
  12449. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12450. }
  12451. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  12452. isKnowKey = TRUE;
  12453. }
  12454. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  12455. {
  12456. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  12457. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  12458. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12459. {
  12460. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  12461. }
  12462. else
  12463. {
  12464. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  12465. }
  12466. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  12467. isKnowKey = TRUE;
  12468. }
  12469. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  12470. {
  12471. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  12472. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  12473. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12474. {
  12475. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  12476. }
  12477. else
  12478. {
  12479. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  12480. }
  12481. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  12482. isKnowKey = TRUE;
  12483. }
  12484. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  12485. {
  12486. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  12487. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  12488. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12489. {
  12490. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  12491. }
  12492. else
  12493. {
  12494. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  12495. }
  12496. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  12497. isKnowKey = TRUE;
  12498. }
  12499. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  12500. {
  12501. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  12502. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  12503. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12504. {
  12505. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12506. }
  12507. else
  12508. {
  12509. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12510. }
  12511. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  12512. isKnowKey = TRUE;
  12513. }
  12514. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  12515. {
  12516. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  12517. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  12518. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12519. {
  12520. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  12521. }
  12522. else
  12523. {
  12524. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  12525. }
  12526. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  12527. isKnowKey = TRUE;
  12528. }
  12529. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  12530. {
  12531. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  12532. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  12533. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12534. {
  12535. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12536. }
  12537. else
  12538. {
  12539. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12540. }
  12541. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  12542. isKnowKey = TRUE;
  12543. }
  12544. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  12545. {
  12546. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  12547. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  12548. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12549. {
  12550. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  12551. }
  12552. else
  12553. {
  12554. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  12555. }
  12556. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  12557. isKnowKey = TRUE;
  12558. }
  12559. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  12560. {
  12561. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  12562. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  12563. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12564. {
  12565. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12566. }
  12567. else
  12568. {
  12569. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12570. }
  12571. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  12572. isKnowKey = TRUE;
  12573. }
  12574. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  12575. {
  12576. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  12577. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  12578. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12579. {
  12580. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  12581. }
  12582. else
  12583. {
  12584. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  12585. }
  12586. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  12587. isKnowKey = TRUE;
  12588. }
  12589. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  12590. {
  12591. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  12592. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  12593. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12594. {
  12595. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  12596. }
  12597. else
  12598. {
  12599. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  12600. }
  12601. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  12602. isKnowKey = TRUE;
  12603. }
  12604. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  12605. {
  12606. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  12607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  12608. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12609. {
  12610. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  12611. }
  12612. else
  12613. {
  12614. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  12615. }
  12616. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  12617. isKnowKey = TRUE;
  12618. }
  12619. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  12620. {
  12621. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  12622. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  12623. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12624. {
  12625. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  12626. }
  12627. else
  12628. {
  12629. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  12630. }
  12631. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  12632. isKnowKey = TRUE;
  12633. }
  12634. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  12635. {
  12636. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  12637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  12638. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12639. {
  12640. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  12641. }
  12642. else
  12643. {
  12644. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  12645. }
  12646. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  12647. isKnowKey = TRUE;
  12648. }
  12649. /*
  12650. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  12651. {
  12652. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  12653. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  12654. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  12655. {
  12656. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  12657. }
  12658. else
  12659. {
  12660. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  12661. }
  12662. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  12663. isKnowKey = TRUE;
  12664. }*/
  12665. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  12666. {
  12667. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  12668. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  12669. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  12670. {
  12671. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  12672. }
  12673. else
  12674. {
  12675. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  12676. }
  12677. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  12678. isKnowKey = TRUE;
  12679. }
  12680. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  12681. {
  12682. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  12683. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  12684. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  12685. {
  12686. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  12687. }
  12688. else
  12689. {
  12690. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  12691. }
  12692. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  12693. isKnowKey = TRUE;
  12694. }
  12695. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  12696. {
  12697. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  12698. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  12699. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  12700. {
  12701. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  12702. }
  12703. else
  12704. {
  12705. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  12706. }
  12707. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  12708. isKnowKey = TRUE;
  12709. }
  12710. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  12711. {
  12712. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  12713. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  12714. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  12715. {
  12716. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  12717. }
  12718. else
  12719. {
  12720. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  12721. }
  12722. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  12723. isKnowKey = TRUE;
  12724. }
  12725. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  12726. {
  12727. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  12728. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  12729. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  12730. {
  12731. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  12732. }
  12733. else
  12734. {
  12735. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  12736. }
  12737. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  12738. isKnowKey = TRUE;
  12739. }
  12740. #if 1
  12741. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  12742. {
  12743. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  12744. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  12745. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12746. {
  12747. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  12748. }
  12749. else
  12750. {
  12751. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  12752. }
  12753. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  12754. isKnowKey = TRUE;
  12755. }
  12756. #endif
  12757. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  12758. {
  12759. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  12760. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  12761. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12762. {
  12763. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12764. }
  12765. else
  12766. {
  12767. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12768. }
  12769. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  12770. isKnowKey = TRUE;
  12771. }
  12772. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  12773. {
  12774. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  12775. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  12776. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12777. {
  12778. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12779. }
  12780. else
  12781. {
  12782. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12783. }
  12784. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  12785. isKnowKey = TRUE;
  12786. }
  12787. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  12788. {
  12789. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  12790. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  12791. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12792. {
  12793. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  12794. }
  12795. else
  12796. {
  12797. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  12798. }
  12799. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12800. isKnowKey = TRUE;
  12801. }
  12802. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  12803. {
  12804. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  12805. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  12806. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12807. {
  12808. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  12809. }
  12810. else
  12811. {
  12812. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  12813. }
  12814. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12815. isKnowKey = TRUE;
  12816. }
  12817. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  12818. {
  12819. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  12820. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  12821. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12822. {
  12823. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  12824. }
  12825. else
  12826. {
  12827. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  12828. }
  12829. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12830. isKnowKey = TRUE;
  12831. }
  12832. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  12833. {
  12834. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  12835. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  12836. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12837. {
  12838. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  12839. }
  12840. else
  12841. {
  12842. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  12843. }
  12844. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12845. isKnowKey = TRUE;
  12846. }
  12847. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  12848. {
  12849. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  12850. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  12851. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12852. {
  12853. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  12854. }
  12855. else
  12856. {
  12857. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  12858. }
  12859. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12860. isKnowKey = TRUE;
  12861. }
  12862. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  12863. {
  12864. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  12865. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  12866. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12867. {
  12868. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  12869. }
  12870. else
  12871. {
  12872. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  12873. }
  12874. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12875. isKnowKey = TRUE;
  12876. }
  12877. //=========================================================
  12878. if(!isEmpty && !isKnowKey)
  12879. {
  12880. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  12881. strcpy(unknownkey[UnknownKeynum], keyReq);
  12882. UnknownKeynum = UnknownKeynum + 1;
  12883. }
  12884. }
  12885. void processUnkownKey(void)
  12886. {
  12887. DEBUG_INFO("processUnkownKey...\n");
  12888. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  12889. for(int index=0; index < UnknownKeynum; index++)
  12890. {
  12891. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  12892. {
  12893. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  12894. }
  12895. }
  12896. }
  12897. int setKeyValue(char *key, char *value)
  12898. {
  12899. int isSuccess = NotSupported;
  12900. int check_ascii=0;
  12901. char str[256]={0};
  12902. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  12903. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  12904. {
  12905. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  12906. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  12907. {
  12908. strcpy(str, (const char*)value);
  12909. for(int i = 0; str[i]; i++){
  12910. str[i] = tolower(str[i]);
  12911. }
  12912. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12913. isSuccess = ConfigurationStatus_Accepted;
  12914. }
  12915. else
  12916. {
  12917. isSuccess = ConfigurationStatus_Rejected;
  12918. }
  12919. }
  12920. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  12921. {
  12922. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  12923. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  12924. {
  12925. strcpy(str, (const char*)value);
  12926. for(int i = 0; str[i]; i++){
  12927. str[i] = tolower(str[i]);
  12928. }
  12929. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12930. isSuccess = ConfigurationStatus_Accepted;
  12931. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  12932. }
  12933. else
  12934. {
  12935. isSuccess = ConfigurationStatus_Rejected;
  12936. }
  12937. }
  12938. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  12939. {
  12940. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  12941. {
  12942. strcpy(str, (const char*)value);
  12943. for(int i = 0; str[i]; i++)
  12944. {
  12945. str[i] = tolower(str[i]);
  12946. }
  12947. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  12948. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12949. isSuccess = ConfigurationStatus_Accepted;
  12950. }
  12951. else
  12952. {
  12953. isSuccess = ConfigurationStatus_Rejected;
  12954. }
  12955. }
  12956. if(strcmp(key, "BlinkRepeat") == 0)
  12957. {
  12958. //Charger.BlinkRepeat = Integer.parseInt(value);
  12959. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  12960. {
  12961. check_ascii = value[0];
  12962. if( (check_ascii < 48) || (check_ascii > 57) )
  12963. {
  12964. isSuccess = ConfigurationStatus_Rejected;
  12965. }
  12966. else
  12967. {
  12968. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  12969. isSuccess = ConfigurationStatus_Accepted;
  12970. }
  12971. }
  12972. else
  12973. {
  12974. isSuccess = ConfigurationStatus_Rejected;
  12975. }
  12976. }
  12977. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  12978. {
  12979. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  12980. {
  12981. check_ascii = value[0];
  12982. if( (check_ascii < 48) || (check_ascii > 57) )
  12983. {
  12984. isSuccess = ConfigurationStatus_Rejected;
  12985. }
  12986. else
  12987. {
  12988. if((atoi(value) == 0) || (atoi(value) >= 10))
  12989. {
  12990. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  12991. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  12992. isSuccess = ConfigurationStatus_Accepted;
  12993. }
  12994. else
  12995. isSuccess = ConfigurationStatus_Rejected;
  12996. }
  12997. }
  12998. else
  12999. {
  13000. isSuccess = ConfigurationStatus_Rejected;
  13001. }
  13002. }
  13003. if(strcmp(key, "ConnectionTimeOut") == 0 )
  13004. {
  13005. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  13006. {
  13007. check_ascii = value[0];
  13008. if( (check_ascii < 48) || (check_ascii > 57) )
  13009. {
  13010. isSuccess = ConfigurationStatus_Rejected;
  13011. }
  13012. else
  13013. {
  13014. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  13015. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  13016. isSuccess = ConfigurationStatus_Accepted;
  13017. }
  13018. }
  13019. else
  13020. {
  13021. isSuccess = ConfigurationStatus_Rejected;
  13022. }
  13023. }
  13024. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  13025. {
  13026. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  13027. {
  13028. check_ascii = value[0];
  13029. if( (check_ascii < 48) || (check_ascii > 57) )
  13030. {
  13031. isSuccess = ConfigurationStatus_Rejected;
  13032. }
  13033. else
  13034. {
  13035. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13036. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  13037. isSuccess = ConfigurationStatus_Accepted;
  13038. }
  13039. }
  13040. else
  13041. {
  13042. isSuccess = ConfigurationStatus_Rejected;
  13043. }
  13044. }
  13045. if(strcmp(key, "HeartbeatInterval") == 0)
  13046. {
  13047. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13048. {
  13049. check_ascii = value[0];
  13050. if( (check_ascii < 48) || (check_ascii > 57) )
  13051. {
  13052. isSuccess = ConfigurationStatus_Rejected;
  13053. }
  13054. else
  13055. {
  13056. if((atoi(value) == 0) || (atoi(value) >= 10))
  13057. {
  13058. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13059. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  13060. HeartBeatWaitTime = atoi(value);
  13061. isSuccess = ConfigurationStatus_Accepted;
  13062. }
  13063. else
  13064. {
  13065. isSuccess = ConfigurationStatus_Rejected;
  13066. }
  13067. }
  13068. }
  13069. else
  13070. {
  13071. isSuccess = ConfigurationStatus_Rejected;
  13072. }
  13073. }
  13074. if(strcmp(key, "LightIntensity") == 0)
  13075. {
  13076. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13077. {
  13078. check_ascii = value[0];
  13079. if( (check_ascii < 48) || (check_ascii > 57) )
  13080. {
  13081. isSuccess = ConfigurationStatus_Rejected;
  13082. }
  13083. else
  13084. {
  13085. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  13086. isSuccess = ConfigurationStatus_Accepted;
  13087. }
  13088. }
  13089. else
  13090. {
  13091. isSuccess = ConfigurationStatus_Rejected;
  13092. }
  13093. }
  13094. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  13095. {
  13096. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  13097. {
  13098. strcpy(str, (const char*)value);
  13099. for(int i = 0; str[i]; i++)
  13100. {
  13101. str[i] = tolower(str[i]);
  13102. }
  13103. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13104. isSuccess = ConfigurationStatus_Accepted;
  13105. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13106. }
  13107. else
  13108. {
  13109. isSuccess = ConfigurationStatus_Rejected;
  13110. }
  13111. }
  13112. if(strcmp(key, "LocalPreAuthorize") == 0)
  13113. {
  13114. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  13115. {
  13116. strcpy(str, (const char*)value);
  13117. for(int i = 0; str[i]; i++)
  13118. {
  13119. str[i] = tolower(str[i]);
  13120. }
  13121. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13122. isSuccess = ConfigurationStatus_Accepted;
  13123. }
  13124. else
  13125. {
  13126. isSuccess = ConfigurationStatus_Rejected;
  13127. }
  13128. }
  13129. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  13130. {
  13131. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  13132. {
  13133. check_ascii = value[0];
  13134. if( (check_ascii < 48) || (check_ascii > 57) )
  13135. {
  13136. isSuccess = ConfigurationStatus_Rejected;
  13137. }
  13138. else
  13139. {
  13140. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  13141. isSuccess = ConfigurationStatus_Accepted;
  13142. }
  13143. }
  13144. else
  13145. {
  13146. isSuccess = ConfigurationStatus_Rejected;
  13147. }
  13148. }
  13149. if(strcmp(key, "MeterValuesAlignedData") == 0)
  13150. {
  13151. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13152. {
  13153. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  13154. isSuccess = ConfigurationStatus_Accepted;
  13155. }
  13156. else
  13157. {
  13158. isSuccess = ConfigurationStatus_Rejected;
  13159. }
  13160. }
  13161. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  13162. {
  13163. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13164. {
  13165. check_ascii = value[0];
  13166. if( (check_ascii < 48) || (check_ascii > 57) )
  13167. {
  13168. isSuccess = ConfigurationStatus_Rejected;
  13169. }
  13170. else
  13171. {
  13172. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13173. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  13174. isSuccess = ConfigurationStatus_Accepted;
  13175. }
  13176. }
  13177. else
  13178. {
  13179. isSuccess = ConfigurationStatus_Rejected;
  13180. }
  13181. }
  13182. if(strcmp(key, "MeterValuesSampledData") == 0 )
  13183. {
  13184. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  13185. {
  13186. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  13187. isSuccess = ConfigurationStatus_Accepted;
  13188. }
  13189. else
  13190. {
  13191. isSuccess = ConfigurationStatus_Rejected;
  13192. }
  13193. }
  13194. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  13195. {
  13196. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  13197. {
  13198. check_ascii = value[0];
  13199. if( (check_ascii < 48) || (check_ascii > 57) )
  13200. {
  13201. isSuccess = ConfigurationStatus_Rejected;
  13202. }
  13203. else
  13204. {
  13205. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13206. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  13207. isSuccess = ConfigurationStatus_Accepted;
  13208. }
  13209. }
  13210. else
  13211. {
  13212. isSuccess = ConfigurationStatus_Rejected;
  13213. }
  13214. }
  13215. if(strcmp(key, "MeterValueSampleInterval") == 0)
  13216. {
  13217. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  13218. {
  13219. check_ascii = value[0];
  13220. if( (check_ascii < 48) || (check_ascii > 57) )
  13221. {
  13222. isSuccess = ConfigurationStatus_Rejected;
  13223. }
  13224. else
  13225. {
  13226. if((atoi(value) == 0) || (atoi(value) >= 10))
  13227. {
  13228. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13229. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  13230. isSuccess = ConfigurationStatus_Accepted;
  13231. }
  13232. else
  13233. {
  13234. isSuccess = ConfigurationStatus_Rejected;
  13235. }
  13236. }
  13237. }
  13238. else
  13239. {
  13240. isSuccess = ConfigurationStatus_Rejected;
  13241. }
  13242. }
  13243. if(strcmp(key, "MinimumStatusDuration") == 0)
  13244. {
  13245. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  13246. {
  13247. check_ascii = value[0];
  13248. if( (check_ascii < 48) || (check_ascii > 57) )
  13249. {
  13250. isSuccess = ConfigurationStatus_Rejected;
  13251. }
  13252. else
  13253. {
  13254. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  13255. {
  13256. isSuccess = ConfigurationStatus_Rejected;
  13257. }
  13258. else
  13259. {
  13260. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  13261. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  13262. server_cycle_Status = atoi(value); //StatusNotification Cycle
  13263. isSuccess = ConfigurationStatus_Accepted;
  13264. }
  13265. }
  13266. }
  13267. else
  13268. {
  13269. isSuccess = ConfigurationStatus_Rejected;
  13270. }
  13271. }
  13272. if(strcmp(key, "NumberOfConnectors") == 0)
  13273. {
  13274. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  13275. {
  13276. check_ascii = value[0];
  13277. if( (check_ascii < 48) || (check_ascii > 57) )
  13278. {
  13279. isSuccess = ConfigurationStatus_Rejected;
  13280. }
  13281. else
  13282. {
  13283. //Charger.ResetRetries = Integer.parseInt(value);
  13284. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  13285. isSuccess = ConfigurationStatus_Accepted;
  13286. }
  13287. }
  13288. else
  13289. {
  13290. isSuccess = ConfigurationStatus_Rejected;
  13291. }
  13292. }
  13293. if(strcmp(key, "ResetRetries") == 0)
  13294. {
  13295. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  13296. {
  13297. check_ascii = value[0];
  13298. if( (check_ascii < 48) || (check_ascii > 57) )
  13299. {
  13300. isSuccess = ConfigurationStatus_Rejected;
  13301. }
  13302. else
  13303. {
  13304. //Charger.ResetRetries = Integer.parseInt(value);
  13305. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  13306. isSuccess = ConfigurationStatus_Accepted;
  13307. }
  13308. }
  13309. else
  13310. {
  13311. isSuccess = ConfigurationStatus_Rejected;
  13312. }
  13313. }
  13314. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  13315. {
  13316. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  13317. {
  13318. strcpy(str, (const char*)value);
  13319. for(int i = 0; str[i]; i++)
  13320. {
  13321. str[i] = tolower(str[i]);
  13322. }
  13323. if(strcmp(str, "notapplicable")== 0)
  13324. {
  13325. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  13326. isSuccess = ConfigurationStatus_Accepted;
  13327. }
  13328. else if(strcmp(str, "unknown")== 0)
  13329. {
  13330. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  13331. isSuccess = ConfigurationStatus_Accepted;
  13332. }
  13333. else if(strcmp(str, "rst")== 0)
  13334. {
  13335. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  13336. isSuccess = ConfigurationStatus_Accepted;
  13337. }
  13338. else if(strcmp(str, "rts")== 0)
  13339. {
  13340. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  13341. isSuccess = ConfigurationStatus_Accepted;
  13342. }
  13343. else if(strcmp(str, "srt")== 0)
  13344. {
  13345. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  13346. isSuccess = ConfigurationStatus_Accepted;
  13347. }
  13348. else if(strcmp(str, "str")== 0)
  13349. {
  13350. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  13351. isSuccess = ConfigurationStatus_Accepted;
  13352. }
  13353. else if(strcmp(str, "trs")== 0)
  13354. {
  13355. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  13356. isSuccess = ConfigurationStatus_Accepted;
  13357. }
  13358. else if(strcmp(str, "tsr")== 0)
  13359. {
  13360. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  13361. isSuccess = ConfigurationStatus_Accepted;
  13362. }
  13363. else
  13364. {
  13365. isSuccess = ConfigurationStatus_Rejected;
  13366. }
  13367. }
  13368. else
  13369. {
  13370. isSuccess = ConfigurationStatus_Rejected;
  13371. }
  13372. }
  13373. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  13374. {
  13375. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  13376. {
  13377. check_ascii = value[0];
  13378. if( (check_ascii < 48) || (check_ascii > 57) )
  13379. {
  13380. isSuccess = ConfigurationStatus_Rejected;
  13381. }
  13382. else
  13383. {
  13384. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  13385. isSuccess = ConfigurationStatus_Accepted;
  13386. }
  13387. }
  13388. else
  13389. {
  13390. isSuccess = ConfigurationStatus_Rejected;
  13391. }
  13392. }
  13393. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  13394. {
  13395. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  13396. {
  13397. strcpy(str, (const char*)value);
  13398. for(int i = 0; str[i]; i++)
  13399. {
  13400. str[i] = tolower(str[i]);
  13401. }
  13402. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  13403. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13404. isSuccess = ConfigurationStatus_Accepted;
  13405. }
  13406. else
  13407. {
  13408. isSuccess = ConfigurationStatus_Rejected;
  13409. }
  13410. }
  13411. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  13412. {
  13413. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  13414. {
  13415. strcpy(str, (const char*)value);
  13416. for(int i = 0; str[i]; i++)
  13417. {
  13418. str[i] = tolower(str[i]);
  13419. }
  13420. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  13421. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13422. isSuccess = ConfigurationStatus_Accepted;
  13423. }
  13424. else
  13425. {
  13426. isSuccess = ConfigurationStatus_Rejected;
  13427. }
  13428. }
  13429. if(strcmp(key, "StopTxnAlignedData") == 0)
  13430. {
  13431. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  13432. {
  13433. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  13434. isSuccess = ConfigurationStatus_Accepted;
  13435. }
  13436. else
  13437. {
  13438. isSuccess = ConfigurationStatus_Rejected;
  13439. }
  13440. }
  13441. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  13442. {
  13443. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  13444. {
  13445. check_ascii = value[0];
  13446. if( (check_ascii < 48) || (check_ascii > 57) )
  13447. {
  13448. isSuccess = ConfigurationStatus_Rejected;
  13449. }
  13450. else
  13451. {
  13452. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  13453. isSuccess = ConfigurationStatus_Accepted;
  13454. }
  13455. }
  13456. else
  13457. {
  13458. isSuccess = ConfigurationStatus_Rejected;
  13459. }
  13460. }
  13461. if(strcmp(key, "StopTxnSampledData") == 0)
  13462. {
  13463. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  13464. {
  13465. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  13466. isSuccess = ConfigurationStatus_Accepted;
  13467. }
  13468. else
  13469. {
  13470. isSuccess = ConfigurationStatus_Rejected;
  13471. }
  13472. }
  13473. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  13474. {
  13475. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  13476. {
  13477. check_ascii = value[0];
  13478. if( (check_ascii < 48) || (check_ascii > 57) )
  13479. {
  13480. isSuccess = ConfigurationStatus_Rejected;
  13481. }
  13482. else
  13483. {
  13484. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  13485. isSuccess = ConfigurationStatus_Accepted;
  13486. }
  13487. }
  13488. else
  13489. {
  13490. isSuccess = ConfigurationStatus_Rejected;
  13491. }
  13492. }
  13493. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  13494. {
  13495. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  13496. {
  13497. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  13498. isSuccess = ConfigurationStatus_Accepted;
  13499. }
  13500. else
  13501. {
  13502. isSuccess = ConfigurationStatus_Rejected;
  13503. }
  13504. }
  13505. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  13506. {
  13507. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  13508. {
  13509. check_ascii = value[0];
  13510. if( (check_ascii < 48) || (check_ascii > 57) )
  13511. {
  13512. isSuccess = ConfigurationStatus_Rejected;
  13513. }
  13514. else
  13515. {
  13516. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  13517. isSuccess = ConfigurationStatus_Accepted;
  13518. }
  13519. }
  13520. else
  13521. {
  13522. isSuccess = ConfigurationStatus_Rejected;
  13523. }
  13524. }
  13525. if(strcmp(key, "TransactionMessageAttempts") == 0)
  13526. {
  13527. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  13528. {
  13529. check_ascii = value[0];
  13530. if( (check_ascii < 48) || (check_ascii > 57) )
  13531. {
  13532. isSuccess = ConfigurationStatus_Rejected;
  13533. }
  13534. else
  13535. {
  13536. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  13537. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  13538. TransactionMessageAttemptsValue = atoi(value);
  13539. isSuccess = ConfigurationStatus_Accepted;
  13540. }
  13541. }
  13542. else
  13543. {
  13544. isSuccess = ConfigurationStatus_Rejected;
  13545. }
  13546. }
  13547. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  13548. {
  13549. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  13550. {
  13551. check_ascii = value[0];
  13552. if( (check_ascii < 48) || (check_ascii > 57) )
  13553. {
  13554. isSuccess = ConfigurationStatus_Rejected;
  13555. }
  13556. else
  13557. {
  13558. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  13559. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  13560. TransactionMessageRetryIntervalValue = atoi(value);
  13561. isSuccess = ConfigurationStatus_Accepted;
  13562. }
  13563. }
  13564. else
  13565. {
  13566. isSuccess = ConfigurationStatus_Rejected;
  13567. }
  13568. }
  13569. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  13570. {
  13571. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  13572. {
  13573. strcpy(str, (const char*)value);
  13574. for(int i = 0; str[i]; i++)
  13575. {
  13576. str[i] = tolower(str[i]);
  13577. }
  13578. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  13579. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13580. isSuccess = ConfigurationStatus_Accepted;
  13581. }
  13582. else
  13583. {
  13584. isSuccess = ConfigurationStatus_Rejected;
  13585. }
  13586. }
  13587. if(strcmp(key, "WebSocketPingInterval") == 0)
  13588. {
  13589. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  13590. {
  13591. check_ascii = value[0];
  13592. if( (check_ascii < 48) || (check_ascii > 57) )
  13593. {
  13594. isSuccess = ConfigurationStatus_Rejected;
  13595. }
  13596. else
  13597. {
  13598. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  13599. isSuccess = ConfigurationStatus_Accepted;
  13600. }
  13601. }
  13602. else
  13603. {
  13604. isSuccess = ConfigurationStatus_Rejected;
  13605. }
  13606. }
  13607. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  13608. {
  13609. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  13610. {
  13611. strcpy(str, (const char*)value);
  13612. for(int i = 0; str[i]; i++)
  13613. {
  13614. str[i] = tolower(str[i]);
  13615. }
  13616. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13617. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13618. isSuccess = ConfigurationStatus_Accepted;
  13619. }
  13620. else
  13621. {
  13622. isSuccess = ConfigurationStatus_Rejected;
  13623. }
  13624. }
  13625. if(strcmp(key, "AuthorizationKey") == 0)
  13626. {
  13627. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  13628. {
  13629. strcpy(str, (const char*)value);
  13630. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  13631. isSuccess = ConfigurationStatus_Accepted;
  13632. }
  13633. else
  13634. {
  13635. isSuccess = ConfigurationStatus_Rejected;
  13636. }
  13637. }
  13638. if(strcmp(key, "SecurityProfile") == 0)
  13639. {
  13640. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  13641. {
  13642. check_ascii = value[0];
  13643. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  13644. {
  13645. isSuccess = ConfigurationStatus_Rejected;
  13646. }
  13647. else if(check_ascii == 0x33)
  13648. {
  13649. isSuccess = NotSupported;
  13650. }
  13651. else
  13652. {
  13653. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  13654. {
  13655. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  13656. isSuccess = ConfigurationStatus_Accepted;
  13657. }
  13658. else
  13659. isSuccess = ConfigurationStatus_Rejected;
  13660. }
  13661. }
  13662. else
  13663. {
  13664. isSuccess = ConfigurationStatus_Rejected;
  13665. }
  13666. }
  13667. if(strcmp(key, "DefaultPrice") == 0)
  13668. {
  13669. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  13670. {
  13671. strcpy(str, (const char*)value);
  13672. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  13673. isSuccess = ConfigurationStatus_Accepted;
  13674. }
  13675. else
  13676. {
  13677. isSuccess = ConfigurationStatus_Rejected;
  13678. }
  13679. }
  13680. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  13681. {
  13682. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  13683. {
  13684. strcpy(str, (const char*)value);
  13685. for(int i = 0; str[i]; i++)
  13686. {
  13687. str[i] = tolower(str[i]);
  13688. }
  13689. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13690. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13691. isSuccess = ConfigurationStatus_Accepted;
  13692. }
  13693. else
  13694. {
  13695. isSuccess = ConfigurationStatus_Rejected;
  13696. }
  13697. }
  13698. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  13699. {
  13700. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  13701. {
  13702. strcpy(str, (const char*)value);
  13703. for(int i = 0; str[i]; i++)
  13704. {
  13705. str[i] = tolower(str[i]);
  13706. }
  13707. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13708. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13709. isSuccess = ConfigurationStatus_Accepted;
  13710. }
  13711. else
  13712. {
  13713. isSuccess = ConfigurationStatus_Rejected;
  13714. }
  13715. }
  13716. #if 0
  13717. //For OCPP Test Case
  13718. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  13719. {
  13720. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13721. {
  13722. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  13723. isSuccess = ConfigurationStatus_Accepted;
  13724. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13725. }
  13726. else
  13727. {
  13728. isSuccess = ConfigurationStatus_Rejected;
  13729. }
  13730. }
  13731. #endif
  13732. #if 1
  13733. if(strcmp(key, "LocalAuthListEnabled") == 0)
  13734. {
  13735. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13736. {
  13737. strcpy(str, (const char*)value);
  13738. for(int i = 0; str[i]; i++)
  13739. {
  13740. str[i] = tolower(str[i]);
  13741. }
  13742. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13743. isSuccess = ConfigurationStatus_Accepted;
  13744. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13745. }
  13746. else
  13747. {
  13748. isSuccess = ConfigurationStatus_Rejected;
  13749. }
  13750. }
  13751. #endif
  13752. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  13753. {
  13754. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  13755. {
  13756. check_ascii = value[0];
  13757. if( (check_ascii < 48) || (check_ascii > 57) )
  13758. {
  13759. isSuccess = ConfigurationStatus_Rejected;
  13760. }
  13761. else
  13762. {
  13763. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  13764. isSuccess = ConfigurationStatus_Accepted;
  13765. }
  13766. }
  13767. else
  13768. {
  13769. isSuccess = ConfigurationStatus_Rejected;
  13770. }
  13771. }
  13772. if(strcmp(key, "SendLocalListMaxLength") == 0)
  13773. {
  13774. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  13775. {
  13776. check_ascii = value[0];
  13777. if( (check_ascii < 48) || (check_ascii > 57) )
  13778. {
  13779. isSuccess = ConfigurationStatus_Rejected;
  13780. }
  13781. else
  13782. {
  13783. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  13784. isSuccess = ConfigurationStatus_Accepted;
  13785. }
  13786. }
  13787. else
  13788. {
  13789. isSuccess = ConfigurationStatus_Rejected;
  13790. }
  13791. }
  13792. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  13793. {
  13794. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  13795. {
  13796. strcpy(str, (const char*)value);
  13797. for(int i = 0; str[i]; i++)
  13798. {
  13799. str[i] = tolower(str[i]);
  13800. }
  13801. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13802. isSuccess = ConfigurationStatus_Accepted;
  13803. }
  13804. else
  13805. {
  13806. isSuccess = ConfigurationStatus_Rejected;
  13807. }
  13808. }
  13809. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  13810. {
  13811. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].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.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  13821. isSuccess = ConfigurationStatus_Accepted;
  13822. }
  13823. }
  13824. else
  13825. {
  13826. isSuccess = ConfigurationStatus_Rejected;
  13827. }
  13828. }
  13829. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  13830. {
  13831. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  13832. {
  13833. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  13834. isSuccess = ConfigurationStatus_Accepted;
  13835. }
  13836. else
  13837. {
  13838. isSuccess = ConfigurationStatus_Rejected;
  13839. }
  13840. }
  13841. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  13842. {
  13843. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  13844. {
  13845. check_ascii = value[0];
  13846. if( (check_ascii < 48) || (check_ascii > 57) )
  13847. {
  13848. isSuccess = ConfigurationStatus_Rejected;
  13849. }
  13850. else
  13851. {
  13852. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  13853. isSuccess = ConfigurationStatus_Accepted;
  13854. }
  13855. }
  13856. else
  13857. {
  13858. isSuccess = ConfigurationStatus_Rejected;
  13859. }
  13860. }
  13861. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  13862. {
  13863. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  13864. {
  13865. strcpy(str, (const char*)value);
  13866. for(int i = 0; str[i]; i++)
  13867. {
  13868. str[i] = tolower(str[i]);
  13869. }
  13870. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13871. isSuccess = ConfigurationStatus_Accepted;
  13872. }
  13873. else
  13874. {
  13875. isSuccess = ConfigurationStatus_Rejected;
  13876. }
  13877. }
  13878. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  13879. {
  13880. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].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[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  13890. isSuccess = ConfigurationStatus_Accepted;
  13891. }
  13892. }
  13893. else
  13894. {
  13895. isSuccess = ConfigurationStatus_Rejected;
  13896. }
  13897. }
  13898. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13899. return isSuccess;
  13900. }
  13901. int TransactionMessageAttemptsGet(void)
  13902. {
  13903. return TransactionMessageAttemptsValue;
  13904. }
  13905. int FirstHeartBeatResponse(void)
  13906. {
  13907. return FirstHeartBeat;
  13908. }
  13909. int TransactionMessageRetryIntervalGet(void)
  13910. {
  13911. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13912. }
  13913. int ReadHttpStatus(int sock)
  13914. {
  13915. //char c;
  13916. char buff[1024]="",*ptr=buff+1;
  13917. int bytes_received, status;
  13918. DEBUG_INFO("Begin Response ..\n");
  13919. while((bytes_received = recv(sock, ptr, 1, 0))){
  13920. if(bytes_received==-1){
  13921. perror("ReadHttpStatus");
  13922. exit(1);
  13923. }
  13924. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  13925. ptr++;
  13926. }
  13927. *ptr=0;
  13928. ptr=buff+1;
  13929. sscanf(ptr,"%*s %d ", &status);
  13930. DEBUG_INFO("%s\n",ptr);
  13931. DEBUG_INFO("status=%d\n",status);
  13932. DEBUG_INFO("End Response ..\n");
  13933. return (bytes_received>0)?status:0;
  13934. }
  13935. //the only filed that it parsed is 'Content-Length'
  13936. int ParseHeader(int sock)
  13937. {
  13938. //char c;
  13939. char buff[1024]="",*ptr=buff+4;
  13940. int bytes_received;
  13941. DEBUG_INFO("Begin HEADER ..\n");
  13942. while((bytes_received = recv(sock, ptr, 1, 0))){
  13943. if(bytes_received==-1){
  13944. perror("Parse Header");
  13945. exit(1);
  13946. }
  13947. if(
  13948. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  13949. (ptr[-1]=='\r') && (*ptr=='\n' )
  13950. ) break;
  13951. ptr++;
  13952. }
  13953. *ptr=0;
  13954. ptr=buff+4;
  13955. //printf("%s",ptr);
  13956. if(bytes_received){
  13957. ptr=strstr(ptr,"Content-Length:");
  13958. if(ptr){
  13959. sscanf(ptr,"%*s %d",&bytes_received);
  13960. }else
  13961. bytes_received=-1; //unknown size
  13962. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  13963. }
  13964. DEBUG_INFO("End HEADER ..\n");
  13965. return bytes_received ;
  13966. }
  13967. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  13968. {
  13969. int result = TRUE;
  13970. char rmFileCmd[100]={0};
  13971. char FilePath[100]={0};
  13972. char ftpbuf[200];
  13973. int systemresult;
  13974. //DEBUG_INFO("filename=%s\n",filename);
  13975. //DEBUG_INFO("url=%s\n",url);
  13976. sprintf(FilePath,"/mnt/%s",filename);
  13977. system("ping 8.8.8.8 &");
  13978. if((access(FilePath,F_OK))!=-1)
  13979. {
  13980. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13981. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13982. system(rmFileCmd);
  13983. }
  13984. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13985. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  13986. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13987. systemresult = system(ftpbuf);
  13988. //DEBUG_INFO("systemresult=%d\n",systemresult);
  13989. if(systemresult != 0)
  13990. {
  13991. DEBUG_INFO("http DownLoad error!\n");
  13992. result = FALSE;
  13993. }
  13994. system("pkill ping");
  13995. return result;
  13996. }
  13997. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  13998. {
  13999. int result = TRUE;
  14000. char rmFileCmd[100]={0};
  14001. char FilePath[100]={0};
  14002. char ftpbuf[200];
  14003. int systemresult;
  14004. //char temp[100];
  14005. sprintf(FilePath,"/mnt/%s",filename);
  14006. system("ping 8.8.8.8 &");
  14007. if((access(FilePath,F_OK))!=-1)
  14008. {
  14009. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14010. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14011. system(rmFileCmd);
  14012. }
  14013. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14014. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14015. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  14016. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14017. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14018. systemresult = system(ftpbuf);
  14019. //DEBUG_INFO("systemresult=%d\n",systemresult);
  14020. if(systemresult != 0)
  14021. {
  14022. printf("wget error!\n");
  14023. result = FALSE;
  14024. }
  14025. system("pkill ping");
  14026. return result;
  14027. }
  14028. int httpUploadFile(char *location, char *path, char *filename,char *url)
  14029. {
  14030. char rmFileCmd[100]={0};
  14031. char FilePath[100]={0};
  14032. char buf[512];
  14033. int systemresult = 0;
  14034. //DEBUG_INFO("filename=%s\n",filename);
  14035. //DEBUG_INFO("url=%s\n",url);
  14036. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  14037. if((access(FilePath,F_OK))!=-1)
  14038. {
  14039. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14040. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14041. system(rmFileCmd);
  14042. }
  14043. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  14044. if(fp == NULL)
  14045. {
  14046. DEBUG_INFO("log is NULL\n");
  14047. return FALSE;
  14048. }
  14049. else
  14050. {
  14051. fprintf(fp, "%s\n", url);
  14052. fprintf(fp, "%s\n", filename);
  14053. fclose(fp);
  14054. }
  14055. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  14056. if(phpFP == NULL)
  14057. {
  14058. DEBUG_INFO("PHP upload fail.\n");
  14059. return FALSE;
  14060. }
  14061. else
  14062. {
  14063. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  14064. {
  14065. if(strstr(buf, "result") != NULL)
  14066. {
  14067. sscanf(buf, "result: %d", &systemresult);
  14068. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  14069. }
  14070. }
  14071. pclose(phpFP);
  14072. }
  14073. if(systemresult != 1)
  14074. {
  14075. DEBUG_INFO("HTTP upload error!\n");
  14076. return FALSE;
  14077. }
  14078. return TRUE;
  14079. }
  14080. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  14081. {
  14082. struct hostent* server;
  14083. char *IPbuffer;
  14084. char ftpbuf[200];
  14085. int systemresult;
  14086. // To retrieve host information
  14087. server = gethostbyname(location);
  14088. // To convert an Internet network
  14089. // address into ASCII string
  14090. IPbuffer = inet_ntoa(*((struct in_addr*)
  14091. server->h_addr_list[0]));
  14092. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14093. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  14094. /* format : ftpput -u username -p passwd IP target source*/
  14095. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  14096. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14097. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14098. systemresult = system(ftpbuf);
  14099. DEBUG_INFO("systemresult=%d\n",systemresult);
  14100. if(systemresult != 0)
  14101. {
  14102. DEBUG_INFO("ftpput error!\n");
  14103. return FALSE;
  14104. }
  14105. return TRUE;
  14106. }
  14107. int GetOcppServerURL()
  14108. {
  14109. int result = FALSE;
  14110. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  14111. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  14112. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  14113. struct yuarel url;
  14114. char urlStr[512];
  14115. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  14116. {
  14117. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  14118. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14119. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  14120. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  14121. if(yuarel_parse(&url, urlStr) != -1)
  14122. {
  14123. sprintf(OcppProtocol, "%s", url.scheme);
  14124. sprintf(OcppHost, "%s", url.host);
  14125. if(url.path == NULL)
  14126. OcppTempPath[0] = '\0';
  14127. else
  14128. {
  14129. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  14130. {
  14131. sprintf(OcppTempPath, "%s/", url.path);
  14132. }
  14133. else
  14134. {
  14135. sprintf(OcppTempPath, "%s", url.path);
  14136. }
  14137. }
  14138. if(url.port == 0)
  14139. {
  14140. if(strcmp(OcppProtocol, "wss") == 0)
  14141. OcppPort = 443;
  14142. else
  14143. OcppPort = 80;
  14144. }
  14145. else
  14146. OcppPort = url.port;
  14147. result = TRUE;
  14148. }
  14149. }
  14150. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  14151. {
  14152. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  14153. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14154. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  14155. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  14156. if(yuarel_parse(&url, urlStr) != -1)
  14157. {
  14158. sprintf(OcppProtocol, "%s", url.scheme);
  14159. sprintf(OcppHost, "%s", url.host);
  14160. if(url.path == NULL)
  14161. OcppTempPath[0] = '\0';
  14162. else
  14163. sprintf(OcppTempPath, "%s", url.path);
  14164. if(url.port == 0)
  14165. {
  14166. if(strcmp(OcppProtocol, "wss") == 0)
  14167. OcppPort = 443;
  14168. else
  14169. OcppPort = 80;
  14170. }
  14171. else
  14172. OcppPort = url.port;
  14173. result = TRUE;
  14174. }
  14175. }
  14176. else
  14177. {
  14178. strcpy(OcppHost,"");
  14179. }
  14180. return result;
  14181. }
  14182. int GetOcppPath()
  14183. {
  14184. int result = FALSE;
  14185. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  14186. {
  14187. if(OcppTempPath == NULL)
  14188. {
  14189. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  14190. }
  14191. else
  14192. {
  14193. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  14194. }
  14195. result = TRUE;
  14196. goto End;
  14197. }
  14198. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  14199. {
  14200. if(OcppTempPath == NULL)
  14201. {
  14202. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  14203. }
  14204. else
  14205. {
  14206. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  14207. }
  14208. result = TRUE;
  14209. goto End;
  14210. }
  14211. else
  14212. {
  14213. strcpy(OcppPath,"");
  14214. }
  14215. End:
  14216. return result;
  14217. }
  14218. int GetOcppPort()
  14219. {
  14220. return OcppPort;
  14221. }
  14222. int GetOcppConnStatus(void)
  14223. {
  14224. return ShmOCPP16Data->OcppConnStatus;
  14225. }
  14226. void SetOcppConnStatus(uint8_t status)
  14227. {
  14228. ShmOCPP16Data->OcppConnStatus = status;
  14229. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  14230. }
  14231. int GetHeartBeatWithNOResponse(void)
  14232. {
  14233. return HeartBeatWithNOResponse;
  14234. }
  14235. void SetHeartBeatWithNOResponse(void)
  14236. {
  14237. HeartBeatWithNOResponse = 0;
  14238. }
  14239. void GetStartTransactionIdTag(int gun_index)
  14240. {
  14241. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  14242. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  14243. }
  14244. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  14245. {
  14246. char ch;
  14247. FILE *fptr1;
  14248. int temptransactionId;
  14249. char str[100]={0};
  14250. temptransactionId = 0;
  14251. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  14252. {
  14253. DEBUG_INFO("IdTag is empty.\n");
  14254. return temptransactionId;
  14255. }
  14256. /*------ Read the file ----------------*/
  14257. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  14258. if (!fptr1)
  14259. {
  14260. DEBUG_INFO("QueueTransactionId file open error.\n");
  14261. //printf(" File not found or unable to open the input file!!\n");
  14262. return temptransactionId;
  14263. }
  14264. ch=fgetc(fptr1);
  14265. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  14266. rewind(fptr1);
  14267. if(ch!=EOF)
  14268. {
  14269. // printf("%c",ch);
  14270. while (fgets(str, 100, fptr1) != NULL)
  14271. {
  14272. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14273. if(str[0]=='\0')
  14274. {
  14275. break;
  14276. }
  14277. char *revbuf[8] = {0}; // Variable store string split
  14278. int num = 0;// Quantity after string split
  14279. DEBUG_INFO("Transaction queue data= %s\n", str);
  14280. splitstring(str,",",revbuf,&num); // String split
  14281. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  14282. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  14283. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  14284. DEBUG_INFO("------------------------------\n");
  14285. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  14286. {
  14287. if(isStopTransaction)
  14288. {
  14289. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  14290. {
  14291. temptransactionId = atoi(revbuf[2]);
  14292. //break;
  14293. }
  14294. }
  14295. else
  14296. {
  14297. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  14298. {
  14299. temptransactionId = atoi(revbuf[2]);
  14300. //break;
  14301. }
  14302. }
  14303. }
  14304. }
  14305. }
  14306. else
  14307. DEBUG_INFO("EOF\n");
  14308. fclose(fptr1);
  14309. /*------- End of reading ---------------*/
  14310. return temptransactionId;
  14311. }
  14312. void SetTransactionIdZero(int transactionId)
  14313. {
  14314. char ch;
  14315. FILE *fptr1, *fptr2;
  14316. int temptransactionId = 0;
  14317. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  14318. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  14319. if (!fptr1)
  14320. {
  14321. //printf(" File not found or unable to open the input file!!\n");
  14322. return ;
  14323. }
  14324. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  14325. if (!fptr2)
  14326. {
  14327. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  14328. fclose(fptr1);
  14329. return ;
  14330. }
  14331. ch=fgetc(fptr1);
  14332. rewind(fptr1);
  14333. if(ch!=EOF)
  14334. {
  14335. // copy all contents to the temporary file except the specific line
  14336. while (fgets(str, 100, fptr1) != NULL)
  14337. {
  14338. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14339. if(str[0]=='\0')
  14340. {
  14341. break;
  14342. }
  14343. char *revbuf[8] = {0};
  14344. int num = 0;
  14345. strcpy(strtemp, str);
  14346. splitstring(str,",",revbuf,&num);
  14347. if(revbuf[2][0] != '\0')
  14348. {
  14349. temptransactionId = atoi(revbuf[2]);
  14350. if(transactionId != temptransactionId)
  14351. {
  14352. fprintf(fptr2, "%s\n", strtemp);
  14353. }
  14354. }
  14355. }
  14356. }
  14357. fclose(fptr1);
  14358. fclose(fptr2);
  14359. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  14360. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  14361. /*------ Read the file ----------------*/
  14362. }
  14363. int InternetDisconnect(void)
  14364. {
  14365. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  14366. }
  14367. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  14368. void storeTempStopTransaction(int gun_index)
  14369. {
  14370. char guid[37]={0};
  14371. int tempIndex = 0;
  14372. char TempStopTransaction[256];
  14373. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  14374. DEBUG_INFO("storeTempStopTransaction...\n");
  14375. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  14376. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  14377. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  14378. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14379. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14380. {
  14381. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14382. {
  14383. tempIndex = ((gun_index==2) ? 1: 0);
  14384. }
  14385. else
  14386. {
  14387. tempIndex = gun_index;
  14388. }
  14389. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14390. {
  14391. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14392. {
  14393. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  14394. }
  14395. }// END OF CHAdeMO_QUANTITY
  14396. }
  14397. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14398. {
  14399. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14400. {
  14401. tempIndex = ((gun_index==2) ? 1: 0);
  14402. }
  14403. else
  14404. {
  14405. tempIndex = gun_index;
  14406. }
  14407. for (int index = 0; index < CCS_QUANTITY; index++)
  14408. {
  14409. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14410. {
  14411. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  14412. }
  14413. }// END OF CCS_QUANTITY
  14414. }
  14415. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14416. {
  14417. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14418. {
  14419. tempIndex = ((gun_index==2) ? 1: 0);
  14420. }
  14421. else
  14422. {
  14423. tempIndex = gun_index;
  14424. }
  14425. for (int index = 0; index < GB_QUANTITY; index++)
  14426. {
  14427. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14428. {
  14429. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  14430. }
  14431. }// END OF GB_QUANTITY
  14432. }
  14433. else if(gunType[gun_index] == GUN_TYPE_DO)
  14434. {
  14435. tempIndex = gun_index;
  14436. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14437. {
  14438. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14439. {
  14440. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  14441. }
  14442. }
  14443. }
  14444. else
  14445. {
  14446. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14447. {
  14448. tempIndex = 2;
  14449. }
  14450. else
  14451. {
  14452. tempIndex = gun_index;
  14453. }
  14454. for (int index = 0; index < AC_QUANTITY; index++)
  14455. {
  14456. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14457. {
  14458. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  14459. }
  14460. }// END OF AC_QUANTITY
  14461. }
  14462. //Stop Transaction Time
  14463. struct timeval tmnow;
  14464. struct tm *tm;
  14465. char buf[28];//, usec_buf[6];
  14466. gettimeofday(&tmnow, NULL);
  14467. time_t t;
  14468. t = time(NULL);
  14469. /*UTC time and date*/
  14470. tm = gmtime(&t);
  14471. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  14472. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  14473. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  14474. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  14475. random_uuid(guid);
  14476. /***********************************transactionData******************************************************/
  14477. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  14478. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  14479. //=================================
  14480. //1. Transaction_Begin
  14481. //=================================
  14482. //============================== Energy.Active.Import.Interval ===========================================
  14483. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  14484. {
  14485. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  14486. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  14487. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  14488. 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*/]);
  14489. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14490. 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))
  14491. {
  14492. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  14493. }
  14494. else
  14495. {
  14496. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  14497. }
  14498. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  14499. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  14500. }
  14501. //=================================
  14502. //2. Transaction_End
  14503. //=================================
  14504. //2.1====================================== Current.Import L1 ==============================================
  14505. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  14506. {
  14507. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  14508. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14509. {
  14510. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14511. {
  14512. tempIndex = ((gun_index==2) ? 1: 0);
  14513. }
  14514. else
  14515. {
  14516. tempIndex = gun_index;
  14517. }
  14518. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14519. {
  14520. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14521. {
  14522. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14523. }
  14524. }// End of for CHAdeMO_QUANTITY
  14525. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14526. }
  14527. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14528. {
  14529. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14530. {
  14531. tempIndex = ((gun_index==2) ? 1: 0);
  14532. }
  14533. else
  14534. {
  14535. tempIndex = gun_index;
  14536. }
  14537. for (int index = 0; index < CCS_QUANTITY; index++)
  14538. {
  14539. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14540. {
  14541. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14542. }
  14543. }// End of for CCS_QUANTITY
  14544. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14545. }
  14546. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14547. {
  14548. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14549. {
  14550. tempIndex = ((gun_index==2) ? 1: 0);
  14551. }
  14552. else
  14553. {
  14554. tempIndex = gun_index;
  14555. }
  14556. for (int index = 0; index < GB_QUANTITY; index++)
  14557. {
  14558. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14559. {
  14560. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14561. }
  14562. }// End of for GB_QUANTITY
  14563. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14564. }
  14565. else if(gunType[gun_index] == GUN_TYPE_DO)
  14566. {
  14567. tempIndex = gun_index;
  14568. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14569. {
  14570. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14571. {
  14572. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14573. }
  14574. }
  14575. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14576. }
  14577. else
  14578. {
  14579. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14580. {
  14581. tempIndex = 2;
  14582. }
  14583. else
  14584. {
  14585. tempIndex = gun_index;
  14586. }
  14587. for (int index = 0; index < AC_QUANTITY; index++)
  14588. {
  14589. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14590. {
  14591. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  14592. }
  14593. }// End of for AC_QUANTITY
  14594. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  14595. }
  14596. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14597. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  14598. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  14599. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  14600. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  14601. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14602. }
  14603. //2.2===================================== Energy.Active.Import.Interval ==========================================
  14604. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  14605. {
  14606. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14607. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14608. {
  14609. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14610. {
  14611. tempIndex = ((gun_index==2) ? 1: 0);
  14612. }
  14613. else
  14614. {
  14615. tempIndex = gun_index;
  14616. }
  14617. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14618. {
  14619. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14620. {
  14621. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14622. }
  14623. }// END OF CHAdeMO_QUANTITY
  14624. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14625. }
  14626. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14627. {
  14628. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14629. {
  14630. tempIndex = ((gun_index==2) ? 1: 0);
  14631. }
  14632. else
  14633. {
  14634. tempIndex = gun_index;
  14635. }
  14636. for (int index = 0; index < CCS_QUANTITY; index++)
  14637. {
  14638. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14639. {
  14640. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14641. }
  14642. }// END OF CCS_QUANTITY
  14643. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14644. }
  14645. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14646. {
  14647. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14648. {
  14649. tempIndex = ((gun_index==2) ? 1: 0);
  14650. }
  14651. else
  14652. {
  14653. tempIndex = gun_index;
  14654. }
  14655. for (int index = 0; index < GB_QUANTITY; index++)
  14656. {
  14657. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14658. {
  14659. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14660. }
  14661. }// END OF GB_QUANTITY
  14662. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14663. }
  14664. else if(gunType[gun_index] == GUN_TYPE_DO)
  14665. {
  14666. tempIndex = gun_index;
  14667. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14668. {
  14669. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14670. {
  14671. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14672. }
  14673. }
  14674. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14675. }
  14676. else
  14677. {
  14678. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14679. {
  14680. tempIndex = 2;
  14681. }
  14682. else
  14683. {
  14684. tempIndex = gun_index;
  14685. }
  14686. for (int index = 0; index < AC_QUANTITY; index++)
  14687. {
  14688. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14689. {
  14690. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14691. }
  14692. }// END OF AC_QUANTITY
  14693. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  14694. }
  14695. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14696. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  14697. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  14698. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  14699. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  14700. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  14701. }
  14702. //2.3====================================== Power.Active.Import =========================================
  14703. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  14704. {
  14705. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14706. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14707. {
  14708. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14709. {
  14710. tempIndex = ((gun_index==2) ? 1: 0);
  14711. }
  14712. else
  14713. {
  14714. tempIndex = gun_index;
  14715. }
  14716. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14717. {
  14718. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14719. {
  14720. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14721. }
  14722. } // End for CHAdeMO_QUANTITY
  14723. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14724. }
  14725. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14726. {
  14727. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14728. {
  14729. tempIndex = ((gun_index==2) ? 1: 0);
  14730. }
  14731. else
  14732. {
  14733. tempIndex = gun_index;
  14734. }
  14735. for (int index = 0; index < CCS_QUANTITY; index++)
  14736. {
  14737. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14738. {
  14739. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14740. }
  14741. } // END for CCS_QUANTITY
  14742. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14743. }
  14744. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14745. {
  14746. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14747. {
  14748. tempIndex = ((gun_index==2) ? 1: 0);
  14749. }
  14750. else
  14751. {
  14752. tempIndex = gun_index;
  14753. }
  14754. for (int index = 0; index < GB_QUANTITY; index++)
  14755. {
  14756. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14757. {
  14758. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14759. }
  14760. }// END for GB_QUANTITY
  14761. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14762. }
  14763. else if(gunType[gun_index] == GUN_TYPE_DO)
  14764. {
  14765. tempIndex = gun_index;
  14766. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14767. {
  14768. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14769. {
  14770. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14771. }
  14772. }
  14773. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14774. }
  14775. else
  14776. {
  14777. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14778. {
  14779. tempIndex = 2;
  14780. }
  14781. else
  14782. {
  14783. tempIndex = gun_index;
  14784. }
  14785. for (int index = 0; index < AC_QUANTITY; index++)
  14786. {
  14787. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14788. {
  14789. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14790. }
  14791. } // END for AC_QUANTITY
  14792. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  14793. }
  14794. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14795. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  14796. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  14797. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  14798. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  14799. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  14800. }
  14801. //2.4====================================== Voltage L1 ====================================================
  14802. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  14803. {
  14804. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14805. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14806. {
  14807. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14808. {
  14809. tempIndex = ((gun_index==2) ? 1: 0);
  14810. }
  14811. else
  14812. {
  14813. tempIndex = gun_index;
  14814. }
  14815. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14816. {
  14817. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14818. {
  14819. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14820. }
  14821. } // END OF FOR CHAdeMO_QUANTITY
  14822. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14823. }
  14824. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14825. {
  14826. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14827. {
  14828. tempIndex = ((gun_index==2) ? 1: 0);
  14829. }
  14830. else
  14831. {
  14832. tempIndex = gun_index;
  14833. }
  14834. for (int index = 0; index < CCS_QUANTITY; index++)
  14835. {
  14836. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14837. {
  14838. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14839. }
  14840. } // END OF FOR CCS_QUANTITY
  14841. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14842. }
  14843. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14844. {
  14845. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14846. {
  14847. tempIndex = ((gun_index==2) ? 1: 0);
  14848. }
  14849. else
  14850. {
  14851. tempIndex = gun_index;
  14852. }
  14853. for (int index = 0; index < GB_QUANTITY; index++)
  14854. {
  14855. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14856. {
  14857. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14858. }
  14859. } // END OF FOR GB_QUANTITY
  14860. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14861. }
  14862. else if(gunType[gun_index] == GUN_TYPE_DO)
  14863. {
  14864. tempIndex = gun_index;
  14865. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14866. {
  14867. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14868. {
  14869. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14870. }
  14871. }
  14872. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14873. }
  14874. else
  14875. {
  14876. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14877. {
  14878. tempIndex = 2;
  14879. }
  14880. else
  14881. {
  14882. tempIndex = gun_index;
  14883. }
  14884. for (int index = 0; index < AC_QUANTITY; index++)
  14885. {
  14886. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14887. {
  14888. 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
  14889. }
  14890. } // END OF FOR AC_QUANTITY
  14891. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  14892. }
  14893. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14894. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  14895. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  14896. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  14897. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  14898. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  14899. }
  14900. //2.5============================================== End SoC =========================================================
  14901. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  14902. {
  14903. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14904. 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))
  14905. {
  14906. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  14907. {
  14908. tempIndex = ((gun_index==2) ? 1: 0);
  14909. }
  14910. else
  14911. {
  14912. tempIndex = gun_index;
  14913. }
  14914. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14915. {
  14916. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14917. {
  14918. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14919. {
  14920. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  14921. }
  14922. }
  14923. }
  14924. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14925. {
  14926. for (int index = 0; index < CCS_QUANTITY; index++)
  14927. {
  14928. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14929. {
  14930. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  14931. }
  14932. }
  14933. }
  14934. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14935. {
  14936. for (int index = 0; index < GB_QUANTITY; index++)
  14937. {
  14938. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14939. {
  14940. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  14941. }
  14942. }
  14943. }
  14944. else if(gunType[gun_index] == GUN_TYPE_DO)
  14945. {
  14946. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14947. {
  14948. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14949. {
  14950. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  14951. }
  14952. }
  14953. }
  14954. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14955. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  14956. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  14957. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  14958. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  14959. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  14960. } // END FOR DC CASE
  14961. }
  14962. //2.6====================================== Current.Import L2 ==============================================
  14963. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  14964. {
  14965. // AC 3 phase L2 current
  14966. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  14967. {
  14968. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14969. {
  14970. tempIndex = 2;
  14971. }
  14972. else
  14973. {
  14974. tempIndex = gun_index;
  14975. }
  14976. for (int index = 0; index < AC_QUANTITY; index++)
  14977. {
  14978. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14979. {
  14980. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  14981. }
  14982. }// End of for AC_QUANTITY
  14983. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  14984. }
  14985. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14986. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  14987. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  14988. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  14989. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14990. }
  14991. //2.7====================================== Current.Import L3 ==============================================
  14992. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  14993. {
  14994. // AC 3 phase L3 current
  14995. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  14996. {
  14997. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14998. {
  14999. tempIndex = 2;
  15000. }
  15001. else
  15002. {
  15003. tempIndex = gun_index;
  15004. }
  15005. for (int index = 0; index < AC_QUANTITY; index++)
  15006. {
  15007. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15008. {
  15009. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  15010. }
  15011. }// End of for AC_QUANTITY
  15012. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  15013. }
  15014. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15015. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  15016. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  15017. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  15018. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15019. }
  15020. //2.9====================================== Voltage L2 ====================================================
  15021. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15022. {
  15023. // AC 3 phase L2 volatge
  15024. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15025. {
  15026. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15027. {
  15028. tempIndex = 2;
  15029. }
  15030. else
  15031. {
  15032. tempIndex = gun_index;
  15033. }
  15034. for (int index = 0; index < AC_QUANTITY; index++)
  15035. {
  15036. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15037. {
  15038. 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
  15039. }
  15040. } // END OF FOR AC_QUANTITY
  15041. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  15042. }
  15043. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15044. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  15045. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  15046. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  15047. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15048. }
  15049. //2.10====================================== Voltage L3 ====================================================
  15050. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15051. {
  15052. // AC 3 phase L3 volatge
  15053. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15054. {
  15055. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15056. {
  15057. tempIndex = 2;
  15058. }
  15059. else
  15060. {
  15061. tempIndex = gun_index;
  15062. }
  15063. for (int index = 0; index < AC_QUANTITY; index++)
  15064. {
  15065. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15066. {
  15067. 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
  15068. }
  15069. } // END OF FOR AC_QUANTITY
  15070. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  15071. }
  15072. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15073. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  15074. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  15075. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  15076. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15077. }
  15078. //====================== Start SoC ================================
  15079. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  15080. {
  15081. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15082. 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))
  15083. {
  15084. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15085. {
  15086. tempIndex = ((gun_index==2) ? 1: 0);
  15087. }
  15088. else
  15089. {
  15090. tempIndex = gun_index;
  15091. }
  15092. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15093. {
  15094. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15095. {
  15096. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15097. {
  15098. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  15099. }
  15100. }
  15101. }
  15102. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15103. {
  15104. for (int index = 0; index < CCS_QUANTITY; index++)
  15105. {
  15106. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15107. {
  15108. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  15109. }
  15110. }
  15111. }
  15112. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15113. {
  15114. for (int index = 0; index < GB_QUANTITY; index++)
  15115. {
  15116. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15117. {
  15118. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  15119. }
  15120. }
  15121. }
  15122. else if(gunType[gun_index] == GUN_TYPE_DO)
  15123. {
  15124. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15125. {
  15126. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15127. {
  15128. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  15129. }
  15130. }
  15131. }
  15132. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15133. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  15134. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15135. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  15136. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  15137. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15138. } // END FOR DC CASE
  15139. }
  15140. //======================================== Message create ==============================================
  15141. json_object *StopTransaction = json_object_new_object();
  15142. json_object *transactionDatas = json_object_new_array();
  15143. json_object *sampledValues = json_object_new_array();
  15144. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  15145. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  15146. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  15147. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  15148. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  15149. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  15150. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  15151. {
  15152. json_object *transactionData = json_object_new_object();
  15153. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  15154. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  15155. {
  15156. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  15157. {
  15158. json_object *sampledValue = json_object_new_object();
  15159. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  15160. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  15161. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  15162. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  15163. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  15164. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  15165. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  15166. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  15167. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  15168. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  15169. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  15170. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  15171. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  15172. json_object_array_add(sampledValues, sampledValue);
  15173. }
  15174. }
  15175. json_object_object_add(transactionData, "sampledValue", sampledValues);
  15176. json_object_array_add(transactionDatas, transactionData);
  15177. }
  15178. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  15179. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  15180. ,MESSAGE_TYPE_CALL
  15181. ,guid
  15182. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  15183. json_object_put(StopTransaction);
  15184. // Check File "TempStopTransaction" Exist
  15185. if((access(TempStopTransaction,F_OK))!=-1)
  15186. {
  15187. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  15188. fclose(fopen(TempStopTransaction, "w"));
  15189. }
  15190. else
  15191. {
  15192. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  15193. FILE *log = fopen(TempStopTransaction, "w+");
  15194. if(log == NULL)
  15195. {
  15196. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  15197. return ;
  15198. }
  15199. else
  15200. {
  15201. fclose(log);
  15202. }
  15203. }
  15204. //Add TempStopTransaction | Update TempStopTransaction
  15205. // open file for writing
  15206. FILE *outfile;
  15207. outfile = fopen (TempStopTransaction, "a");
  15208. //DEBUG_INFO("data = %s\n", queuedata);
  15209. fputs(queuedata, outfile);
  15210. fputs("\n", outfile);
  15211. fclose (outfile);
  15212. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15213. }
  15214. void checkTempStopTransaction(int gun_index)
  15215. {
  15216. FILE *fptr1;
  15217. char ch;
  15218. char str[QUEUE_MESSAGE_LENGTH]={0};
  15219. char guid[37]={0};
  15220. char tempdata[65]={0};
  15221. char connectorStr[2]={0};
  15222. char TempStopTransaction[256];
  15223. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  15224. fptr1 = fopen(TempStopTransaction, "r");
  15225. //TempStopTransaction格式: 槍號,StopTransaction封包
  15226. if (!fptr1)
  15227. {
  15228. //printf(" File not found or unable to open the input file!!\n");
  15229. return ;
  15230. }
  15231. ch=fgetc(fptr1);
  15232. //printf(" Now the content of the file %s is : \n",fname);
  15233. rewind(fptr1);
  15234. if(ch!=EOF)
  15235. {
  15236. // copy all contents to the temporary file except the specific line
  15237. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  15238. {
  15239. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15240. if(str[0]=='\0')
  15241. {
  15242. break;
  15243. }
  15244. //TempStopTransaction格式: 槍號,StopTransaction封包
  15245. strncpy(connectorStr, str, 1);
  15246. if(atoi(connectorStr) != (gun_index+1))
  15247. {
  15248. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  15249. fclose(fptr1);
  15250. return ;
  15251. }
  15252. //random_uuid(guid);
  15253. strncpy(guid, str+6, 36); //copy guid
  15254. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  15255. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  15256. {
  15257. //DEBUG_INFO("StopTransaction mapitem pass\n");
  15258. }
  15259. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  15260. OCPP_insert_transaction_msg(NO, str);
  15261. memset(str,0,ARRAY_SIZE(str));
  15262. }
  15263. }
  15264. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  15265. fclose(fptr1);
  15266. remove(TempStopTransaction); // remove the original file
  15267. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15268. }
  15269. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  15270. {
  15271. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  15272. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  15273. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  15274. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  15275. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  15276. }
  15277. int GetWebSocketPingInterval(void)
  15278. {
  15279. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15280. }
  15281. int GetServerSign(void)
  15282. {
  15283. return server_sign;
  15284. }
  15285. uint8_t GetOcppSecurityProfile()
  15286. {
  15287. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15288. }
  15289. void GetOcppChargerBoxId(uint8_t *data)
  15290. {
  15291. sprintf((char*)data, "%s", ShmOCPP16Data->ChargeBoxId);
  15292. }
  15293. void GetOcppSecurityPassword(uint8_t *data)
  15294. {
  15295. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15296. }
  15297. void SetOcppVersion(uint8_t *version)
  15298. {
  15299. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  15300. DEBUG_INFO("ocpp version: %s\n", version);
  15301. if(strstr((char*)version, "ocpp1.6") != NULL)
  15302. {
  15303. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  15304. }
  15305. else if(strstr((char*)version, "ocpp2.0") != NULL)
  15306. {
  15307. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  15308. system("pkill OcppBackend");
  15309. }
  15310. }
  15311. void SetServerSign(int value)
  15312. {
  15313. server_sign = value;
  15314. }
  15315. int GetBootNotificationInterval(void)
  15316. {
  15317. return BootNotificationInterval;
  15318. }
  15319. int GetInternetConn(void)
  15320. {
  15321. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  15322. }
  15323. int GetBackendConnectionTimeout(void)
  15324. {
  15325. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  15326. }
  15327. int isConnectorInitMode(int gun_index)
  15328. {
  15329. int tempIndex = 0;
  15330. int result = TRUE;
  15331. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15332. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15333. {
  15334. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15335. {
  15336. tempIndex = ((gun_index==2) ? 1: 0);
  15337. }
  15338. else
  15339. {
  15340. tempIndex = gun_index;
  15341. }
  15342. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15343. {
  15344. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  15345. {
  15346. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15347. } //end of the same index
  15348. }//end of for CHAdeMO_QUANTITY
  15349. }
  15350. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15351. {
  15352. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15353. {
  15354. tempIndex = ((gun_index==2) ? 1: 0);
  15355. }
  15356. else
  15357. {
  15358. tempIndex = gun_index;
  15359. }
  15360. for (int index = 0; index < CCS_QUANTITY; index++)
  15361. {
  15362. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15363. {
  15364. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15365. } //end of the same index
  15366. } // end of for CCS_QUANTITY
  15367. }
  15368. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15369. {
  15370. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15371. {
  15372. tempIndex = ((gun_index==2) ? 1: 0);
  15373. }
  15374. else
  15375. {
  15376. tempIndex = gun_index;
  15377. }
  15378. for (int index = 0; index < GB_QUANTITY; index++)
  15379. {
  15380. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15381. {
  15382. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15383. } //end of the same index
  15384. } // end of for GB_QUANTITY
  15385. }
  15386. else if(gunType[gun_index] == GUN_TYPE_DO)
  15387. {
  15388. tempIndex = gun_index;
  15389. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15390. {
  15391. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15392. {
  15393. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15394. } //end of the same index
  15395. }
  15396. }
  15397. else
  15398. {
  15399. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15400. {
  15401. tempIndex = 2;
  15402. }
  15403. else
  15404. {
  15405. tempIndex = gun_index;
  15406. }
  15407. for (int index = 0; index < AC_QUANTITY; index++)
  15408. {
  15409. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15410. {
  15411. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15412. }//end of the same index
  15413. }//end of for AC_QUANTITY
  15414. }
  15415. return result;
  15416. }
  15417. void refreshProcDogTimer()
  15418. {
  15419. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  15420. }
  15421. void InitialSystemValue(void)
  15422. {
  15423. int connectorIndex = 0;
  15424. //int valueASCII = 0;
  15425. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  15426. gunTotalNumber=0;
  15427. SystemInitial = 0;
  15428. localversion=0;
  15429. BootNotificationInterval = 0;
  15430. authorizeRetryTimes = 0;
  15431. GunStatusInterval = 10;
  15432. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15433. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15434. //Hear Beat
  15435. HeartBeatWithNOResponse = 0;
  15436. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  15437. FirstHeartBeat = 0;
  15438. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  15439. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  15440. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  15441. memset(statusModeChage, 0, ARRAY_SIZE(statusModeChage));
  15442. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  15443. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  15444. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  15445. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  15446. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  15447. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  15448. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  15449. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  15450. memset(gunType, 0, ARRAY_SIZE(gunType));
  15451. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  15452. {
  15453. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O')
  15454. {
  15455. // DO series
  15456. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  15457. {
  15458. SystemInitial = SystemInitial + 1;
  15459. gunTotalNumber = gunTotalNumber + 1;
  15460. gunType[connectorIndex] = GUN_TYPE_DO;
  15461. connectorIndex = connectorIndex + 1;
  15462. }
  15463. }
  15464. else
  15465. {
  15466. // DM, DW, DS series
  15467. //check connector / socket type (index: 8, 9, 10)
  15468. for(int index=7; index <10 ; index++)
  15469. {
  15470. if(index != 8)
  15471. {
  15472. // DC Connector
  15473. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  15474. {
  15475. SystemInitial = SystemInitial + 1;
  15476. gunTotalNumber = gunTotalNumber + 1;
  15477. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  15478. connectorIndex = connectorIndex + 1;
  15479. }
  15480. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  15481. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  15482. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  15483. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  15484. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  15485. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  15486. {
  15487. SystemInitial = SystemInitial + 1;
  15488. gunTotalNumber = gunTotalNumber + 1;
  15489. gunType[connectorIndex] = GUN_TYPE_CCS;
  15490. connectorIndex = connectorIndex + 1;
  15491. }
  15492. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  15493. {
  15494. SystemInitial = SystemInitial + 1;
  15495. gunTotalNumber = gunTotalNumber + 1;
  15496. gunType[connectorIndex] = GUN_TYPE_GBT;
  15497. connectorIndex = connectorIndex + 1;
  15498. }
  15499. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  15500. {
  15501. SystemInitial = SystemInitial + 1;
  15502. gunTotalNumber = gunTotalNumber + 1;
  15503. gunType[connectorIndex] = GUN_TYPE_DO;
  15504. connectorIndex = connectorIndex + 1;
  15505. }
  15506. }
  15507. else
  15508. {
  15509. // AC Connector
  15510. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  15511. {
  15512. SystemInitial = SystemInitial + 1;
  15513. gunTotalNumber = gunTotalNumber + 1;
  15514. gunType[connectorIndex] = GUN_TYPE_AC;
  15515. connectorIndex = connectorIndex + 1;
  15516. }
  15517. }
  15518. }
  15519. }
  15520. //DEBUG_INFO("DC ...\n");
  15521. }
  15522. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  15523. {
  15524. //check connector / socket type (index: 8, 9, 10)
  15525. for(int index=7; index <10 ; index++)
  15526. {
  15527. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  15528. {
  15529. SystemInitial = SystemInitial + 1;
  15530. gunTotalNumber = gunTotalNumber + 1;
  15531. gunType[connectorIndex] = GUN_TYPE_AC;
  15532. connectorIndex = connectorIndex + 1;
  15533. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  15534. }
  15535. }
  15536. }
  15537. //Status && ConnectorPlugIn Setting
  15538. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15539. {
  15540. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  15541. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  15542. }
  15543. for (int index = 0; index < CCS_QUANTITY; index++)
  15544. {
  15545. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  15546. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  15547. }
  15548. for (int index = 0; index < GB_QUANTITY; index++)
  15549. {
  15550. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  15551. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  15552. }
  15553. for (int index = 0; index < AC_QUANTITY; index++)
  15554. {
  15555. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  15556. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  15557. }
  15558. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15559. {
  15560. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  15561. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  15562. }
  15563. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  15564. {
  15565. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  15566. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  15567. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  15568. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  15569. }
  15570. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  15571. clientTime.Heartbeat=time((time_t*)NULL);
  15572. sleep(1);
  15573. }
  15574. void LWS_Send(char *str)
  15575. {
  15576. //=====================================================
  15577. // Check InternetConn 0: disconnected, 1: connected
  15578. //====================================================
  15579. if(GetOcppConnStatus() == 0)
  15580. {
  15581. DEBUG_INFO("offline now !!!\n");
  15582. return;
  15583. }
  15584. // Only disable isWebsocketSendable operation initiated by charger
  15585. if((strstr((char*)str, "\"Authorize\"") != NULL)
  15586. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  15587. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  15588. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  15589. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  15590. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  15591. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  15592. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  15593. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  15594. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  15595. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  15596. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  15597. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  15598. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  15599. {
  15600. isWebsocketSendable = 0;
  15601. }
  15602. pthread_mutex_lock(&lock_send);
  15603. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  15604. sprintf((char *)SendBuffer, "%s", str);
  15605. SendBufLen = strlen(str);
  15606. pthread_mutex_unlock(&lock_send);
  15607. lws_callback_on_writable(wsi_client);
  15608. //lws_service(context, 0);
  15609. //sleep(1);
  15610. }
  15611. void LWS_SendNow(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. }