MessageHandler.c 692 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. //ConfigurationMaxKeys
  12. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  13. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  14. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  15. //=================================
  16. // StatusNotification cycle
  17. //=================================
  18. static int server_cycle_Status = 120;
  19. //===============================
  20. // Configuration: unknownkey
  21. //===============================
  22. static char unknownkey[10][20] = {0};
  23. static int UnknownKeynum = 0;
  24. //===============================
  25. // Gun Total Numbers
  26. //===============================
  27. static int gunTotalNumber = 0;
  28. static uint8_t gunType[4] = {0};
  29. //===============================
  30. // Local List Version
  31. //===============================
  32. static int localversion=0;
  33. static char idTagAuthorization[32] = {0};
  34. //===============================
  35. // OCPP sign variable
  36. //===============================
  37. static int server_sign = FALSE;
  38. int server_pending = FALSE;
  39. static int BootNotificationInterval = 0;
  40. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  41. //===============================
  42. // OCPP auth variable
  43. //===============================
  44. static int authorizeRetryTimes = 0; //number of Retry times
  45. //===============================
  46. // OCPP other variables
  47. //===============================
  48. static int HeartBeatWaitTime = 10;
  49. static int FirstHeartBeat = 0;
  50. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  51. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  52. static char CurrentChargingProfileScheduleStr[30] = {0};
  53. //========================================
  54. // OCPP status/previous related variables
  55. //========================================
  56. static int GunStatusInterval = 10;
  57. static uint8_t statusModeChage[CONNECTOR_QUANTITY] = {FALSE};
  58. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  59. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  60. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  61. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  62. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  63. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  64. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  65. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  66. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  67. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  68. static int TransactionMessageAttemptsValue = 0;
  69. static int TransactionMessageRetryIntervalValue = 0;
  70. static int TempMeterValueInterval = 0;
  71. static struct OCPPAuthLocalElemet
  72. {
  73. int listVersionInt;
  74. char idTagstr[20];
  75. char parentIdTag[20];
  76. char expiryDate[30];
  77. char idTagstatus[16];
  78. }idTagQuery;
  79. //=============================================
  80. // OCPP HeartBeat Response Not Receive Counts
  81. //============================================
  82. static int HeartBeatWithNOResponse = 0;
  83. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  84. extern sqlite3 *db;
  85. int TransactionMessageAttemptsGet(void);
  86. int TransactionMessageRetryIntervalGet(void);
  87. int GetOcppConnStatus(void);
  88. void SetOcppConnStatus(uint8_t status);
  89. int setKeyValue(char *key, char *value);
  90. void OCPP_get_TableAuthlocalAllData(void);
  91. void processUnkownKey(void);
  92. struct StructOCPPMeterValue
  93. {
  94. unsigned char TimeStamp[28];
  95. struct StructSampledValue SampledValue[10];
  96. };
  97. struct ClientTime
  98. {
  99. unsigned int Heartbeat;
  100. unsigned int StatusNotification[CONNECTOR_QUANTITY];
  101. unsigned int StartTransaction;
  102. unsigned int StopTransaction;
  103. unsigned int MeterValues[CONNECTOR_QUANTITY];
  104. }clientTime;
  105. typedef union
  106. {
  107. //Operations Initiated by Central System
  108. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  109. struct
  110. {
  111. //CsMsgValue[0]
  112. unsigned char StatusNotificationReq:1; //bit 0,
  113. unsigned char StatusNotificationConf:1; //bit 1,
  114. unsigned char TriggerMeterValue:1; //bit 2,
  115. unsigned char :5; //bit 5~7
  116. }bits[CONNECTOR_QUANTITY];
  117. }CpinitiateMsg;
  118. CpinitiateMsg cpinitateMsg;
  119. //GetConfiguration Array
  120. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  121. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  122. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  123. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  124. #if 0
  125. static char *ChargePointErrorCodeStr[] = {
  126. MACROSTR(ConnectorLockFailure),
  127. MACROSTR(EVCommunicationError),
  128. MACROSTR(GroundFailure),
  129. MACROSTR(HighTemperature),
  130. MACROSTR(InternalError),
  131. MACROSTR(LocalListConflict),
  132. MACROSTR(NoError),
  133. MACROSTR(OtherError),
  134. MACROSTR(OverCurrentFailure),
  135. MACROSTR(OverVoltage),
  136. MACROSTR(PowerMeterFailure),
  137. MACROSTR(PowerSwitchFailure),
  138. MACROSTR(ReaderFailure),
  139. MACROSTR(ResetFailure),
  140. MACROSTR(UnderVoltage),
  141. MACROSTR(WeakSignal)
  142. };
  143. #endif
  144. static char * ChargePointStatusStr[] = {
  145. MACROSTR(Available),
  146. MACROSTR(Preparing),
  147. MACROSTR(Charging),
  148. MACROSTR(SuspendedEVSE),
  149. MACROSTR(SuspendedEV),
  150. MACROSTR(Finishing),
  151. MACROSTR(Reserved),
  152. MACROSTR(Unavailable),
  153. MACROSTR(Faulted)
  154. };
  155. static char *RegistrationStatusStr[] = {
  156. MACROSTR(Accepted),
  157. MACROSTR(Pending),
  158. MACROSTR(Rejected)
  159. };
  160. static char *AvailabilityTypeStr[] = {
  161. MACROSTR(Inoperative),
  162. MACROSTR(Operative)
  163. };
  164. static char *AvailabilityStatusStr[] = {
  165. MACROSTR(Accepted),
  166. MACROSTR(Rejected),
  167. MACROSTR(Scheduled)
  168. };
  169. static char *ConfigurationStatusStr[] = {
  170. MACROSTR(Accepted),
  171. MACROSTR(Rejected),
  172. MACROSTR(RebootRequired),
  173. MACROSTR(NotSupported)
  174. };
  175. static char *ClearCacheStatusStr[] = {
  176. MACROSTR(Accepted),
  177. MACROSTR(Rejected)
  178. };
  179. static char *ChargingProfilePurposeTypeStr[] = {
  180. MACROSTR(ChargePointMaxProfile),
  181. MACROSTR(TxDefaultProfile),
  182. MACROSTR(TxProfile)
  183. };
  184. static char *ChargingProfileStatusStr[] = {
  185. MACROSTR(Accepted),
  186. MACROSTR(Rejected),
  187. MACROSTR(NotSupported)
  188. };
  189. static char *ClearChargingProfileStatusStr[] = {
  190. MACROSTR(Accepted),
  191. MACROSTR(Unknown)
  192. };
  193. static char *GetCompositeScheduleStatusStr[] = {
  194. MACROSTR(Accepted),
  195. MACROSTR(Rejected)
  196. };
  197. static char *UpdateTypeStr[] = {
  198. MACROSTR(Differential),
  199. MACROSTR(Full)
  200. };
  201. static char *UpdateStatusStr[] = {
  202. MACROSTR(Accepted),
  203. MACROSTR(Failed),
  204. MACROSTR(NotSupported),
  205. MACROSTR(VersionMismatch)
  206. };
  207. static char *RemoteStartStopStatusStr[] = {
  208. MACROSTR(Accepted),
  209. MACROSTR(Rejected)
  210. };
  211. static char *ReservationStatusStr[] = {
  212. MACROSTR(Accepted),
  213. MACROSTR(Faulted),
  214. MACROSTR(Occupied),
  215. MACROSTR(Rejected),
  216. MACROSTR(Unavailable)
  217. };
  218. static char *ResetTypeStr[] = {
  219. MACROSTR(Hard),
  220. MACROSTR(Soft)
  221. };
  222. static char *ResetStatusStr[] = {
  223. MACROSTR(Accepted),
  224. MACROSTR(Rejected)
  225. };
  226. static char * DiagnosticsStatusStr[] = {
  227. MACROSTR(Idle),
  228. MACROSTR(Uploaded),
  229. MACROSTR(UploadFailed),
  230. MACROSTR(Uploading)
  231. };
  232. static char * FirmwareStatusStr[] = {
  233. MACROSTR(Downloaded),
  234. MACROSTR(DownloadFailed),
  235. MACROSTR(Downloading),
  236. MACROSTR(Idle),
  237. MACROSTR(InstallationFailed),
  238. MACROSTR(Installing),
  239. MACROSTR(Installed)
  240. };
  241. static char * MessageTriggerStr[] = {
  242. MACROSTR(BootNotification),
  243. MACROSTR(DiagnosticsStatusNotification),
  244. MACROSTR(FirmwareStatusNotification),
  245. MACROSTR(Heartbeat),
  246. MACROSTR(MeterValues),
  247. MACROSTR(StatusNotification)
  248. };
  249. static char * TriggerMessageStatusStr[] = {
  250. MACROSTR(Accepted),
  251. MACROSTR(Rejected),
  252. MACROSTR(NotImplemented)
  253. };
  254. static char * UnlockStatusStr[] = {
  255. MACROSTR(Unlocked),
  256. MACROSTR(UnlockFailed),
  257. MACROSTR(NotSupported)
  258. };
  259. #if 0
  260. static char * StopTransactionReasonStr[] = {
  261. MACROSTR(EmergencyStop),
  262. MACROSTR(EVDisconnected),
  263. MACROSTR(HardReset),
  264. MACROSTR(Local),
  265. MACROSTR(Other),
  266. MACROSTR(PowerLoss),
  267. MACROSTR(Reboot),
  268. MACROSTR(Remote),
  269. MACROSTR(SoftReset),
  270. MACROSTR(UnlockCommand),
  271. MACROSTR(DeAuthorized)
  272. };
  273. #endif
  274. static char * CancelReservationStatusStr[] = {
  275. MACROSTR(Accepted),
  276. MACROSTR(Rejected)
  277. };
  278. static char * ReadingContextStr[] = {
  279. MACROSTR(Interruption.Begin),
  280. MACROSTR(Interruption.End),
  281. MACROSTR(Other),
  282. MACROSTR(Sample.Clock),
  283. MACROSTR(Sample.Periodic),
  284. MACROSTR(Transaction.Begin),
  285. MACROSTR(Transaction.End),
  286. MACROSTR(Trigger)
  287. };
  288. static char * ValueFormatStr[] = {
  289. MACROSTR(Raw),
  290. MACROSTR(SignedData)
  291. };
  292. static char * MeasurandStr[] = {
  293. MACROSTR(Current.Export),
  294. MACROSTR(Current.Import),
  295. MACROSTR(Current.Offered),
  296. MACROSTR(Energy.Active.Export.Register),
  297. MACROSTR(Energy.Active.Import.Register),
  298. MACROSTR(Energy.Reactive.Export.Register),
  299. MACROSTR(Energy.Reactive.Import.Register),
  300. MACROSTR(Energy.Active.Export.Interval),
  301. MACROSTR(Energy.Active.Import.Interval),
  302. MACROSTR(Energy.Reactive.Export.Interval),
  303. MACROSTR(Energy.Reactive.Import.Interval),
  304. MACROSTR(Frequency),
  305. MACROSTR(Power.Active.Export),
  306. MACROSTR(Power.Active.Import),
  307. MACROSTR(Power.Factor),
  308. MACROSTR(Power.Offered),
  309. MACROSTR(Power.Reactive.ExportMACROSTR),
  310. MACROSTR(Power.Reactive.Import),
  311. MACROSTR(RPM),
  312. MACROSTR(SoC),
  313. MACROSTR(Temperature),
  314. MACROSTR(Voltage)
  315. };
  316. static char * LocationStr[] = {
  317. MACROSTR(Body),
  318. MACROSTR(Cable),
  319. MACROSTR(EV),
  320. MACROSTR(Inlet),
  321. MACROSTR(Outlet)
  322. };
  323. static char * PhaseStr[] = {
  324. MACROSTR(L1),
  325. MACROSTR(L2),
  326. MACROSTR(L3),
  327. MACROSTR(N),
  328. MACROSTR(L1-N),
  329. MACROSTR(L2-N),
  330. MACROSTR(L3-N),
  331. MACROSTR(L1-L2),
  332. MACROSTR(L2-L3),
  333. MACROSTR(L3-L1)
  334. };
  335. static char * UnitOfMeasureStr[] = {
  336. MACROSTR(Wh),
  337. MACROSTR(kWh),
  338. MACROSTR(varh),
  339. MACROSTR(kvarh),
  340. MACROSTR(W),
  341. MACROSTR(kW),
  342. MACROSTR(VA),
  343. MACROSTR(kVA),
  344. MACROSTR(var),
  345. MACROSTR(kvar),
  346. MACROSTR(A),
  347. MACROSTR(V),
  348. MACROSTR(Celsius),
  349. MACROSTR(Fahrenheit),
  350. MACROSTR(K),
  351. MACROSTR(Percent)
  352. };
  353. //==========================================
  354. // Check time passed since today
  355. //==========================================
  356. long long DiffTimebWithNow(struct timeb ST)
  357. {
  358. //return milli-second
  359. struct timeb ET;
  360. long long StartTime,StopTime;
  361. ftime(&ET);
  362. StartTime=(long long)ST.time;
  363. StopTime=(long long)ET.time;
  364. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  365. }
  366. int getTimePassSinceToday()
  367. {
  368. int result = -1;
  369. static time_t lastTime;
  370. time_t t;
  371. struct tm *tmStartToday;
  372. struct timeb tbStartToday;
  373. t=time(NULL);
  374. if(difftime(t, lastTime)>0)
  375. {
  376. tmStartToday=localtime(&t);
  377. tmStartToday->tm_hour = 0;
  378. tmStartToday->tm_min = 0;
  379. tmStartToday->tm_sec = 0;
  380. tbStartToday.time = mktime(tmStartToday);
  381. tbStartToday.millitm = 0;
  382. result = DiffTimebWithNow(tbStartToday)/1000;
  383. lastTime = t;
  384. }
  385. return result;
  386. }
  387. void getNowDatetime(uint8_t *data)
  388. {
  389. time_t t = time(NULL);
  390. struct tm tm = *localtime(&t);
  391. 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);
  392. }
  393. //==========================================
  394. // GetCompositeSchedule logic related function
  395. //==========================================
  396. int DiffTimebSec(struct timeb ST, struct timeb ET)
  397. {
  398. //return milli-second
  399. unsigned int StartTime,StopTime;
  400. StartTime=(unsigned int)ST.time;
  401. StopTime=(unsigned int)ET.time;
  402. return (StopTime-StartTime);
  403. }
  404. int DiffTimebWithNowSec(struct timeb ST)
  405. {
  406. //return milli-second
  407. struct timeb ET;
  408. unsigned int StartTime,StopTime;
  409. ftime(&ET);
  410. StartTime=(unsigned int)ST.time;
  411. StopTime=(unsigned int)ET.time;
  412. return (StopTime-StartTime);
  413. }
  414. int getStartStop(uint8_t *start, uint8_t *stop)
  415. {
  416. int result = -1;
  417. struct tm tmStart;
  418. struct timeb tbStart;
  419. struct tm tmStop;
  420. struct timeb tbStop;
  421. 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) &&
  422. (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))
  423. {
  424. //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);
  425. //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);
  426. tmStart.tm_year -= 1900;
  427. tmStart.tm_mon -= 1;
  428. tbStart.time = mktime(&tmStart);
  429. tbStart.millitm = 0;
  430. tmStop.tm_year -= 1900;
  431. tmStop.tm_mon -= 1;
  432. tbStop.time = mktime(&tmStop);
  433. tbStop.millitm = 0;
  434. result = DiffTimebSec(tbStart, tbStop);
  435. //DEBUG_INFO("getStartStop(): %d\n", result);
  436. }
  437. else
  438. {
  439. DEBUG_WARN("Start or stop date parsing error.\r\n");
  440. }
  441. return result;
  442. }
  443. int isOvertNow(uint8_t *start)
  444. {
  445. int result = YES;
  446. struct tm tmStart;
  447. struct timeb tbStart;
  448. 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))
  449. {
  450. //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);
  451. tmStart.tm_year -= 1900;
  452. tmStart.tm_mon -= 1;
  453. tbStart.time = mktime(&tmStart);
  454. tbStart.millitm = 0;
  455. if(DiffTimebWithNowSec(tbStart) <= 0)
  456. result = NO;
  457. }
  458. else
  459. {
  460. DEBUG_WARN("Start date parsing error.\r\n");
  461. }
  462. return result;
  463. }
  464. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  465. {
  466. int result = -1;
  467. struct tm tmStart;
  468. struct timeb tbStart;
  469. struct tm tmStop;
  470. struct timeb tbStop;
  471. 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) &&
  472. (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))
  473. {
  474. tmStart.tm_year -= 1900;
  475. tmStart.tm_mon -= 1;
  476. tbStart.time = mktime(&tmStart);
  477. tbStart.millitm = 0;
  478. tmStop.tm_year -= 1900;
  479. tmStop.tm_mon -= 1;
  480. tbStop.time = mktime(&tmStop);
  481. tbStop.millitm = 0;
  482. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  483. }
  484. return result;
  485. }
  486. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile)
  487. {
  488. FILE *fp;
  489. char profileFileName[128];
  490. char *line = NULL;
  491. size_t len = 0;
  492. time_t CurrentTime;
  493. struct tm *tmComposite;
  494. struct StructChargingProfile maxProfile;
  495. struct StructChargingProfile defaultTxProfile;
  496. struct StructChargingProfile txProfile;
  497. struct StructChargingSchedulePeriod tmpPeriod;
  498. uint8_t limitMax=0;
  499. uint8_t limitDef=0;
  500. uint8_t limitTx=0;
  501. int compositePeriodIdx = 0;
  502. CurrentTime = time(NULL);
  503. tmComposite=localtime(&CurrentTime);
  504. 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);
  505. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  506. compositeProfile->ChargingSchedule.Duration = durationReq;
  507. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  508. {
  509. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  510. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  511. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  512. }
  513. compositeProfile->ChargingProfileId = 0;
  514. compositeProfile->StackLevel = 99 ;
  515. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  516. maxProfile.ChargingProfileId = -1;
  517. defaultTxProfile.ChargingProfileId = -1;
  518. txProfile.ChargingProfileId = -1;
  519. maxProfile.ChargingSchedule.Duration = -1;
  520. defaultTxProfile.ChargingSchedule.Duration = -1;
  521. txProfile.ChargingSchedule.Duration = -1;
  522. system("yes|rm /tmp/*.json");
  523. system("cp /Storage/OCPP/*.json /tmp");
  524. /*
  525. * Search valid charging profile
  526. */
  527. //DEBUG_INFO("====================================\n");
  528. // Search tx profile
  529. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  530. if((access(profileFileName, F_OK))!=-1)
  531. {
  532. fp = fopen(profileFileName, "r");
  533. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  534. {
  535. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  536. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  537. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  538. }
  539. txProfile.ChargingProfileId = -1;
  540. txProfile.StackLevel = -1;
  541. while(getline(&line, &len, fp) != -1)
  542. {
  543. json_object *obj = NULL;
  544. obj = json_tokener_parse(line);
  545. if(is_error(obj))
  546. {
  547. DEBUG_ERROR("Parse txProfile from file error.\n");
  548. }
  549. else
  550. {
  551. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  552. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  553. )
  554. {
  555. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  556. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  557. )
  558. {
  559. struct tm tmFrom, tmTo;
  560. struct timeb tbFrom, tbTo;
  561. 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) &&
  562. (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))
  563. {
  564. tmFrom.tm_year -= 1900;
  565. tmFrom.tm_mon -= 1;
  566. tbFrom.time = mktime(&tmFrom);
  567. tmTo.tm_year -= 1900;
  568. tmTo.tm_mon -= 1;
  569. tbTo.time = mktime(&tmTo);
  570. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  571. {
  572. if(txProfile.ChargingProfileId == -1)
  573. DEBUG_INFO("TxProfile found.\n");
  574. else
  575. DEBUG_INFO("TxProfile updated.\n");
  576. // Required item
  577. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  578. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  579. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  580. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  581. 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++)
  582. {
  583. 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"));
  584. 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: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")));
  585. 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?
  586. 3:
  587. 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")));
  588. }
  589. // Optional item
  590. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  591. {
  592. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  593. }
  594. else
  595. {
  596. sprintf((char*)txProfile.ValidFrom, " ");
  597. }
  598. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  599. {
  600. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  601. }
  602. else
  603. {
  604. sprintf((char*)txProfile.ValidTo, " ");
  605. }
  606. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  607. {
  608. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  609. }
  610. else
  611. {
  612. sprintf((char*)txProfile.RecurrencyKind, " ");
  613. }
  614. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  615. {
  616. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  617. }
  618. else
  619. {
  620. txProfile.TransactionId = -1;
  621. }
  622. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  623. {
  624. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  625. }
  626. else
  627. {
  628. txProfile.ChargingSchedule.Duration = 86400;
  629. }
  630. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  631. {
  632. 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")));
  633. }
  634. else
  635. {
  636. 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));
  637. }
  638. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  639. {
  640. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  641. }
  642. else
  643. {
  644. txProfile.ChargingSchedule.MinChargingRate = -1;
  645. }
  646. }
  647. }
  648. }
  649. else
  650. {
  651. if(txProfile.ChargingProfileId == -1)
  652. DEBUG_INFO("TxProfile found.\n");
  653. else
  654. DEBUG_INFO("TxProfile updated.\n");
  655. // Required item
  656. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  657. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  658. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  659. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  660. 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++)
  661. {
  662. 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"));
  663. 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: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")));
  664. 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?
  665. 3:
  666. 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")));
  667. }
  668. // Optional item
  669. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  670. {
  671. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  672. }
  673. else
  674. {
  675. sprintf((char*)txProfile.ValidFrom, " ");
  676. }
  677. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  678. {
  679. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  680. }
  681. else
  682. {
  683. sprintf((char*)txProfile.ValidTo, " ");
  684. }
  685. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  686. {
  687. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  688. }
  689. else
  690. {
  691. sprintf((char*)txProfile.RecurrencyKind, " ");
  692. }
  693. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  694. {
  695. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  696. }
  697. else
  698. {
  699. txProfile.TransactionId = -1;
  700. }
  701. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  702. {
  703. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  704. }
  705. else
  706. {
  707. txProfile.ChargingSchedule.Duration = 86400;
  708. }
  709. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  710. {
  711. 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")));
  712. }
  713. else
  714. {
  715. 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));
  716. }
  717. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  718. {
  719. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  720. }
  721. else
  722. {
  723. txProfile.ChargingSchedule.MinChargingRate = -1;
  724. }
  725. }
  726. }
  727. }
  728. json_object_put(obj);
  729. }
  730. fclose(fp);
  731. /*
  732. if(txProfile.ChargingProfileId != -1)
  733. {
  734. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  735. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  736. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  737. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  738. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  739. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  740. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  741. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  742. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  743. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  744. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  745. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  746. {
  747. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  748. {
  749. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  750. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  751. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  752. }
  753. }
  754. }
  755. else
  756. DEBUG_INFO("TxProfile not found.\n");*/
  757. }
  758. // Search default tx profile
  759. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  760. if((access(profileFileName, F_OK))==-1)
  761. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  762. if((access(profileFileName, F_OK))!=-1)
  763. {
  764. fp = fopen(profileFileName, "r");
  765. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  766. {
  767. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  768. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  769. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  770. }
  771. defaultTxProfile.ChargingProfileId = -1;
  772. defaultTxProfile.StackLevel = -1;
  773. while(getline(&line, &len, fp) != -1)
  774. {
  775. json_object *obj = NULL;
  776. obj = json_tokener_parse(line);
  777. if(is_error(obj))
  778. {
  779. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  780. }
  781. else
  782. {
  783. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  784. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  785. )
  786. {
  787. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  788. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  789. )
  790. {
  791. struct tm tmFrom, tmTo;
  792. struct timeb tbFrom, tbTo;
  793. 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) &&
  794. (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))
  795. {
  796. tmFrom.tm_year -= 1900;
  797. tmFrom.tm_mon -= 1;
  798. tbFrom.time = mktime(&tmFrom);
  799. tmTo.tm_year -= 1900;
  800. tmTo.tm_mon -= 1;
  801. tbTo.time = mktime(&tmTo);
  802. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  803. {
  804. if(defaultTxProfile.ChargingProfileId == -1)
  805. DEBUG_INFO("TxDefaultProfile found.\n");
  806. else
  807. DEBUG_INFO("TxDefaultProfile updated.\n");
  808. // Required item
  809. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  810. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  811. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  812. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  813. 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++)
  814. {
  815. 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"));
  816. 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: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")));
  817. 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?
  818. 3:
  819. 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")));
  820. }
  821. // Optional item
  822. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  823. {
  824. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  825. }
  826. else
  827. {
  828. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  829. }
  830. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  831. {
  832. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  833. }
  834. else
  835. {
  836. sprintf((char*)defaultTxProfile.ValidTo, " ");
  837. }
  838. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  839. {
  840. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  841. }
  842. else
  843. {
  844. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  845. }
  846. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  847. {
  848. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  849. }
  850. else
  851. {
  852. defaultTxProfile.TransactionId = -1;
  853. }
  854. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  855. {
  856. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  857. }
  858. else
  859. {
  860. defaultTxProfile.ChargingSchedule.Duration = 86400;
  861. }
  862. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  863. {
  864. 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")));
  865. }
  866. else
  867. {
  868. 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));
  869. }
  870. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  871. {
  872. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  873. }
  874. else
  875. {
  876. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  877. }
  878. }
  879. }
  880. }
  881. else
  882. {
  883. if(defaultTxProfile.ChargingProfileId == -1)
  884. DEBUG_INFO("TxDefaultProfile found.\n");
  885. else
  886. DEBUG_INFO("TxDefaultProfile updated.\n");
  887. // Required item
  888. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  889. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  890. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  891. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  892. 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++)
  893. {
  894. 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"));
  895. 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: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")));
  896. 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?
  897. 3:
  898. 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")));
  899. }
  900. // Optional item
  901. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  902. {
  903. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  904. }
  905. else
  906. {
  907. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  908. }
  909. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  910. {
  911. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  912. }
  913. else
  914. {
  915. sprintf((char*)defaultTxProfile.ValidTo, " ");
  916. }
  917. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  918. {
  919. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  920. }
  921. else
  922. {
  923. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  924. }
  925. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  926. {
  927. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  928. }
  929. else
  930. {
  931. defaultTxProfile.TransactionId = -1;
  932. }
  933. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  934. {
  935. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  936. }
  937. else
  938. {
  939. defaultTxProfile.ChargingSchedule.Duration = 86400;
  940. }
  941. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  942. {
  943. 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")));
  944. }
  945. else
  946. {
  947. 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));
  948. }
  949. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  950. {
  951. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  952. }
  953. else
  954. {
  955. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  956. }
  957. }
  958. }
  959. }
  960. json_object_put(obj);
  961. }
  962. fclose(fp);
  963. /*
  964. if(defaultTxProfile.ChargingProfileId != -1)
  965. {
  966. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  967. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  968. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  969. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  970. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  971. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  972. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  973. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  974. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  975. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  976. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  977. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  978. {
  979. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  980. {
  981. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  982. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  983. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  984. }
  985. }
  986. }
  987. else
  988. DEBUG_INFO("TxDefaultProfile not found.\n");
  989. DEBUG_INFO("------------------------------------\n");*/
  990. }
  991. // Search max profile
  992. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  993. if((access(profileFileName, F_OK))!=-1)
  994. {
  995. fp = fopen(profileFileName, "r");
  996. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  997. {
  998. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  999. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1000. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1001. }
  1002. maxProfile.ChargingProfileId = -1;
  1003. maxProfile.StackLevel = -1;
  1004. while(getline(&line, &len, fp) != -1)
  1005. {
  1006. json_object *obj = NULL;
  1007. obj = json_tokener_parse(line);
  1008. if(is_error(obj))
  1009. {
  1010. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1011. }
  1012. else
  1013. {
  1014. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  1015. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1016. )
  1017. {
  1018. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1019. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1020. )
  1021. {
  1022. struct tm tmFrom, tmTo;
  1023. struct timeb tbFrom, tbTo;
  1024. 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) &&
  1025. (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))
  1026. {
  1027. tmFrom.tm_year -= 1900;
  1028. tmFrom.tm_mon -= 1;
  1029. tbFrom.time = mktime(&tmFrom);
  1030. tmTo.tm_year -= 1900;
  1031. tmTo.tm_mon -= 1;
  1032. tbTo.time = mktime(&tmTo);
  1033. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1034. {
  1035. if(maxProfile.ChargingProfileId == -1)
  1036. DEBUG_INFO("MaxProfile found.\n");
  1037. else
  1038. DEBUG_INFO("MaxProfile updated.\n");
  1039. // Required item
  1040. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1041. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1042. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1043. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1044. 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++)
  1045. {
  1046. 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"));
  1047. 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: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")));
  1048. 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?
  1049. 3:
  1050. 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")));
  1051. }
  1052. // Optional item
  1053. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1054. {
  1055. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1056. }
  1057. else
  1058. {
  1059. sprintf((char*)maxProfile.ValidFrom, " ");
  1060. }
  1061. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1062. {
  1063. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1064. }
  1065. else
  1066. {
  1067. sprintf((char*)maxProfile.ValidTo, " ");
  1068. }
  1069. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1070. {
  1071. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1072. }
  1073. else
  1074. {
  1075. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1076. }
  1077. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1078. {
  1079. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1080. }
  1081. else
  1082. {
  1083. maxProfile.TransactionId = -1;
  1084. }
  1085. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1086. {
  1087. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1088. }
  1089. else
  1090. {
  1091. maxProfile.ChargingSchedule.Duration = 86400;
  1092. }
  1093. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1094. {
  1095. 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")));
  1096. }
  1097. else
  1098. {
  1099. 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));
  1100. }
  1101. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1102. {
  1103. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1104. }
  1105. else
  1106. {
  1107. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1108. }
  1109. }
  1110. }
  1111. }
  1112. else
  1113. {
  1114. if(maxProfile.ChargingProfileId == -1)
  1115. DEBUG_INFO("MaxProfile found.\n");
  1116. else
  1117. DEBUG_INFO("MaxProfile updated.\n");
  1118. // Required item
  1119. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1120. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1121. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1122. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1123. 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++)
  1124. {
  1125. 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"));
  1126. 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: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")));
  1127. 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?
  1128. 3:
  1129. 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")));
  1130. }
  1131. // Optional item
  1132. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1133. {
  1134. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1135. }
  1136. else
  1137. {
  1138. sprintf((char*)maxProfile.ValidFrom, " ");
  1139. }
  1140. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1141. {
  1142. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1143. }
  1144. else
  1145. {
  1146. sprintf((char*)maxProfile.ValidTo, " ");
  1147. }
  1148. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1149. {
  1150. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1151. }
  1152. else
  1153. {
  1154. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1155. }
  1156. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1157. {
  1158. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1159. }
  1160. else
  1161. {
  1162. maxProfile.TransactionId = -1;
  1163. }
  1164. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1165. {
  1166. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1167. }
  1168. else
  1169. {
  1170. maxProfile.ChargingSchedule.Duration = 86400;
  1171. }
  1172. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1173. {
  1174. 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")));
  1175. }
  1176. else
  1177. {
  1178. 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));
  1179. }
  1180. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1181. {
  1182. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1183. }
  1184. else
  1185. {
  1186. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1187. }
  1188. }
  1189. }
  1190. }
  1191. json_object_put(obj);
  1192. }
  1193. fclose(fp);
  1194. /*
  1195. if(maxProfile.ChargingProfileId !=-1)
  1196. {
  1197. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1198. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1199. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1200. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1201. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1202. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1203. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1204. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1205. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1206. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1207. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1208. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1209. {
  1210. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1211. {
  1212. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1213. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1214. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1215. }
  1216. }
  1217. }
  1218. else
  1219. DEBUG_INFO("MaxProfile not found.\n");
  1220. DEBUG_INFO("------------------------------------\n");*/
  1221. }
  1222. /*
  1223. * Align found profile start schedule & periods
  1224. */
  1225. //DEBUG_INFO("====================================\n");
  1226. /*
  1227. // For local test usage, force modify found profile start schedule info
  1228. 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);
  1229. 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);
  1230. 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);
  1231. */
  1232. if(txProfile.ChargingProfileId != -1)
  1233. {
  1234. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  1235. {
  1236. if(txProfile.ChargingSchedule.Duration != -1)
  1237. {
  1238. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1239. 0:
  1240. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1241. }
  1242. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1243. {
  1244. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1245. {
  1246. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1247. 0:
  1248. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1249. if(idxPeriod > 0)
  1250. {
  1251. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1252. {
  1253. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1254. }
  1255. }
  1256. }
  1257. }
  1258. }
  1259. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  1260. {
  1261. if(txProfile.ChargingSchedule.Duration != -1)
  1262. {
  1263. 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?
  1264. 0:
  1265. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1266. }
  1267. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1268. {
  1269. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1270. {
  1271. 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?
  1272. 0:
  1273. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1274. if(idxPeriod > 0)
  1275. {
  1276. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1277. {
  1278. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1279. }
  1280. }
  1281. }
  1282. }
  1283. }
  1284. else
  1285. {
  1286. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  1287. {
  1288. if(txProfile.ChargingSchedule.Duration != -1)
  1289. {
  1290. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1291. 0:
  1292. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1293. }
  1294. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1295. {
  1296. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1297. {
  1298. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1299. 0:
  1300. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1301. if(idxPeriod > 0)
  1302. {
  1303. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1304. {
  1305. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1306. }
  1307. }
  1308. }
  1309. }
  1310. }
  1311. else
  1312. {
  1313. if(txProfile.ChargingSchedule.Duration != -1)
  1314. {
  1315. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1316. 0:
  1317. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1318. }
  1319. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1320. {
  1321. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1322. {
  1323. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1324. 0:
  1325. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1326. if(idxPeriod > 0)
  1327. {
  1328. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1329. {
  1330. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1331. }
  1332. }
  1333. }
  1334. }
  1335. }
  1336. }
  1337. /*
  1338. DEBUG_INFO("txProfile after align.\n");
  1339. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1340. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1341. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1342. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1343. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1344. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1345. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1346. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1347. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1348. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1349. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1350. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1351. {
  1352. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1353. {
  1354. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1355. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1356. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1357. }
  1358. }*/
  1359. }
  1360. if(defaultTxProfile.ChargingProfileId != -1)
  1361. {
  1362. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  1363. {
  1364. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1365. {
  1366. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1367. 0:
  1368. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1369. }
  1370. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1371. {
  1372. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1373. {
  1374. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1375. 0:
  1376. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1377. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1378. {
  1379. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1380. }
  1381. if(idxPeriod > 0)
  1382. {
  1383. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1384. {
  1385. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1386. }
  1387. }
  1388. }
  1389. }
  1390. }
  1391. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  1392. {
  1393. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1394. {
  1395. 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?
  1396. 0:
  1397. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1398. }
  1399. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1400. {
  1401. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1402. {
  1403. 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?
  1404. 0:
  1405. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1406. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1407. {
  1408. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1409. }
  1410. if(idxPeriod > 0)
  1411. {
  1412. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1413. {
  1414. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1415. }
  1416. }
  1417. }
  1418. }
  1419. }
  1420. else
  1421. {
  1422. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  1423. {
  1424. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1425. {
  1426. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1427. 0:
  1428. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1429. }
  1430. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1431. {
  1432. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1433. {
  1434. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1435. 0:
  1436. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1437. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1438. {
  1439. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1440. }
  1441. if(idxPeriod > 0)
  1442. {
  1443. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1444. {
  1445. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1446. }
  1447. }
  1448. }
  1449. }
  1450. }
  1451. else
  1452. {
  1453. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1454. {
  1455. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1456. 0:
  1457. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1458. }
  1459. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1460. {
  1461. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1462. {
  1463. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1464. 0:
  1465. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1466. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1467. {
  1468. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1469. }
  1470. if(idxPeriod > 0)
  1471. {
  1472. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1473. {
  1474. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1475. }
  1476. }
  1477. }
  1478. }
  1479. }
  1480. }
  1481. /*
  1482. DEBUG_INFO("defaultTxProfile after align.\n");
  1483. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1484. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1485. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1486. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1487. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1488. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1489. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1490. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1491. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1492. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1493. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1494. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1495. {
  1496. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1497. {
  1498. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1499. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1500. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1501. }
  1502. }
  1503. DEBUG_INFO("------------------------------------\n");*/
  1504. }
  1505. if(maxProfile.ChargingProfileId != -1)
  1506. {
  1507. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1508. {
  1509. if(maxProfile.ChargingSchedule.Duration != -1)
  1510. {
  1511. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1512. 0:
  1513. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1514. }
  1515. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1516. {
  1517. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1518. {
  1519. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1520. 0:
  1521. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1522. if(idxPeriod > 0)
  1523. {
  1524. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1525. {
  1526. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1527. }
  1528. }
  1529. }
  1530. }
  1531. }
  1532. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1533. {
  1534. if(maxProfile.ChargingSchedule.Duration != -1)
  1535. {
  1536. 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?
  1537. 0:
  1538. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1539. }
  1540. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1541. {
  1542. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1543. {
  1544. 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?
  1545. 0:
  1546. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1547. if(idxPeriod > 0)
  1548. {
  1549. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1550. {
  1551. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1552. }
  1553. }
  1554. }
  1555. }
  1556. }
  1557. else
  1558. {
  1559. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1560. {
  1561. if(maxProfile.ChargingSchedule.Duration != -1)
  1562. {
  1563. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1564. 0:
  1565. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1566. }
  1567. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1568. {
  1569. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1570. {
  1571. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1572. 0:
  1573. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1574. if(idxPeriod > 0)
  1575. {
  1576. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1577. {
  1578. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1579. }
  1580. }
  1581. }
  1582. }
  1583. }
  1584. else
  1585. {
  1586. if(maxProfile.ChargingSchedule.Duration != -1)
  1587. {
  1588. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1589. 0:
  1590. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1591. }
  1592. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1593. {
  1594. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1595. {
  1596. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1597. 0:
  1598. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1599. if(idxPeriod > 0)
  1600. {
  1601. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1602. {
  1603. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1604. }
  1605. }
  1606. }
  1607. }
  1608. }
  1609. }
  1610. /*
  1611. DEBUG_INFO("MaxProfile after align.\n");
  1612. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1613. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1614. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1615. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1616. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1617. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1618. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1619. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1620. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1621. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1622. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1623. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1624. {
  1625. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1626. {
  1627. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1628. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1629. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1630. }
  1631. }
  1632. DEBUG_INFO("------------------------------------\n");*/
  1633. }
  1634. /*
  1635. * Merge to conposite schedule
  1636. */
  1637. //DEBUG_INFO("====================================\n");
  1638. // Find each profile period quantity
  1639. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1640. {
  1641. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1642. limitMax = idx+1;
  1643. }
  1644. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1645. {
  1646. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1647. limitDef = idx+1;
  1648. }
  1649. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1650. {
  1651. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1652. limitTx = idx+1;
  1653. }
  1654. // TxProfile found, composite schedule based on it
  1655. if(txProfile.ChargingProfileId != -1)
  1656. {
  1657. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  1658. {
  1659. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  1660. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  1661. (txProfile.ChargingSchedule.Duration > 0))
  1662. {
  1663. if(maxProfile.ChargingProfileId != -1)
  1664. {
  1665. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1666. {
  1667. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  1668. {
  1669. if((maxProfile.ChargingSchedule.Duration > 0))
  1670. {
  1671. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1672. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1673. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1674. }
  1675. else
  1676. {
  1677. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1678. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1679. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  1680. }
  1681. }
  1682. if(idxMaxPeriod == (limitMax-1))
  1683. {
  1684. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1685. {
  1686. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1687. {
  1688. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1689. compositePeriodIdx++;
  1690. }
  1691. else
  1692. {
  1693. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1694. }
  1695. }
  1696. }
  1697. }
  1698. }
  1699. else
  1700. {
  1701. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1702. {
  1703. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1704. compositePeriodIdx++;
  1705. }
  1706. else
  1707. {
  1708. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1709. }
  1710. }
  1711. }
  1712. if(idxTxPeriod == (limitTx-1))
  1713. {
  1714. if(defaultTxProfile.ChargingProfileId != -1)
  1715. {
  1716. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1717. {
  1718. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  1719. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  1720. (defaultTxProfile.ChargingSchedule.Duration>0))
  1721. {
  1722. if(maxProfile.ChargingProfileId != -1)
  1723. {
  1724. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1725. {
  1726. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1727. {
  1728. if((maxProfile.ChargingSchedule.Duration > 0))
  1729. {
  1730. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1731. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1732. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1733. }
  1734. else
  1735. {
  1736. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1737. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1738. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  1739. }
  1740. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1741. {
  1742. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1743. {
  1744. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1745. compositePeriodIdx++;
  1746. }
  1747. else
  1748. {
  1749. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1750. }
  1751. }
  1752. break;
  1753. }
  1754. }
  1755. }
  1756. else
  1757. {
  1758. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1759. {
  1760. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1761. compositePeriodIdx++;
  1762. }
  1763. else
  1764. {
  1765. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1766. }
  1767. }
  1768. }
  1769. }
  1770. }
  1771. }
  1772. }
  1773. }
  1774. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  1775. else if(defaultTxProfile.ChargingProfileId != -1)
  1776. {
  1777. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1778. {
  1779. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  1780. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  1781. (defaultTxProfile.ChargingSchedule.Duration > 0))
  1782. {
  1783. if(maxProfile.ChargingProfileId != -1)
  1784. {
  1785. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1786. {
  1787. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1788. {
  1789. if((maxProfile.ChargingSchedule.Duration > 0))
  1790. {
  1791. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1792. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1793. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  1794. }
  1795. else
  1796. {
  1797. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1798. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1799. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  1800. }
  1801. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1802. {
  1803. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1804. {
  1805. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1806. compositePeriodIdx++;
  1807. }
  1808. else
  1809. {
  1810. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1811. }
  1812. }
  1813. break;
  1814. }
  1815. }
  1816. }
  1817. else
  1818. {
  1819. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1820. {
  1821. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1822. compositePeriodIdx++;
  1823. }
  1824. else
  1825. {
  1826. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1827. }
  1828. }
  1829. }
  1830. }
  1831. }
  1832. // Fill other period by MaxProfile
  1833. if(maxProfile.ChargingProfileId != -1)
  1834. {
  1835. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1836. {
  1837. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1838. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1839. (maxProfile.ChargingSchedule.Duration > 0))
  1840. {
  1841. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  1842. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  1843. {
  1844. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  1845. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  1846. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1847. }
  1848. if((maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  1849. {
  1850. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.Duration;
  1851. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  1852. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1853. }
  1854. if(tmpPeriod.Limit != -1)
  1855. {
  1856. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1857. {
  1858. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1859. {
  1860. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1861. compositePeriodIdx++;
  1862. }
  1863. else
  1864. {
  1865. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1866. }
  1867. }
  1868. }
  1869. }
  1870. }
  1871. }
  1872. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  1873. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1874. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1875. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1876. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1877. {
  1878. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1879. {
  1880. compositeProfile->ChargingProfileId = 1;
  1881. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1882. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1883. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1884. }
  1885. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1886. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1887. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1888. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1889. }
  1890. if(line)
  1891. free(line);
  1892. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  1893. }
  1894. //==========================================
  1895. // Init all share memory
  1896. //==========================================
  1897. int InitShareMemory()
  1898. {
  1899. int result = PASS;
  1900. int MeterSMId;
  1901. //creat ShmSysConfigAndInfo
  1902. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  1903. {
  1904. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  1905. result = FAIL;
  1906. }
  1907. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1908. {
  1909. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  1910. result = FAIL;
  1911. }
  1912. else
  1913. {}
  1914. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  1915. {
  1916. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  1917. result = FAIL;
  1918. }
  1919. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1920. {
  1921. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  1922. result = FAIL;
  1923. }
  1924. else
  1925. {}
  1926. //creat ShmPsuData
  1927. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  1928. {
  1929. DEBUG_ERROR("shmget ShmPsuData NG\n");
  1930. result = FAIL;
  1931. }
  1932. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1933. {
  1934. DEBUG_ERROR("shmat ShmPsuData NG\n");
  1935. result = FAIL;
  1936. }
  1937. else
  1938. {}
  1939. //creat ShmOCPP16Data
  1940. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  1941. {
  1942. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  1943. result = FAIL;
  1944. }
  1945. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1946. {
  1947. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  1948. result = FAIL;
  1949. }
  1950. else
  1951. {}
  1952. /****************************** For Initial Settings************************************************/
  1953. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  1954. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  1955. // allocate Configuration memory address
  1956. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  1957. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  1958. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  1959. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  1960. //offline MeterValue Interval
  1961. TempMeterValueInterval = 0;
  1962. return result;
  1963. }
  1964. int ProcessShareMemory()
  1965. {
  1966. if(InitShareMemory() == FAIL)
  1967. {
  1968. DEBUG_ERROR("InitShareMemory NG\n");
  1969. if(ShmStatusCodeData!=NULL)
  1970. {
  1971. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  1972. }
  1973. sleep(5);
  1974. return FAIL;
  1975. }
  1976. return PASS;
  1977. }
  1978. //---------------------common routine---------------------------//
  1979. //---------------------------------------------
  1980. // new:
  1981. // enum SYSTEM_STATUS
  1982. // {
  1983. // SYS_MODE_BOOTING = 0,
  1984. // SYS_MODE_IDLE = 1,
  1985. // SYS_MODE_AUTHORIZING = 2,
  1986. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  1987. // SYS_MODE_REASSIGN = 4,
  1988. // SYS_MODE_PREPARING = 5,
  1989. // SYS_MODE_PREPARE_FOR_EV = 6,
  1990. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  1991. // SYS_MODE_CHARGING = 8,
  1992. // SYS_MODE_TERMINATING = 9,
  1993. // SYS_MODE_COMPLETE = 10,
  1994. // SYS_MODE_ALARM = 11,
  1995. // SYS_MODE_FAULT = 12,
  1996. // SYS_MODE_RESERVATION = 13,
  1997. // SYS_MODE_BOOKING = 14,
  1998. // SYS_MODE_MAINTAIN = 15,
  1999. // SYS_MODE_DEBUG = 16,
  2000. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  2001. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  2002. // SYS_MODE_UPDATE = 19
  2003. // };
  2004. //
  2005. //
  2006. //-----------------------------------------
  2007. void CheckSystemValue(void)
  2008. {
  2009. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  2010. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  2011. char filenmae[100]={0};
  2012. char str[100]={0};
  2013. int tempIndex = 0;
  2014. //===============================
  2015. // send Heartbeat
  2016. //===============================
  2017. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2018. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  2019. {
  2020. clientTime.Heartbeat=time((time_t*)NULL);
  2021. if(server_sign == TRUE)
  2022. {
  2023. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2024. }
  2025. else
  2026. {
  2027. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  2028. }
  2029. }
  2030. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  2031. {
  2032. //parameter for test
  2033. sendHeartbeatRequest(0);
  2034. //==============================================
  2035. // Reset Waiting Time
  2036. //==============================================
  2037. HeartBeatWithNOResponse += 1;
  2038. }
  2039. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  2040. {
  2041. //==========================================
  2042. // csu trigger DataTransferReq
  2043. //==========================================
  2044. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  2045. {
  2046. sendDataTransferRequest(gun_index);
  2047. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  2048. }
  2049. //===============================
  2050. // CSU Trigger Reset Conf
  2051. //===============================
  2052. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  2053. {
  2054. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  2055. }
  2056. //===============================
  2057. // CSU Trigger Authorize Request
  2058. //===============================
  2059. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  2060. {
  2061. sendAuthorizeRequest(0);
  2062. authorizeRetryTimes = authorizeRetryTimes + 1;
  2063. if(authorizeRetryTimes < 3)
  2064. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2065. }
  2066. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  2067. {
  2068. authorizeRetryTimes = 0;
  2069. SetOcppConnStatus(FALSE);
  2070. server_sign = FALSE;
  2071. }
  2072. 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))
  2073. {
  2074. sendAuthorizeRequest(0);
  2075. }
  2076. //===============================
  2077. // CSU Trigger Smart Charging Profilw
  2078. //===============================
  2079. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  2080. {
  2081. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index]);
  2082. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  2083. }
  2084. //==============================================
  2085. // Charger start transaction
  2086. //==============================================
  2087. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2088. {
  2089. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  2090. sendStartTransactionRequest(gun_index);
  2091. clientTime.StartTransaction = time((time_t*)NULL);
  2092. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2093. storeTempStopTransaction(gun_index);
  2094. }
  2095. //==============================================
  2096. // Charger stop transaction
  2097. //==============================================
  2098. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2099. {
  2100. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2101. sendStopTransactionRequest(gun_index);
  2102. clientTime.StopTransaction = time((time_t*)NULL);
  2103. }
  2104. //==============================================
  2105. // Charger status report
  2106. //==============================================
  2107. //--- Check Mode Change ---//
  2108. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2109. if(gunType[gun_index] == 'J')
  2110. {
  2111. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2112. {
  2113. tempIndex = ((gun_index==2) ? 1: 0);
  2114. }
  2115. else
  2116. {
  2117. tempIndex = gun_index;
  2118. }
  2119. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2120. {
  2121. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2122. {
  2123. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  2124. {
  2125. // Sent unplug message for California pricing logic
  2126. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  2127. {
  2128. uint8_t ts[20];
  2129. getNowDatetime(ts);
  2130. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2131. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2132. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2133. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2134. }
  2135. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2136. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2137. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2138. statusModeChage[gun_index] = TRUE;
  2139. }
  2140. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2141. {
  2142. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2143. if((access(filenmae,F_OK))!=-1)
  2144. {
  2145. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2146. sprintf(str,"rm -f %s",filenmae);
  2147. system(str);
  2148. }
  2149. }
  2150. #if 1 // for TempStopTransaction
  2151. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2152. {
  2153. checkTempStopTransaction(gun_index);
  2154. }
  2155. #endif
  2156. }
  2157. }
  2158. }
  2159. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2160. {
  2161. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2162. {
  2163. tempIndex = ((gun_index==2) ? 1: 0);
  2164. }
  2165. else
  2166. {
  2167. tempIndex = gun_index;
  2168. }
  2169. for (int index = 0; index < CCS_QUANTITY; index++)
  2170. {
  2171. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2172. {
  2173. 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]*/ )
  2174. {
  2175. // Sent unplug message for California pricing logic
  2176. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  2177. {
  2178. uint8_t ts[20];
  2179. getNowDatetime(ts);
  2180. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2181. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2182. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2183. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2184. }
  2185. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2186. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2187. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2188. statusModeChage[gun_index] = TRUE;
  2189. }
  2190. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2191. {
  2192. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2193. if((access(filenmae,F_OK))!=-1)
  2194. {
  2195. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2196. sprintf(str,"rm -f %s",filenmae);
  2197. system(str);
  2198. }
  2199. }
  2200. #if 1 // for TempStopTransaction
  2201. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2202. {
  2203. checkTempStopTransaction(gun_index);
  2204. }
  2205. #endif
  2206. }
  2207. }
  2208. }
  2209. else if(gunType[gun_index] == 'G')
  2210. {
  2211. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2212. {
  2213. tempIndex = ((gun_index==2) ? 1: 0);
  2214. }
  2215. else
  2216. {
  2217. tempIndex = gun_index;
  2218. }
  2219. for (int index = 0; index < GB_QUANTITY; index++)
  2220. {
  2221. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2222. {
  2223. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  2224. {
  2225. // Sent unplug message for California pricing logic
  2226. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  2227. {
  2228. uint8_t ts[20];
  2229. getNowDatetime(ts);
  2230. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2231. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2232. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2233. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2234. }
  2235. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2236. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2237. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2238. statusModeChage[gun_index] = TRUE;
  2239. }
  2240. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2241. {
  2242. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2243. if((access(filenmae,F_OK))!=-1)
  2244. {
  2245. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2246. sprintf(str,"rm -f %s",filenmae);
  2247. system(str);
  2248. }
  2249. }
  2250. #if 1 // for TempStopTransaction
  2251. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2252. {
  2253. checkTempStopTransaction(gun_index);
  2254. }
  2255. #endif
  2256. }
  2257. }
  2258. }
  2259. else if(gunType[gun_index] == 'O')
  2260. {
  2261. tempIndex = gun_index;
  2262. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2263. {
  2264. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2265. {
  2266. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  2267. {
  2268. // Sent unplug message for California pricing logic
  2269. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  2270. {
  2271. uint8_t ts[20];
  2272. getNowDatetime(ts);
  2273. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2274. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2275. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2276. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2277. }
  2278. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  2279. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  2280. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2281. statusModeChage[gun_index] = TRUE;
  2282. }
  2283. 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
  2284. {
  2285. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2286. if((access(filenmae,F_OK))!=-1)
  2287. {
  2288. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2289. sprintf(str,"rm -f %s",filenmae);
  2290. system(str);
  2291. }
  2292. }
  2293. #if 1 // for TempStopTransaction
  2294. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2295. {
  2296. checkTempStopTransaction(gun_index);
  2297. }
  2298. #endif
  2299. }
  2300. }
  2301. }
  2302. else
  2303. {
  2304. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2305. {
  2306. tempIndex = 2;
  2307. }
  2308. else
  2309. {
  2310. tempIndex = gun_index;
  2311. }
  2312. for (int index = 0; index < AC_QUANTITY; index++)
  2313. {
  2314. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2315. {
  2316. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  2317. {
  2318. // Sent unplug message for California pricing logic
  2319. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)
  2320. {
  2321. uint8_t ts[20];
  2322. getNowDatetime(ts);
  2323. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2324. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2325. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2326. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2327. }
  2328. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2329. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2330. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2331. statusModeChage[gun_index] = TRUE;
  2332. }
  2333. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2334. {
  2335. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2336. if((access(filenmae,F_OK))!=-1)
  2337. {
  2338. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2339. sprintf(str,"rm -f %s",filenmae);
  2340. system(str);
  2341. }
  2342. }
  2343. #if 1 // for TempStopTransaction
  2344. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2345. {
  2346. checkTempStopTransaction(gun_index);
  2347. }
  2348. #endif
  2349. }
  2350. }// END
  2351. }
  2352. if(isWebsocketSendable &&
  2353. (
  2354. (statusModeChage[gun_index] == TRUE) ||
  2355. //((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index))) ||
  2356. ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 10))
  2357. )
  2358. )
  2359. {
  2360. if(SystemInitial > 0)
  2361. SystemInitial -= 1;
  2362. sendStatusNotificationRequest(gun_index);
  2363. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2364. statusModeChage[gun_index] = FALSE;
  2365. }
  2366. //==============================================
  2367. // Meter report
  2368. //==============================================
  2369. // Trigger MeterValue
  2370. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  2371. {
  2372. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  2373. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  2374. }
  2375. // ClockAlign MeterValue
  2376. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  2377. {
  2378. if(gunType[gun_index] == 'J')
  2379. {
  2380. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2381. {
  2382. tempIndex = ((gun_index==2) ? 1: 0);
  2383. }
  2384. else
  2385. {
  2386. tempIndex = gun_index;
  2387. }
  2388. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2389. {
  2390. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2391. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2392. {
  2393. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2394. {
  2395. reqClockAlignMeter[gun_index] = 1;
  2396. }
  2397. }
  2398. }// End for CHAdeMO
  2399. }
  2400. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2401. {
  2402. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2403. {
  2404. tempIndex = ((gun_index==2) ? 1: 0);
  2405. }
  2406. else
  2407. {
  2408. tempIndex = gun_index;
  2409. }
  2410. for (int index = 0; index < CCS_QUANTITY; index++)
  2411. {
  2412. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2413. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2414. {
  2415. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2416. {
  2417. reqClockAlignMeter[gun_index] = 1;
  2418. }
  2419. }
  2420. } // End for CCS
  2421. }
  2422. else if(gunType[gun_index] == 'G')
  2423. {
  2424. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2425. {
  2426. tempIndex = ((gun_index==2) ? 1: 0);
  2427. }
  2428. else
  2429. {
  2430. tempIndex = gun_index;
  2431. }
  2432. for (int index = 0; index < GB_QUANTITY; index++)
  2433. {
  2434. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2435. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2436. {
  2437. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2438. {
  2439. reqClockAlignMeter[gun_index] = 1;
  2440. }
  2441. }
  2442. }// End for GB
  2443. }
  2444. else if(gunType[gun_index] == 'O')
  2445. {
  2446. tempIndex = gun_index;
  2447. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2448. {
  2449. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2450. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2451. {
  2452. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_CHARGING)
  2453. {
  2454. reqClockAlignMeter[gun_index] = 1;
  2455. }
  2456. }
  2457. }
  2458. }
  2459. else
  2460. {
  2461. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2462. {
  2463. tempIndex = 2;
  2464. }
  2465. else
  2466. {
  2467. tempIndex = gun_index;
  2468. }
  2469. for (int index = 0; index < AC_QUANTITY; index++)
  2470. {
  2471. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2472. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2473. {
  2474. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2475. {
  2476. reqClockAlignMeter[gun_index] = 1;
  2477. }
  2478. }
  2479. }//End for AC
  2480. }
  2481. if(reqClockAlignMeter[gun_index] == 1)
  2482. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  2483. }
  2484. // Sample period MeterValue
  2485. if((((time((time_t*)NULL) - clientTime.MeterValues[gun_index]) > (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1))))
  2486. {
  2487. //check Transaction active
  2488. if(gunType[gun_index] == 'J')
  2489. {
  2490. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2491. {
  2492. tempIndex = ((gun_index==2) ? 1: 0);
  2493. }
  2494. else
  2495. {
  2496. tempIndex = gun_index;
  2497. }
  2498. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2499. {
  2500. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2501. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2502. {
  2503. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2504. {
  2505. reqSampleMeter[gun_index] = 1;
  2506. }
  2507. }
  2508. }// End for CHAdeMO
  2509. }
  2510. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2511. {
  2512. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2513. {
  2514. tempIndex = ((gun_index==2) ? 1: 0);
  2515. }
  2516. else
  2517. {
  2518. tempIndex = gun_index;
  2519. }
  2520. for (int index = 0; index < CCS_QUANTITY; index++)
  2521. {
  2522. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2523. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2524. {
  2525. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2526. {
  2527. reqSampleMeter[gun_index] = 1;
  2528. }
  2529. }
  2530. } // End for CCS
  2531. }
  2532. else if(gunType[gun_index] == 'G')
  2533. {
  2534. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2535. {
  2536. tempIndex = ((gun_index==2) ? 1: 0);
  2537. }
  2538. else
  2539. {
  2540. tempIndex = gun_index;
  2541. }
  2542. for (int index = 0; index < GB_QUANTITY; index++)
  2543. {
  2544. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2545. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2546. {
  2547. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2548. {
  2549. reqSampleMeter[gun_index] = 1;
  2550. }
  2551. }
  2552. }// End for GB
  2553. }
  2554. else if(gunType[gun_index] == 'O')
  2555. {
  2556. tempIndex = gun_index;
  2557. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2558. {
  2559. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2560. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2561. {
  2562. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  2563. {
  2564. reqSampleMeter[gun_index] = 1;
  2565. }
  2566. }
  2567. }
  2568. }
  2569. else
  2570. {
  2571. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2572. {
  2573. tempIndex = 2;
  2574. }
  2575. else
  2576. {
  2577. tempIndex = gun_index;
  2578. }
  2579. for (int index = 0; index < AC_QUANTITY; index++)
  2580. {
  2581. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2582. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2583. {
  2584. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  2585. {
  2586. reqSampleMeter[gun_index] = 1;
  2587. }
  2588. }
  2589. }//End for AC
  2590. }
  2591. if(reqSampleMeter[gun_index] == 1)
  2592. {
  2593. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  2594. storeTempStopTransaction(gun_index);
  2595. }
  2596. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2597. }
  2598. //==============================================
  2599. // Check Connector reserved
  2600. //==============================================
  2601. //===============================
  2602. // Check if Reserve is expired
  2603. //===============================
  2604. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  2605. {
  2606. double diff_t;
  2607. struct tm tp;
  2608. // current time
  2609. time_t t = time(NULL);
  2610. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  2611. tp.tm_isdst = -1;
  2612. time_t utc = mktime(&tp);
  2613. diff_t = difftime(utc, t);
  2614. if(diff_t <= 0)
  2615. {
  2616. DEBUG_INFO("reserve expired.\n");
  2617. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  2618. }
  2619. }//END OF Check if Reserve is expired
  2620. //==========================================
  2621. // csu trigger FirmwareStatusNotificationReq
  2622. //==========================================
  2623. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  2624. {
  2625. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  2626. }
  2627. //==========================================
  2628. // csu trigger CancelReservationConf
  2629. //==========================================
  2630. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  2631. {
  2632. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  2633. }
  2634. //==========================================
  2635. // csu trigger ChangeAvailabilityConf
  2636. //==========================================
  2637. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  2638. {
  2639. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  2640. }
  2641. //==========================================
  2642. // csu trigger UnlockConnectorConf
  2643. //==========================================
  2644. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  2645. {
  2646. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  2647. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  2648. }
  2649. //==========================================
  2650. // csu trigger ReserveNowConf
  2651. //==========================================
  2652. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  2653. {
  2654. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  2655. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  2656. }
  2657. }
  2658. }
  2659. //==========================================
  2660. // send request routine
  2661. //==========================================
  2662. int sendAuthorizeRequest(int gun_index)
  2663. {
  2664. mtrace();
  2665. int result = FAIL;
  2666. char message[100]={0};
  2667. char guid[37];
  2668. char tempdata[65]={0};
  2669. DEBUG_INFO("sendAuthorizeRequest...\n");
  2670. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  2671. //Local Authorize
  2672. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  2673. {
  2674. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  2675. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2676. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  2677. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  2678. result = PASS;
  2679. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2680. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2681. authorizeRetryTimes = 0;
  2682. return result;
  2683. }
  2684. 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))||
  2685. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  2686. {
  2687. // Query from cache
  2688. DEBUG_INFO("Authorize from cache.\n");
  2689. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2690. // Query from list
  2691. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  2692. {
  2693. DEBUG_INFO("Authorize from list.\n");
  2694. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2695. }
  2696. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  2697. {
  2698. if(strcmp(idTagQuery.idTagstr,"") == 0)
  2699. {
  2700. DEBUG_INFO("off-line Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  2701. }
  2702. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  2703. {
  2704. DEBUG_INFO("off-line Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  2705. }
  2706. DEBUG_INFO("off-line Local Authorization Fail !!!!\n");
  2707. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2708. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2709. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  2710. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  2711. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2712. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2713. authorizeRetryTimes = 0;
  2714. return result;
  2715. }
  2716. else
  2717. {
  2718. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  2719. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  2720. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2721. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  2722. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  2723. else
  2724. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  2725. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  2726. result = PASS;
  2727. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2728. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2729. authorizeRetryTimes = 0;
  2730. return result;
  2731. }
  2732. }
  2733. //initialize struct Authorize
  2734. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  2735. //get data from shared memory
  2736. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2737. random_uuid(guid);
  2738. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  2739. LWS_Send(message);
  2740. sprintf(tempdata, "Authorize,%d", gun_index);
  2741. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2742. {
  2743. result = PASS;
  2744. DEBUG_INFO("Authorize mapItem pass\n");
  2745. }
  2746. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2747. return result;
  2748. }
  2749. int sendBootNotificationRequest(void)
  2750. {
  2751. mtrace();
  2752. int result = FAIL;
  2753. char message[500]={0}, payload[700]={0};
  2754. char guid[37]={0};
  2755. char tempdata[65]={0};
  2756. // Fill BootNotification fields
  2757. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  2758. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  2759. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  2760. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2761. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  2762. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  2763. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  2764. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  2765. ShmOCPP16Data->ChargeBoxId
  2766. ,ShmSysConfigAndInfo->SysConfig.ModelName
  2767. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  2768. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  2769. ,ShmOCPP16Data->BootNotification.CpFwVersion
  2770. ,ShmOCPP16Data->BootNotification.CpIccid
  2771. ,ShmOCPP16Data->BootNotification.CpImsi);
  2772. random_uuid(guid);
  2773. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  2774. LWS_Send(message);
  2775. sprintf(tempdata, "BootNotification,0");
  2776. 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*/)
  2777. {
  2778. result = PASS;
  2779. }
  2780. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  2781. strcpy(queuedata,message);
  2782. return result;
  2783. }
  2784. int sendDataTransferRequest(int gun_index)
  2785. {
  2786. mtrace();
  2787. char message[1000]={0};
  2788. char guid[37]={0};
  2789. char tempdata[65]={0};
  2790. int result = FAIL;
  2791. random_uuid(guid);
  2792. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  2793. MESSAGE_TYPE_CALL,
  2794. guid,
  2795. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  2796. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  2797. ShmOCPP16Data->DataTransfer[gun_index].Data);
  2798. LWS_Send(message);
  2799. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  2800. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2801. {
  2802. result = PASS;
  2803. DEBUG_INFO("DataTransfer mapItem pass\n");
  2804. }
  2805. return result;
  2806. }
  2807. int sendDiagnosticsStatusNotificationRequest(char *status)
  2808. {
  2809. mtrace();
  2810. int result = FAIL;
  2811. char message[110]={0};
  2812. char guid[37]={0};
  2813. char tempdata[65]={0};
  2814. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  2815. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  2816. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  2817. random_uuid(guid);
  2818. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  2819. LWS_SendNow(message);
  2820. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  2821. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2822. {
  2823. result = PASS;
  2824. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  2825. }
  2826. //#ifdef SystemLogMessage
  2827. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  2828. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2829. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  2830. //#endif
  2831. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  2832. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  2833. //record status
  2834. if(strcmp(status,"Idle")==0)
  2835. {
  2836. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  2837. }
  2838. else if(strcmp(status,"Uploaded")==0)
  2839. {
  2840. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  2841. }
  2842. else if(strcmp(status,"UploadFailed")==0)
  2843. {
  2844. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  2845. }
  2846. else if(strcmp(status,"Uploading")==0)
  2847. {
  2848. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  2849. }
  2850. return result;
  2851. }
  2852. int sendFirmwareStatusNotificationRequest(char *status)
  2853. {
  2854. mtrace();
  2855. int result = FAIL;
  2856. char message[110]={0};
  2857. char guid[37]={0};
  2858. char tempdata[65]={0};
  2859. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  2860. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  2861. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  2862. random_uuid(guid);
  2863. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  2864. LWS_SendNow(message);
  2865. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  2866. 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*/)
  2867. {
  2868. result = PASS;
  2869. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  2870. }
  2871. //#ifdef SystemLogMessage
  2872. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  2873. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2874. //#endif
  2875. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  2876. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  2877. //record status
  2878. if(strcmp(status,"Downloaded")==0)
  2879. {
  2880. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  2881. }
  2882. else if(strcmp(status,"DownloadFailed")==0)
  2883. {
  2884. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  2885. }
  2886. else if(strcmp(status,"Downloading")==0)
  2887. {
  2888. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  2889. }
  2890. else if(strcmp(status,"Idle")==0)
  2891. {
  2892. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  2893. }
  2894. else if(strcmp(status,"InstallationFailed")==0)
  2895. {
  2896. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  2897. }
  2898. else if(strcmp(status,"Installing")==0)
  2899. {
  2900. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  2901. }
  2902. else if(strcmp(status,"Installed")==0)
  2903. {
  2904. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  2905. }
  2906. return result;
  2907. }
  2908. int sendHeartbeatRequest(int gun_index)
  2909. {
  2910. mtrace();
  2911. int result = FAIL;
  2912. char message[80]={0};
  2913. char guid[37]={0};
  2914. char tempdata[65]={0};
  2915. random_uuid(guid);
  2916. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  2917. , MESSAGE_TYPE_CALL
  2918. , guid );
  2919. LWS_Send(message);
  2920. sprintf(tempdata, "Heartbeat,%d", 0);
  2921. 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*/)
  2922. {
  2923. result = PASS;
  2924. }
  2925. return result;
  2926. }
  2927. int sendStartTransactionRequest(int gun_index)
  2928. {
  2929. mtrace();
  2930. int result = FAIL;
  2931. char message[250]={0};
  2932. char guid[37]={0};
  2933. struct timeval tmnow;
  2934. struct tm *tm;
  2935. char buf[28];//, usec_buf[6];
  2936. char tempdata[65]={0};
  2937. int tempIndex = 0;
  2938. DEBUG_INFO("sendStartTransactionRequest...\n");
  2939. gettimeofday(&tmnow, NULL);
  2940. time_t t;
  2941. t = time(NULL);
  2942. /*UTC time and date*/
  2943. tm = gmtime(&t);
  2944. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2945. #if 0 // remove temporally
  2946. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2947. strcat(buf,".");
  2948. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2949. strcat(buf,usec_buf);
  2950. #endif
  2951. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  2952. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  2953. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2954. // clear StartTransaction Response
  2955. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  2956. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  2957. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  2958. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  2959. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2960. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2961. if(gunType[gun_index] == 'J')
  2962. {
  2963. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2964. {
  2965. tempIndex = ((gun_index==2) ? 1: 0);
  2966. }
  2967. else
  2968. {
  2969. tempIndex = gun_index;
  2970. }
  2971. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2972. {
  2973. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2974. {
  2975. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  2976. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  2977. }
  2978. }
  2979. }
  2980. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2981. {
  2982. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2983. {
  2984. tempIndex = ((gun_index==2) ? 1: 0);
  2985. }
  2986. else
  2987. {
  2988. tempIndex = gun_index;
  2989. }
  2990. for (int index = 0; index < CCS_QUANTITY; index++)
  2991. {
  2992. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2993. {
  2994. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  2995. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  2996. }
  2997. }
  2998. }
  2999. else if(gunType[gun_index] == 'G')
  3000. {
  3001. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3002. {
  3003. tempIndex = ((gun_index==2) ? 1: 0);
  3004. }
  3005. else
  3006. {
  3007. tempIndex = gun_index;
  3008. }
  3009. for (int index = 0; index < GB_QUANTITY; index++)
  3010. {
  3011. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3012. {
  3013. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3014. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  3015. }
  3016. }
  3017. }
  3018. else if(gunType[gun_index] == 'O')
  3019. {
  3020. tempIndex = gun_index;
  3021. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3022. {
  3023. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3024. {
  3025. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3026. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  3027. }
  3028. }
  3029. }
  3030. else
  3031. {
  3032. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3033. {
  3034. tempIndex = 2;
  3035. }
  3036. else
  3037. {
  3038. tempIndex = gun_index;
  3039. }
  3040. for (int index = 0; index < AC_QUANTITY; index++)
  3041. {
  3042. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3043. {
  3044. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3045. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  3046. }
  3047. }
  3048. }
  3049. random_uuid(guid);
  3050. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  3051. {
  3052. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  3053. , gun_index +1
  3054. , MESSAGE_TYPE_CALL
  3055. , guid
  3056. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3057. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3058. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3059. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3060. }
  3061. else
  3062. {
  3063. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  3064. , gun_index +1
  3065. , MESSAGE_TYPE_CALL
  3066. , guid
  3067. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3068. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3069. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3070. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  3071. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3072. }
  3073. #if 1
  3074. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  3075. 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*/)
  3076. {
  3077. result = PASS;
  3078. }
  3079. #endif
  3080. strcpy(queuedata, message);
  3081. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3082. return result;
  3083. }
  3084. int sendStatusNotificationRequest(int gun_index)
  3085. {
  3086. mtrace();
  3087. int result = FAIL;
  3088. char message[600]={0};
  3089. char guid[37];
  3090. int currentStatus = 0;
  3091. struct timeval tmnow;
  3092. struct tm *tm;
  3093. char buf[28];//, usec_buf[6];
  3094. char tempdata[65]={0};
  3095. int tempIndex = 0;
  3096. gettimeofday(&tmnow, NULL);
  3097. time_t t;
  3098. t = time(NULL);
  3099. /*UTC time and date*/
  3100. tm = gmtime(&t);
  3101. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3102. #if 0 // remove temporally
  3103. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3104. strcat(buf,".");
  3105. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3106. strcat(buf,usec_buf);
  3107. #endif
  3108. printf("%s",buf);
  3109. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  3110. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  3111. // it's option
  3112. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  3113. /*
  3114. enum _SYSTEM_STATUS
  3115. {
  3116. S_BOOTING = 0,
  3117. S_IDLE, = 1
  3118. S_AUTHORIZING, =2
  3119. S_REASSIGN_CHECK, =3
  3120. S_REASSIGN, =4
  3121. S_PRECHARGE, =5
  3122. S_PREPARING_FOR_EV, =6
  3123. S_PREPARING_FOR_EVSE, =7
  3124. S_CHARGING, =8
  3125. S_TERMINATING, =9
  3126. S_COMPLETE, =10
  3127. S_ALARM, =11
  3128. S_FAULT =12
  3129. }
  3130. */
  3131. //check Transaction active
  3132. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3133. if(gunType[gun_index] == 'J')
  3134. {
  3135. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3136. {
  3137. tempIndex = ((gun_index==2) ? 1: 0);
  3138. }
  3139. else
  3140. {
  3141. tempIndex = gun_index;
  3142. }
  3143. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3144. {
  3145. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  3146. {
  3147. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  3148. {
  3149. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3150. {
  3151. currentStatus = 1; //OCPP Status: Preparing
  3152. }
  3153. else
  3154. {
  3155. currentStatus = 0; //OCPP Status: Available
  3156. }
  3157. }
  3158. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3159. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3160. ) //S_PRECHARGE
  3161. {
  3162. currentStatus = 1; //OCPP Status: Preparing
  3163. }
  3164. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3165. {
  3166. currentStatus = 2; //OCPP Status: Charging
  3167. }
  3168. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3169. {
  3170. currentStatus = 5; //OCPP Status: Finishing
  3171. }
  3172. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3173. {
  3174. currentStatus = 4; //OCPP Status: SuspendedEV
  3175. }
  3176. 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)) // ---> Unavailable
  3177. {
  3178. currentStatus = 7; //OCPP Status: Unavailable
  3179. }
  3180. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3181. {
  3182. currentStatus = 8; //OCPP Status: Faulted
  3183. }
  3184. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3185. {
  3186. currentStatus = 6; //OCPP Status: Reserved
  3187. }
  3188. } //end of the same index
  3189. }//end of for CHAdeMO_QUANTITY
  3190. }
  3191. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3192. {
  3193. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3194. {
  3195. tempIndex = ((gun_index==2) ? 1: 0);
  3196. }
  3197. else
  3198. {
  3199. tempIndex = gun_index;
  3200. }
  3201. for (int index = 0; index < CCS_QUANTITY; index++)
  3202. {
  3203. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3204. {
  3205. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3206. {
  3207. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3208. {
  3209. currentStatus = 1; //OCPP Status: Preparing
  3210. }
  3211. else
  3212. {
  3213. currentStatus = 0; //OCPP Status: Available
  3214. }
  3215. }
  3216. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3217. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3218. ) //S_PRECHARGE
  3219. {
  3220. currentStatus = 1; //OCPP Status: Preparing
  3221. }
  3222. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3223. {
  3224. currentStatus = 2; //OCPP Status: Charging
  3225. }
  3226. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3227. {
  3228. currentStatus = 5; //OCPP Status: Finishing
  3229. }
  3230. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3231. {
  3232. currentStatus = 4; //OCPP Status: SuspendedEV
  3233. }
  3234. 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)) // ---> Unavailable
  3235. {
  3236. currentStatus = 7; //OCPP Status : Unavailable
  3237. }
  3238. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3239. {
  3240. currentStatus = 8; //OCPP Status: Faulted
  3241. }
  3242. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3243. {
  3244. currentStatus = 6; //OCPP Status: Reserved
  3245. }
  3246. } //end of the same index
  3247. } // end of for CCS_QUANTITY
  3248. }
  3249. else if(gunType[gun_index] == 'G')
  3250. {
  3251. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3252. {
  3253. tempIndex = ((gun_index==2) ? 1: 0);
  3254. }
  3255. else
  3256. {
  3257. tempIndex = gun_index;
  3258. }
  3259. for (int index = 0; index < GB_QUANTITY; index++)
  3260. {
  3261. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3262. {
  3263. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3264. {
  3265. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3266. {
  3267. currentStatus = 1; //OCPP Status: Preparing
  3268. }
  3269. else
  3270. {
  3271. currentStatus = 0; //OCPP Status: Available
  3272. }
  3273. }
  3274. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3275. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3276. ) //S_PRECHARGE
  3277. {
  3278. currentStatus = 1; //OCPP Status: Preparing
  3279. }
  3280. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3281. {
  3282. currentStatus = 2; //OCPP Status: Charging
  3283. }
  3284. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3285. {
  3286. currentStatus = 5; //OCPP Status: Finishing
  3287. }
  3288. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3289. {
  3290. currentStatus = 4; //OCPP Status: SuspendedEV
  3291. }
  3292. 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)) // ---> Unavailable
  3293. {
  3294. currentStatus = 7; //OCPP Status: Unavailable
  3295. }
  3296. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3297. {
  3298. currentStatus = 8; //OCPP Status: Faulted
  3299. }
  3300. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3301. {
  3302. currentStatus = 6; //OCPP Status: Reserved
  3303. }
  3304. } //end of the same index
  3305. } // end of for GB_QUANTITY
  3306. }
  3307. else if(gunType[gun_index] == 'O')
  3308. {
  3309. tempIndex = gun_index;
  3310. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3311. {
  3312. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3313. {
  3314. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3315. {
  3316. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3317. {
  3318. currentStatus = 1; //OCPP Status: Preparing
  3319. }
  3320. else
  3321. {
  3322. currentStatus = 0; //OCPP Status: Available
  3323. }
  3324. }
  3325. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3326. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3327. ) //S_PRECHARGE
  3328. {
  3329. currentStatus = 1; //OCPP Status: Preparing
  3330. }
  3331. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3332. {
  3333. currentStatus = 2; //OCPP Status: Charging
  3334. }
  3335. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3336. {
  3337. currentStatus = 5; //OCPP Status: Finishing
  3338. }
  3339. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3340. {
  3341. currentStatus = 4; //OCPP Status: SuspendedEV
  3342. }
  3343. 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)) // ---> Unavailable
  3344. {
  3345. currentStatus = 7; //OCPP Status: Unavailable
  3346. }
  3347. 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
  3348. {
  3349. currentStatus = 8; //OCPP Status: Faulted
  3350. }
  3351. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3352. {
  3353. currentStatus = 6; //OCPP Status: Reserved
  3354. }
  3355. } //end of the same index
  3356. }
  3357. }
  3358. else
  3359. {
  3360. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3361. {
  3362. tempIndex = 2;
  3363. }
  3364. else
  3365. {
  3366. tempIndex = gun_index;
  3367. }
  3368. for (int index = 0; index < AC_QUANTITY; index++)
  3369. {
  3370. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3371. {
  3372. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3373. {
  3374. 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))
  3375. {
  3376. currentStatus = 1; //OCPP Status: Preparing
  3377. }
  3378. else
  3379. {
  3380. currentStatus = 0; //OCPP Status: Available
  3381. }
  3382. }
  3383. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  3384. {
  3385. currentStatus = 1; //OCPP Status: Preparing
  3386. }
  3387. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3388. {
  3389. currentStatus = 2; //OCPP Status: Charging
  3390. }
  3391. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3392. {
  3393. currentStatus = 5; //OCPP Status: Finishing
  3394. }
  3395. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3396. {
  3397. currentStatus = 4; //OCPP Status: SuspendedEV
  3398. }
  3399. 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)) // ---> Unavailable
  3400. {
  3401. currentStatus = 7; //OCPP Status: Unavailable
  3402. }
  3403. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3404. {
  3405. currentStatus = 8; //OCPP Status: Faulted
  3406. }
  3407. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3408. {
  3409. currentStatus = 6; //OCPP Status: Reserved
  3410. }
  3411. }//end of the same index
  3412. }//end of for AC_QUANTITY
  3413. }
  3414. //it's option
  3415. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3416. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  3417. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3418. random_uuid(guid);
  3419. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3420. , MESSAGE_TYPE_CALL
  3421. , guid
  3422. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3423. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3424. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3425. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3426. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3427. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3428. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3429. if((server_sign == TRUE))
  3430. {
  3431. LWS_Send(message);
  3432. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3433. 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*/)
  3434. {
  3435. //DEBUG_ERROR("statusNotification mapitem pass");
  3436. result = PASS;
  3437. }
  3438. }
  3439. else
  3440. {
  3441. result = PASS;
  3442. }
  3443. return result;
  3444. }
  3445. int sendStopTransactionRequest(int gun_index)
  3446. {
  3447. mtrace();
  3448. int result = FAIL;
  3449. //char message[1500]={0};
  3450. char guid[37]={0};
  3451. char tempdata[65]={0};
  3452. int tempIndex = 0;
  3453. char TempStopTransaction[256];
  3454. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  3455. //int idx_sample=0;
  3456. DEBUG_INFO("sendStopTransactionRequest \n");
  3457. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3458. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  3459. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  3460. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3461. if(gunType[gun_index] == 'J')
  3462. {
  3463. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3464. {
  3465. tempIndex = ((gun_index==2) ? 1: 0);
  3466. }
  3467. else
  3468. {
  3469. tempIndex = gun_index;
  3470. }
  3471. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3472. {
  3473. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3474. {
  3475. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3476. }
  3477. }// END OF CHAdeMO_QUANTITY
  3478. }
  3479. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3480. {
  3481. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3482. {
  3483. tempIndex = ((gun_index==2) ? 1: 0);
  3484. }
  3485. else
  3486. {
  3487. tempIndex = gun_index;
  3488. }
  3489. for (int index = 0; index < CCS_QUANTITY; index++)
  3490. {
  3491. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3492. {
  3493. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3494. }
  3495. }// END OF CCS_QUANTITY
  3496. }
  3497. else if(gunType[gun_index] == 'G')
  3498. {
  3499. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3500. {
  3501. tempIndex = ((gun_index==2) ? 1: 0);
  3502. }
  3503. else
  3504. {
  3505. tempIndex = gun_index;
  3506. }
  3507. for (int index = 0; index < GB_QUANTITY; index++)
  3508. {
  3509. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3510. {
  3511. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3512. }
  3513. }// END OF GB_QUANTITY
  3514. }
  3515. else if(gunType[gun_index] == 'O')
  3516. {
  3517. tempIndex = gun_index;
  3518. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3519. {
  3520. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3521. {
  3522. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3523. }
  3524. }// END OF GB_QUANTITY
  3525. }
  3526. else
  3527. {
  3528. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3529. {
  3530. tempIndex = 2;
  3531. }
  3532. else
  3533. {
  3534. tempIndex = gun_index;
  3535. }
  3536. for (int index = 0; index < AC_QUANTITY; index++)
  3537. {
  3538. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3539. {
  3540. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3541. }
  3542. }// END OF AC_QUANTITY
  3543. }
  3544. //====================================== Stop Transaction Time =====================================================
  3545. struct timeval tmnow;
  3546. struct tm *tm;
  3547. char buf[28];//, usec_buf[6];
  3548. gettimeofday(&tmnow, NULL);
  3549. time_t t;
  3550. t = time(NULL);
  3551. /*UTC time and date*/
  3552. tm = gmtime(&t);
  3553. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3554. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  3555. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  3556. random_uuid(guid);
  3557. /***********************************transactionData******************************************************/
  3558. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  3559. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  3560. //=================================
  3561. // Transaction_Begin
  3562. //=================================
  3563. //============================================ Energy.Active.Import.Interval ================================
  3564. //idx_sample=0;
  3565. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  3566. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  3567. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  3568. 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*/]);
  3569. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3570. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  3571. {
  3572. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  3573. }
  3574. else
  3575. {
  3576. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  3577. }
  3578. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  3579. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3580. //=================================
  3581. // Transaction_End
  3582. //=================================
  3583. // ================================= Current.Import L1 ===============================================
  3584. //idx_sample=1;
  3585. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  3586. if(gunType[gun_index] == 'J')
  3587. {
  3588. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3589. {
  3590. tempIndex = ((gun_index==2) ? 1: 0);
  3591. }
  3592. else
  3593. {
  3594. tempIndex = gun_index;
  3595. }
  3596. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3597. {
  3598. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3599. {
  3600. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3601. }
  3602. }// End of for CHAdeMO_QUANTITY
  3603. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3604. }
  3605. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3606. {
  3607. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3608. {
  3609. tempIndex = ((gun_index==2) ? 1: 0);
  3610. }
  3611. else
  3612. {
  3613. tempIndex = gun_index;
  3614. }
  3615. for (int index = 0; index < CCS_QUANTITY; index++)
  3616. {
  3617. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3618. {
  3619. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3620. }
  3621. }// End of for CCS_QUANTITY
  3622. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3623. }
  3624. else if(gunType[gun_index] == 'G')
  3625. {
  3626. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3627. {
  3628. tempIndex = ((gun_index==2) ? 1: 0);
  3629. }
  3630. else
  3631. {
  3632. tempIndex = gun_index;
  3633. }
  3634. for (int index = 0; index < GB_QUANTITY; index++)
  3635. {
  3636. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3637. {
  3638. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3639. }
  3640. }// End of for GB_QUANTITY
  3641. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3642. }
  3643. else if(gunType[gun_index] == 'O')
  3644. {
  3645. tempIndex = gun_index;
  3646. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3647. {
  3648. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3649. {
  3650. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3651. }
  3652. }
  3653. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3654. }
  3655. else
  3656. {
  3657. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3658. {
  3659. tempIndex = 2;
  3660. }
  3661. else
  3662. {
  3663. tempIndex = gun_index;
  3664. }
  3665. for (int index = 0; index < AC_QUANTITY; index++)
  3666. {
  3667. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3668. {
  3669. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  3670. }
  3671. }// End of for AC_QUANTITY
  3672. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  3673. }
  3674. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3675. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  3676. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  3677. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  3678. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3679. // ================================= Energy.Active.Import.Interval ==============================================
  3680. //idx_sample=2;
  3681. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3682. if(gunType[gun_index] == 'J')
  3683. {
  3684. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3685. {
  3686. tempIndex = ((gun_index==2) ? 1: 0);
  3687. }
  3688. else
  3689. {
  3690. tempIndex = gun_index;
  3691. }
  3692. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3693. {
  3694. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3695. {
  3696. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3697. }
  3698. }// END OF CHAdeMO_QUANTITY
  3699. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3700. }
  3701. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3702. {
  3703. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3704. {
  3705. tempIndex = ((gun_index==2) ? 1: 0);
  3706. }
  3707. else
  3708. {
  3709. tempIndex = gun_index;
  3710. }
  3711. for (int index = 0; index < CCS_QUANTITY; index++)
  3712. {
  3713. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3714. {
  3715. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3716. }
  3717. }// END OF CCS_QUANTITY
  3718. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3719. }
  3720. else if(gunType[gun_index] == 'G')
  3721. {
  3722. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3723. {
  3724. tempIndex = ((gun_index==2) ? 1: 0);
  3725. }
  3726. else
  3727. {
  3728. tempIndex = gun_index;
  3729. }
  3730. for (int index = 0; index < GB_QUANTITY; index++)
  3731. {
  3732. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3733. {
  3734. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3735. }
  3736. }// END OF GB_QUANTITY
  3737. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3738. }
  3739. else if(gunType[gun_index] == 'O')
  3740. {
  3741. tempIndex = gun_index;
  3742. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3743. {
  3744. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3745. {
  3746. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3747. }
  3748. }
  3749. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3750. }
  3751. else
  3752. {
  3753. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3754. {
  3755. tempIndex = 2;
  3756. }
  3757. else
  3758. {
  3759. tempIndex = gun_index;
  3760. }
  3761. for (int index = 0; index < AC_QUANTITY; index++)
  3762. {
  3763. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3764. {
  3765. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3766. }
  3767. }// END OF AC_QUANTITY
  3768. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  3769. }
  3770. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3771. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  3772. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  3773. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  3774. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3775. //=================================== Power.Active.Import ==================================================
  3776. //idx_sample=3;
  3777. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3778. if(gunType[gun_index] == 'J')
  3779. {
  3780. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3781. {
  3782. tempIndex = ((gun_index==2) ? 1: 0);
  3783. }
  3784. else
  3785. {
  3786. tempIndex = gun_index;
  3787. }
  3788. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3789. {
  3790. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3791. {
  3792. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3793. }
  3794. } // End for CHAdeMO_QUANTITY
  3795. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3796. }
  3797. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3798. {
  3799. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3800. {
  3801. tempIndex = ((gun_index==2) ? 1: 0);
  3802. }
  3803. else
  3804. {
  3805. tempIndex = gun_index;
  3806. }
  3807. for (int index = 0; index < CCS_QUANTITY; index++)
  3808. {
  3809. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3810. {
  3811. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3812. }
  3813. } // END for CCS_QUANTITY
  3814. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3815. }
  3816. else if(gunType[gun_index] == 'G')
  3817. {
  3818. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3819. {
  3820. tempIndex = ((gun_index==2) ? 1: 0);
  3821. }
  3822. else
  3823. {
  3824. tempIndex = gun_index;
  3825. }
  3826. for (int index = 0; index < GB_QUANTITY; index++)
  3827. {
  3828. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3829. {
  3830. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3831. }
  3832. }// END for GB_QUANTITY
  3833. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3834. }
  3835. else if(gunType[gun_index] == 'O')
  3836. {
  3837. tempIndex = gun_index;
  3838. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3839. {
  3840. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3841. {
  3842. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3843. }
  3844. }
  3845. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3846. }
  3847. else
  3848. {
  3849. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3850. {
  3851. tempIndex = 2;
  3852. }
  3853. else
  3854. {
  3855. tempIndex = gun_index;
  3856. }
  3857. for (int index = 0; index < AC_QUANTITY; index++)
  3858. {
  3859. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3860. {
  3861. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3862. }
  3863. } // END for AC_QUANTITY
  3864. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  3865. }
  3866. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3867. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  3868. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  3869. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  3870. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  3871. //============================ Voltage L1 ====================================
  3872. //idx_sample=4;
  3873. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3874. if(gunType[gun_index] == 'J')
  3875. {
  3876. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3877. {
  3878. tempIndex = ((gun_index==2) ? 1: 0);
  3879. }
  3880. else
  3881. {
  3882. tempIndex = gun_index;
  3883. }
  3884. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3885. {
  3886. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3887. {
  3888. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3889. }
  3890. } // END OF FOR CHAdeMO_QUANTITY
  3891. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3892. }
  3893. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3894. {
  3895. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3896. {
  3897. tempIndex = ((gun_index==2) ? 1: 0);
  3898. }
  3899. else
  3900. {
  3901. tempIndex = gun_index;
  3902. }
  3903. for (int index = 0; index < CCS_QUANTITY; index++)
  3904. {
  3905. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3906. {
  3907. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3908. }
  3909. } // END OF FOR CCS_QUANTITY
  3910. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3911. }
  3912. else if(gunType[gun_index] == 'G')
  3913. {
  3914. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3915. {
  3916. tempIndex = ((gun_index==2) ? 1: 0);
  3917. }
  3918. else
  3919. {
  3920. tempIndex = gun_index;
  3921. }
  3922. for (int index = 0; index < GB_QUANTITY; index++)
  3923. {
  3924. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3925. {
  3926. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3927. }
  3928. } // END OF FOR GB_QUANTITY
  3929. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3930. }
  3931. else if(gunType[gun_index] == 'O')
  3932. {
  3933. tempIndex = gun_index;
  3934. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3935. {
  3936. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3937. {
  3938. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3939. }
  3940. }
  3941. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3942. }
  3943. else
  3944. {
  3945. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3946. {
  3947. tempIndex = 2;
  3948. }
  3949. else
  3950. {
  3951. tempIndex = gun_index;
  3952. }
  3953. for (int index = 0; index < AC_QUANTITY; index++)
  3954. {
  3955. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3956. {
  3957. 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
  3958. }
  3959. } // END OF FOR AC_QUANTITY
  3960. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  3961. }
  3962. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3963. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  3964. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  3965. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  3966. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3967. //====================== End SoC ================================
  3968. //idx_sample=5;
  3969. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3970. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  3971. {
  3972. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != 'O'))
  3973. {
  3974. tempIndex = ((gun_index==2) ? 1: 0);
  3975. }
  3976. else
  3977. {
  3978. tempIndex = gun_index;
  3979. }
  3980. if(gunType[gun_index] == 'J')
  3981. {
  3982. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3983. {
  3984. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3985. {
  3986. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  3987. }
  3988. }
  3989. }
  3990. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3991. {
  3992. for (int index = 0; index < CCS_QUANTITY; index++)
  3993. {
  3994. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3995. {
  3996. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  3997. }
  3998. }
  3999. }
  4000. else if(gunType[gun_index] == 'G')
  4001. {
  4002. for (int index = 0; index < GB_QUANTITY; index++)
  4003. {
  4004. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4005. {
  4006. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  4007. }
  4008. }
  4009. }
  4010. else if(gunType[gun_index] == 'O')
  4011. {
  4012. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4013. {
  4014. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4015. {
  4016. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  4017. }
  4018. }
  4019. }
  4020. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4021. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  4022. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4023. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  4024. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  4025. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4026. } // END FOR DC CASE
  4027. // ================================= Current.Import L2 ===============================================
  4028. //idx_sample=6;
  4029. // AC 3 phse L2 current
  4030. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  4031. {
  4032. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4033. {
  4034. tempIndex = 2;
  4035. }
  4036. else
  4037. {
  4038. tempIndex = gun_index;
  4039. }
  4040. for (int index = 0; index < AC_QUANTITY; index++)
  4041. {
  4042. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4043. {
  4044. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  4045. }
  4046. }// End of for AC_QUANTITY
  4047. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  4048. }
  4049. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4050. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  4051. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  4052. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  4053. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4054. // ================================= Current.Import L3 ===============================================
  4055. //idx_sample=7;
  4056. // AC 3 phse L3 current
  4057. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  4058. {
  4059. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4060. {
  4061. tempIndex = 2;
  4062. }
  4063. else
  4064. {
  4065. tempIndex = gun_index;
  4066. }
  4067. for (int index = 0; index < AC_QUANTITY; index++)
  4068. {
  4069. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4070. {
  4071. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  4072. }
  4073. }// End of for AC_QUANTITY
  4074. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  4075. }
  4076. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4077. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  4078. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  4079. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  4080. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4081. //============================ Voltage L2 ====================================
  4082. //idx_sample=8;
  4083. // AC 3 phse L2 voltage
  4084. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  4085. {
  4086. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4087. {
  4088. tempIndex = 2;
  4089. }
  4090. else
  4091. {
  4092. tempIndex = gun_index;
  4093. }
  4094. for (int index = 0; index < AC_QUANTITY; index++)
  4095. {
  4096. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4097. {
  4098. 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
  4099. }
  4100. } // END OF FOR AC_QUANTITY
  4101. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  4102. }
  4103. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4104. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  4105. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  4106. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  4107. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4108. //============================ Voltage L3 ====================================
  4109. //idx_sample=8;
  4110. // AC 3 phse L3 voltage
  4111. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  4112. {
  4113. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4114. {
  4115. tempIndex = 2;
  4116. }
  4117. else
  4118. {
  4119. tempIndex = gun_index;
  4120. }
  4121. for (int index = 0; index < AC_QUANTITY; index++)
  4122. {
  4123. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4124. {
  4125. 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
  4126. }
  4127. } // END OF FOR AC_QUANTITY
  4128. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  4129. }
  4130. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4131. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  4132. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  4133. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  4134. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4135. //====================== Start SoC ================================
  4136. //idx_sample=10;
  4137. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4138. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  4139. {
  4140. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != 'O'))
  4141. {
  4142. tempIndex = ((gun_index==2) ? 1: 0);
  4143. }
  4144. else
  4145. {
  4146. tempIndex = gun_index;
  4147. }
  4148. if(gunType[gun_index] == 'J')
  4149. {
  4150. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4151. {
  4152. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4153. {
  4154. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  4155. }
  4156. }
  4157. }
  4158. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4159. {
  4160. for (int index = 0; index < CCS_QUANTITY; index++)
  4161. {
  4162. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4163. {
  4164. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  4165. }
  4166. }
  4167. }
  4168. else if(gunType[gun_index] == 'G')
  4169. {
  4170. for (int index = 0; index < GB_QUANTITY; index++)
  4171. {
  4172. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4173. {
  4174. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  4175. }
  4176. }
  4177. }
  4178. else if(gunType[gun_index] == 'O')
  4179. {
  4180. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4181. {
  4182. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4183. {
  4184. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  4185. }
  4186. }
  4187. }
  4188. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4189. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  4190. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4191. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  4192. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  4193. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4194. } // END FOR DC CASE
  4195. //================================================ Message create ====================================================
  4196. json_object *StopTransaction = json_object_new_object();
  4197. json_object *transactionDatas = json_object_new_array();
  4198. json_object *sampledValues = json_object_new_array();
  4199. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  4200. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  4201. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  4202. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  4203. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  4204. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  4205. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  4206. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  4207. {
  4208. json_object *transactionData = json_object_new_object();
  4209. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  4210. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  4211. {
  4212. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  4213. {
  4214. json_object *sampledValue = json_object_new_object();
  4215. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  4216. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  4217. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  4218. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  4219. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  4220. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  4221. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  4222. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  4223. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  4224. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  4225. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  4226. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  4227. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  4228. json_object_array_add(sampledValues, sampledValue);
  4229. }
  4230. }
  4231. json_object_object_add(transactionData, "sampledValue", sampledValues);
  4232. json_object_array_add(transactionDatas, transactionData);
  4233. }
  4234. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  4235. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  4236. ,MESSAGE_TYPE_CALL
  4237. ,guid
  4238. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  4239. json_object_put(StopTransaction);
  4240. #if 1 // for TempStopTransaction
  4241. //Delete TempStopTransaction
  4242. if((access(TempStopTransaction,F_OK))!=-1)
  4243. {
  4244. remove(TempStopTransaction); // remove file "TempStopTransaction"
  4245. }
  4246. #endif
  4247. #if 1
  4248. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4249. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4250. {
  4251. result = PASS;
  4252. //DEBUG_INFO("StopTransaction mapitem pass\n");
  4253. }
  4254. #endif
  4255. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4256. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4257. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  4258. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  4259. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4260. {
  4261. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  4262. }
  4263. //for test
  4264. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4265. return result;
  4266. }
  4267. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  4268. {
  4269. mtrace();
  4270. int result = FAIL;
  4271. char guid[37]={0};
  4272. char tempdata[65]={0};
  4273. int tempIndex = 0;
  4274. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4275. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4276. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  4277. //set value
  4278. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4279. 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) )?
  4280. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  4281. -1);
  4282. random_uuid(guid);
  4283. //UTC Date time
  4284. struct timeval tmnow;
  4285. struct tm *tm;
  4286. char buf[28];//, usec_buf[6];
  4287. gettimeofday(&tmnow, NULL);
  4288. time_t t;
  4289. t = time(NULL);
  4290. /*UTC time and date*/
  4291. tm = gmtime(&t);
  4292. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4293. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4294. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4295. //idx_sample=0;
  4296. //********************************(1)Current.Import L1************************************************/
  4297. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4298. if(gunType[gun_index] == 'J')
  4299. {
  4300. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4301. {
  4302. tempIndex = ((gun_index==2) ? 1: 0);
  4303. }
  4304. else
  4305. {
  4306. tempIndex = gun_index;
  4307. }
  4308. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4309. {
  4310. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4311. {
  4312. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4313. }
  4314. }
  4315. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4316. }
  4317. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4318. {
  4319. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4320. {
  4321. tempIndex = ((gun_index==2) ? 1: 0);
  4322. }
  4323. else
  4324. {
  4325. tempIndex = gun_index;
  4326. }
  4327. for (int index = 0; index < CCS_QUANTITY; index++)
  4328. {
  4329. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4330. {
  4331. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4332. }
  4333. }
  4334. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4335. }
  4336. else if(gunType[gun_index] == 'G')
  4337. {
  4338. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4339. {
  4340. tempIndex = ((gun_index==2) ? 1: 0);
  4341. }
  4342. else
  4343. {
  4344. tempIndex = gun_index;
  4345. }
  4346. for (int index = 0; index < GB_QUANTITY; index++)
  4347. {
  4348. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4349. {
  4350. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4351. }
  4352. }
  4353. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4354. }
  4355. else if(gunType[gun_index] == 'O')
  4356. {
  4357. tempIndex = gun_index;
  4358. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4359. {
  4360. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4361. {
  4362. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  4363. }
  4364. }
  4365. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4366. }
  4367. else
  4368. {
  4369. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4370. {
  4371. tempIndex = 2;
  4372. }
  4373. else
  4374. {
  4375. tempIndex = gun_index;
  4376. }
  4377. for (int index = 0; index < AC_QUANTITY; index++)
  4378. {
  4379. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4380. {
  4381. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4382. }
  4383. }
  4384. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4385. }
  4386. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4387. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4388. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4389. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4390. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4391. //idx_sample=1;
  4392. //********************************(2)Energy.Active.Import.Register ************************************************/
  4393. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4394. if(gunType[gun_index] == 'J')
  4395. {
  4396. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4397. {
  4398. tempIndex = ((gun_index==2) ? 1: 0);
  4399. }
  4400. else
  4401. {
  4402. tempIndex = gun_index;
  4403. }
  4404. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4405. {
  4406. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4407. {
  4408. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4409. }
  4410. }
  4411. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4412. }
  4413. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4414. {
  4415. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4416. {
  4417. tempIndex = ((gun_index==2) ? 1: 0);
  4418. }
  4419. else
  4420. {
  4421. tempIndex = gun_index;
  4422. }
  4423. for (int index = 0; index < CCS_QUANTITY; index++)
  4424. {
  4425. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4426. {
  4427. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4428. }
  4429. }
  4430. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4431. }
  4432. else if(gunType[gun_index] == 'G')
  4433. {
  4434. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4435. {
  4436. tempIndex = ((gun_index==2) ? 1: 0);
  4437. }
  4438. else
  4439. {
  4440. tempIndex = gun_index;
  4441. }
  4442. for (int index = 0; index < GB_QUANTITY; index++)
  4443. {
  4444. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4445. {
  4446. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4447. }
  4448. }
  4449. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4450. }
  4451. else if(gunType[gun_index] == 'O')
  4452. {
  4453. tempIndex = gun_index;
  4454. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4455. {
  4456. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4457. {
  4458. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  4459. }
  4460. }
  4461. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4462. }
  4463. else
  4464. {
  4465. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4466. {
  4467. tempIndex = 2;
  4468. }
  4469. else
  4470. {
  4471. tempIndex = gun_index;
  4472. }
  4473. for (int index = 0; index < AC_QUANTITY; index++)
  4474. {
  4475. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4476. {
  4477. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  4478. }
  4479. }
  4480. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4481. }
  4482. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  4483. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  4484. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  4485. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  4486. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4487. //idx_sample=2;
  4488. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  4489. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4490. if(gunType[gun_index] == 'J')
  4491. {
  4492. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4493. {
  4494. tempIndex = ((gun_index==2) ? 1: 0);
  4495. }
  4496. else
  4497. {
  4498. tempIndex = gun_index;
  4499. }
  4500. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4501. {
  4502. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4503. {
  4504. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  4505. }
  4506. } // END OF FOR CHAdeMO_QUANTITY
  4507. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4508. }
  4509. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4510. {
  4511. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4512. {
  4513. tempIndex = ((gun_index==2) ? 1: 0);
  4514. }
  4515. else
  4516. {
  4517. tempIndex = gun_index;
  4518. }
  4519. for (int index = 0; index < CCS_QUANTITY; index++)
  4520. {
  4521. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4522. {
  4523. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  4524. }
  4525. } // END OF CCS_QUANTITY
  4526. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4527. }
  4528. else if(gunType[gun_index] == 'G')
  4529. {
  4530. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4531. {
  4532. tempIndex = ((gun_index==2) ? 1: 0);
  4533. }
  4534. else
  4535. {
  4536. tempIndex = gun_index;
  4537. }
  4538. for (int index = 0; index < GB_QUANTITY; index++)
  4539. {
  4540. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4541. {
  4542. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  4543. }
  4544. } // END OF GB_QUANTITY
  4545. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4546. }
  4547. else if(gunType[gun_index] == 'O')
  4548. {
  4549. tempIndex = gun_index;
  4550. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4551. {
  4552. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4553. {
  4554. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  4555. }
  4556. }
  4557. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4558. }
  4559. else
  4560. {
  4561. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4562. {
  4563. tempIndex = 2;
  4564. }
  4565. else
  4566. {
  4567. tempIndex = gun_index;
  4568. }
  4569. for (int index = 0; index < AC_QUANTITY; index++)
  4570. {
  4571. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4572. {
  4573. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  4574. }
  4575. }
  4576. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  4577. }
  4578. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  4579. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  4580. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  4581. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  4582. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4583. //idx_sample=3;
  4584. //********************************(4)Power.Active.Import************************************************/
  4585. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4586. if(gunType[gun_index] == 'J')
  4587. {
  4588. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4589. {
  4590. tempIndex = ((gun_index==2) ? 1: 0);
  4591. }
  4592. else
  4593. {
  4594. tempIndex = gun_index;
  4595. }
  4596. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4597. {
  4598. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4599. {
  4600. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  4601. }
  4602. } // END OF FOR
  4603. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4604. }
  4605. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4606. {
  4607. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4608. {
  4609. tempIndex = ((gun_index==2) ? 1: 0);
  4610. }
  4611. else
  4612. {
  4613. tempIndex = gun_index;
  4614. }
  4615. for (int index = 0; index < CCS_QUANTITY; index++)
  4616. {
  4617. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4618. {
  4619. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  4620. }
  4621. }
  4622. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4623. }
  4624. else if(gunType[gun_index] == 'G')
  4625. {
  4626. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4627. {
  4628. tempIndex = ((gun_index==2) ? 1: 0);
  4629. }
  4630. else
  4631. {
  4632. tempIndex = gun_index;
  4633. }
  4634. for (int index = 0; index < GB_QUANTITY; index++)
  4635. {
  4636. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4637. {
  4638. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4639. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  4640. }
  4641. }
  4642. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4643. }
  4644. else if(gunType[gun_index] == 'O')
  4645. {
  4646. tempIndex = gun_index;
  4647. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4648. {
  4649. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4650. {
  4651. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4652. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  4653. }
  4654. }
  4655. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4656. }
  4657. else
  4658. {
  4659. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4660. {
  4661. tempIndex = 2;
  4662. }
  4663. else
  4664. {
  4665. tempIndex = gun_index;
  4666. }
  4667. for (int index = 0; index < AC_QUANTITY; index++)
  4668. {
  4669. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4670. {
  4671. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  4672. }
  4673. }
  4674. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  4675. }
  4676. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  4677. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  4678. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  4679. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  4680. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  4681. //idx_sample=4;
  4682. //***********************************************(5)VOLTAGE L1******************************************************/
  4683. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4684. if(gunType[gun_index] == 'J')
  4685. {
  4686. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4687. {
  4688. tempIndex = ((gun_index==2) ? 1: 0);
  4689. }
  4690. else
  4691. {
  4692. tempIndex = gun_index;
  4693. }
  4694. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4695. {
  4696. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4697. {
  4698. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  4699. }
  4700. }
  4701. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4702. }
  4703. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4704. {
  4705. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4706. {
  4707. tempIndex = ((gun_index==2) ? 1: 0);
  4708. }
  4709. else
  4710. {
  4711. tempIndex = gun_index;
  4712. }
  4713. for (int index = 0; index < CCS_QUANTITY; index++)
  4714. {
  4715. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4716. {
  4717. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  4718. }
  4719. }
  4720. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4721. }
  4722. else if(gunType[gun_index] == 'G')
  4723. {
  4724. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4725. {
  4726. tempIndex = ((gun_index==2) ? 1: 0);
  4727. }
  4728. else
  4729. {
  4730. tempIndex = gun_index;
  4731. }
  4732. for (int index = 0; index < GB_QUANTITY; index++)
  4733. {
  4734. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4735. {
  4736. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  4737. }
  4738. }
  4739. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4740. }
  4741. else if(gunType[gun_index] == 'O')
  4742. {
  4743. tempIndex = gun_index;
  4744. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4745. {
  4746. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4747. {
  4748. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  4749. }
  4750. }
  4751. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4752. }
  4753. else
  4754. {
  4755. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4756. {
  4757. tempIndex = 2;
  4758. }
  4759. else
  4760. {
  4761. tempIndex = gun_index;
  4762. }
  4763. for (int index = 0; index < AC_QUANTITY; index++)
  4764. {
  4765. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4766. {
  4767. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  4768. }
  4769. }
  4770. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  4771. }
  4772. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  4773. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  4774. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  4775. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  4776. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4777. //***********************************************(6)SOC******************************************************/
  4778. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  4779. {
  4780. //idx_sample=5;
  4781. //sampledValue = NULL;
  4782. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != 'O'))
  4783. {
  4784. tempIndex = ((gun_index==2) ? 1: 0);
  4785. }
  4786. else
  4787. {
  4788. tempIndex = gun_index;
  4789. }
  4790. if(gunType[gun_index] == 'J')
  4791. {
  4792. //tempIndex = ((gun_index==2) ? 1: 0);
  4793. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4794. {
  4795. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4796. {
  4797. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  4798. }
  4799. }
  4800. }
  4801. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4802. {
  4803. //tempIndex = ((gun_index==2) ? 1: 0);
  4804. for (int index = 0; index < CCS_QUANTITY; index++)
  4805. {
  4806. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4807. {
  4808. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  4809. }
  4810. }
  4811. }
  4812. else if(gunType[gun_index] == 'G')
  4813. {
  4814. //tempIndex = ((gun_index==2) ? 1: 0);
  4815. for (int index = 0; index < GB_QUANTITY; index++)
  4816. {
  4817. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4818. {
  4819. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  4820. }
  4821. }
  4822. }
  4823. else if(gunType[gun_index] == 'O')
  4824. {
  4825. //tempIndex = ((gun_index==2) ? 1: 0);
  4826. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4827. {
  4828. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4829. {
  4830. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  4831. }
  4832. }
  4833. }
  4834. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  4835. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  4836. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  4837. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  4838. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  4839. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  4840. }
  4841. //********************************(7)Current.Import L2************************************************/
  4842. // Only for AC 3 phase
  4843. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4844. {
  4845. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4846. {
  4847. tempIndex = 2;
  4848. }
  4849. else
  4850. {
  4851. tempIndex = gun_index;
  4852. }
  4853. for (int index = 0; index < AC_QUANTITY; index++)
  4854. {
  4855. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4856. {
  4857. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  4858. }
  4859. }
  4860. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  4861. }
  4862. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  4863. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  4864. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  4865. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  4866. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4867. //********************************(8)Current.Import L3************************************************/
  4868. // Only for AC 3 phase
  4869. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4870. {
  4871. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4872. {
  4873. tempIndex = 2;
  4874. }
  4875. else
  4876. {
  4877. tempIndex = gun_index;
  4878. }
  4879. for (int index = 0; index < AC_QUANTITY; index++)
  4880. {
  4881. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4882. {
  4883. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  4884. }
  4885. }
  4886. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  4887. }
  4888. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  4889. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  4890. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  4891. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  4892. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4893. //***********************************************(9)VOLTAGE L2******************************************************/
  4894. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4895. {
  4896. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4897. {
  4898. tempIndex = 2;
  4899. }
  4900. else
  4901. {
  4902. tempIndex = gun_index;
  4903. }
  4904. for (int index = 0; index < AC_QUANTITY; index++)
  4905. {
  4906. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4907. {
  4908. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  4909. }
  4910. }
  4911. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  4912. }
  4913. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  4914. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  4915. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  4916. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  4917. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4918. //***********************************************(10)VOLTAGE L3******************************************************/
  4919. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4920. {
  4921. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4922. {
  4923. tempIndex = 2;
  4924. }
  4925. else
  4926. {
  4927. tempIndex = gun_index;
  4928. }
  4929. for (int index = 0; index < AC_QUANTITY; index++)
  4930. {
  4931. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4932. {
  4933. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  4934. }
  4935. }
  4936. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  4937. }
  4938. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  4939. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  4940. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  4941. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  4942. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4943. // Message create ====================================================================================================
  4944. if(TRUE)
  4945. {
  4946. json_object *MeterValueReq = json_object_new_object();
  4947. json_object *MeterValues = json_object_new_array();
  4948. json_object *sampledValues = json_object_new_array();
  4949. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  4950. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  4951. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  4952. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  4953. {
  4954. json_object *MeterValue = json_object_new_object();
  4955. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  4956. {
  4957. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  4958. {
  4959. json_object *sampledValue = json_object_new_object();
  4960. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  4961. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  4962. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  4963. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  4964. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  4965. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  4966. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  4967. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  4968. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  4969. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  4970. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  4971. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  4972. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  4973. json_object_array_add(sampledValues, sampledValue);
  4974. }
  4975. }
  4976. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  4977. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  4978. json_object_array_add(MeterValues, MeterValue);
  4979. }
  4980. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  4981. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  4982. ,gun_index + 1
  4983. ,MESSAGE_TYPE_CALL
  4984. ,guid
  4985. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  4986. json_object_put(MeterValueReq);
  4987. }
  4988. // Put request guid to hash map
  4989. sprintf(tempdata, "MeterValues,%d", (gun_index));
  4990. 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*/)
  4991. {
  4992. result = PASS;
  4993. //DEBUG_INFO("MeterValues mapitem pass\n");
  4994. }
  4995. if((dataType != ReadingContext_Trigger) &&
  4996. (dataType != ReadingContext_Sample_Clock) &&
  4997. (ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1))
  4998. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  4999. else
  5000. {
  5001. if(FirstHeartBeat)
  5002. LWS_Send(queuedata +2);
  5003. }
  5004. return result;
  5005. }
  5006. //==========================================
  5007. // send confirm routine
  5008. //==========================================
  5009. int sendCancelReservationConfirmation(char *uuid,char *payload)
  5010. {
  5011. mtrace();
  5012. int result = FAIL;
  5013. char message[100]={0};
  5014. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  5015. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5016. LWS_Send(message);
  5017. result = TRUE;
  5018. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  5019. return result;
  5020. }
  5021. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  5022. {
  5023. mtrace();
  5024. int result = FAIL;
  5025. char message[100]={0};
  5026. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  5027. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5028. LWS_Send(message);
  5029. result = TRUE;
  5030. return result;
  5031. }
  5032. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  5033. {
  5034. mtrace();
  5035. int result = FAIL;
  5036. char message[100]={0};
  5037. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  5038. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5039. LWS_Send(message);
  5040. result = TRUE;
  5041. return result;
  5042. }
  5043. int sendClearCacheConfirmation(char *uuid,char *payload)
  5044. {
  5045. mtrace();
  5046. int result = FAIL;
  5047. char message[500]={0};
  5048. DEBUG_INFO("sendClearCacheConfirmation...\n");
  5049. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5050. LWS_Send(message);
  5051. return result;
  5052. }
  5053. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  5054. {
  5055. mtrace();
  5056. int result = FAIL;
  5057. char message[500]={0};
  5058. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  5059. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5060. LWS_Send(message);
  5061. return result;
  5062. }
  5063. int sendDataTransferConfirmation(char *uuid,char *payload)
  5064. {
  5065. mtrace();
  5066. char statusStr[20]={0};
  5067. char dataStr[10]={0};
  5068. char sstr[20]={0};
  5069. int c = 0;
  5070. char *loc;
  5071. int result = FAIL;
  5072. DEBUG_INFO("sendDataTransferConfirmation...\n");
  5073. /**********************status**************************/
  5074. loc = strstr(payload, "status");
  5075. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5076. c = 0;
  5077. while (loc[3+strlen("status")+c] != '\"')
  5078. {
  5079. sstr[c] = loc[3+strlen("status")+c];
  5080. c++;
  5081. }
  5082. sstr[c] = '\0';
  5083. strcpy(statusStr, sstr);
  5084. /**********************data**************************/
  5085. loc = strstr(payload, "data");
  5086. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5087. c = 0;
  5088. while (loc[3+strlen("data")+c] != '\"')
  5089. {
  5090. sstr[c] = loc[3+strlen("data")+c];
  5091. c++;
  5092. }
  5093. sstr[c] = '\0';
  5094. strcpy(dataStr, sstr);
  5095. return result;
  5096. }
  5097. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  5098. {
  5099. mtrace();
  5100. int result = FAIL;
  5101. char message[1000]={0};
  5102. int CompositeScheduleIndex = 0;
  5103. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  5104. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  5105. if(nPeriod == 0)
  5106. {
  5107. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  5108. {
  5109. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  5110. ,MESSAGE_TYPE_CALLRESULT
  5111. ,uuid
  5112. ,payload
  5113. ,connectorIdInt);
  5114. }
  5115. else
  5116. {
  5117. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  5118. ,MESSAGE_TYPE_CALLRESULT
  5119. ,uuid
  5120. ,payload
  5121. ,connectorIdInt
  5122. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5123. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5124. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5125. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  5126. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  5127. }
  5128. }
  5129. else
  5130. {
  5131. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  5132. ,MESSAGE_TYPE_CALLRESULT
  5133. ,uuid
  5134. ,payload
  5135. ,connectorIdInt
  5136. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5137. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5138. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5139. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  5140. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  5141. {
  5142. if (idx_sample == 0)
  5143. {
  5144. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5145. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5146. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5147. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5148. }
  5149. else
  5150. {
  5151. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5152. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5153. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5154. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5155. }
  5156. }
  5157. sprintf(message + strlen(message), "]}}]");
  5158. }
  5159. LWS_Send(message);
  5160. result = TRUE;
  5161. return result;
  5162. }
  5163. int sendGetConfigurationConfirmation(char *uuid)
  5164. {
  5165. mtrace();
  5166. int result = FAIL;
  5167. int MaxKeySupported = 0;
  5168. int sentConfigurationNumber= 0;
  5169. int sentunConfigurationNumber= 0;
  5170. char message[4000]={0};
  5171. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  5172. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  5173. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  5174. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  5175. ,MESSAGE_TYPE_CALLRESULT
  5176. ,uuid );
  5177. //configuration key
  5178. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  5179. {
  5180. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  5181. {
  5182. if (sentConfigurationNumber == 0)
  5183. {
  5184. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5185. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5186. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5187. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5188. }
  5189. else
  5190. {
  5191. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5192. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5193. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5194. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5195. }
  5196. sentConfigurationNumber = sentConfigurationNumber + 1;
  5197. }
  5198. }
  5199. sprintf(message + strlen(message), "]");
  5200. if(UnknownKeynum != 0)
  5201. {
  5202. sprintf(message + strlen(message), ",\"unknownKey\":[");
  5203. //unkown key
  5204. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  5205. {
  5206. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  5207. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  5208. if(sentunConfigurationNumber == 0)
  5209. {
  5210. sprintf(message + strlen(message), "\"%s\""
  5211. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5212. }
  5213. else
  5214. {
  5215. sprintf(message + strlen(message), ",\"%s\""
  5216. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5217. }
  5218. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  5219. }
  5220. sprintf(message + strlen(message), "]");
  5221. }
  5222. sprintf(message + strlen(message), "}]");
  5223. LWS_Send(message);
  5224. return result;
  5225. }
  5226. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  5227. {
  5228. mtrace();
  5229. int result = FAIL;
  5230. char message[400]={0};
  5231. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  5232. if(strcmp(payload,"")==0)
  5233. {
  5234. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5235. }
  5236. else
  5237. {
  5238. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5239. }
  5240. LWS_Send(message);
  5241. result = TRUE;
  5242. return result;
  5243. }
  5244. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  5245. {
  5246. mtrace();
  5247. int result = FAIL;
  5248. char message[80]={0};
  5249. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  5250. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  5251. LWS_Send(message);
  5252. result = TRUE;
  5253. return result;
  5254. }
  5255. int sendRemoteStartConfirmation(char *uuid,char *payload)
  5256. {
  5257. mtrace();
  5258. int result = FAIL;
  5259. char message[80]={0};
  5260. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  5261. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5262. LWS_Send(message);
  5263. result = TRUE;
  5264. return result;
  5265. }
  5266. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5267. {
  5268. mtrace();
  5269. int result = FAIL;
  5270. char message[80]={0};
  5271. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5272. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5273. LWS_Send(message);
  5274. result = TRUE;
  5275. return result;
  5276. }
  5277. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5278. {
  5279. mtrace();
  5280. int result = FAIL;
  5281. char message[80]={0};
  5282. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5283. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  5284. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5285. LWS_Send(message);
  5286. result = TRUE;
  5287. return result;
  5288. }
  5289. int sendResetConfirmation(char *uuid,char *payload)
  5290. {
  5291. mtrace();
  5292. int result = FAIL;
  5293. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  5294. char message[80]={0};
  5295. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  5296. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5297. LWS_Send(message);
  5298. result = TRUE;
  5299. return result;
  5300. }
  5301. int sendSendLocalListConfirmation(char *uuid,char *payload)
  5302. {
  5303. mtrace();
  5304. int result = FAIL;
  5305. char message[500]={0};
  5306. // [ 3, "1571284266109", { "status": "Accepted" } ]
  5307. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5308. LWS_Send(message);
  5309. result = TRUE;
  5310. return result;
  5311. }
  5312. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  5313. {
  5314. mtrace();
  5315. int result = FAIL;
  5316. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  5317. char message[80]={0};
  5318. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  5319. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5320. LWS_Send(message);
  5321. result = TRUE;
  5322. return result;
  5323. }
  5324. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  5325. {
  5326. mtrace();
  5327. int result = FAIL;
  5328. char message[80]={0};
  5329. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  5330. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5331. LWS_Send(message);
  5332. result = TRUE;
  5333. return result;
  5334. }
  5335. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  5336. {
  5337. mtrace();
  5338. int result = FAIL;
  5339. char message[80]={0};
  5340. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5341. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  5342. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5343. LWS_Send(message);
  5344. result = TRUE;
  5345. return result;
  5346. }
  5347. int sendUpdateFirmwareConfirmation(char *uuid)
  5348. {
  5349. mtrace();
  5350. int result = FAIL;
  5351. char message[60]={0};
  5352. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5353. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  5354. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5355. LWS_Send(message);
  5356. result = TRUE;
  5357. return result;
  5358. }
  5359. //==========================================
  5360. // send CallError routine
  5361. //==========================================
  5362. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  5363. {
  5364. mtrace();
  5365. char message[220]={0};
  5366. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  5367. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  5368. LWS_Send(message);
  5369. }
  5370. //==========================================
  5371. // Handle server request routine Start
  5372. //==========================================
  5373. int handleCancelReservationRequest(char *uuid, char *payload)
  5374. {
  5375. mtrace();
  5376. int result = FAIL;
  5377. int gunNO = 0;
  5378. int reservationIdInt = -1;
  5379. char comfirmstr[20];
  5380. DEBUG_INFO("handleCancelReservationRequest...\n");
  5381. json_object *CancelReservation;
  5382. CancelReservation = json_tokener_parse(payload);
  5383. if(!is_error(CancelReservation))
  5384. {
  5385. // Required data
  5386. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  5387. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  5388. }
  5389. json_object_put(CancelReservation);
  5390. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  5391. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5392. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  5393. if(reservationIdInt != -1)
  5394. {
  5395. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  5396. //check Transaction active
  5397. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5398. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5399. {
  5400. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  5401. {
  5402. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5403. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5404. if(gunType[2] == 'J')
  5405. {
  5406. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  5407. }
  5408. else
  5409. {
  5410. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  5411. }
  5412. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5413. goto end;
  5414. }
  5415. }
  5416. for (int index = 0; index < CCS_QUANTITY; index++)
  5417. {
  5418. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  5419. {
  5420. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5421. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5422. if((gunType[2] == 'U') || (gunType[2] == 'E'))
  5423. {
  5424. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  5425. }
  5426. else
  5427. {
  5428. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  5429. }
  5430. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5431. goto end;
  5432. }
  5433. }
  5434. for (int index = 0; index < GB_QUANTITY; index++)
  5435. {
  5436. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  5437. {
  5438. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5439. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5440. if(gunType[2] == 'G')
  5441. {
  5442. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  5443. }
  5444. else
  5445. {
  5446. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  5447. }
  5448. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5449. goto end;
  5450. }
  5451. }
  5452. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5453. {
  5454. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  5455. {
  5456. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5457. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5458. if(gunType[2] == 'G')
  5459. {
  5460. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index + 1;
  5461. }
  5462. else
  5463. {
  5464. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  5465. }
  5466. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5467. goto end;
  5468. }
  5469. }
  5470. for (int index = 0; index < AC_QUANTITY; index++)
  5471. {
  5472. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  5473. {
  5474. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5475. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5476. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5477. {
  5478. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  5479. }
  5480. else
  5481. {
  5482. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  5483. }
  5484. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5485. goto end;
  5486. }
  5487. }
  5488. }
  5489. //The reservationId does NOT match the reservationId
  5490. sendCancelReservationConfirmation(uuid, comfirmstr);
  5491. end:
  5492. // Fill in ocpp packet uuid
  5493. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  5494. return result;
  5495. }
  5496. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  5497. {
  5498. mtrace();
  5499. int result = FAIL;
  5500. int gunIndex = 0;
  5501. char typeStr[16]={0};
  5502. char comfirmstr[20];
  5503. int specificId = FALSE;
  5504. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  5505. json_object *ChangeAvailability;
  5506. ChangeAvailability = json_tokener_parse(payload);
  5507. if(!is_error(ChangeAvailability))
  5508. {
  5509. // Required data
  5510. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  5511. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  5512. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  5513. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  5514. }
  5515. json_object_put(ChangeAvailability);
  5516. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5517. {
  5518. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  5519. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  5520. }
  5521. else if(gunIndex == 0)
  5522. {
  5523. for(int i=0; i < gunTotalNumber; i++)
  5524. {
  5525. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  5526. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  5527. }
  5528. }
  5529. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5530. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5531. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  5532. {
  5533. specificId = TRUE;
  5534. }
  5535. if(specificId == FALSE)
  5536. goto end;
  5537. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  5538. {
  5539. //----------------------gunIndex is 0 ------------------------------------------------//
  5540. if(gunIndex == 0)
  5541. {
  5542. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5543. {
  5544. for(int i=0; i < gunTotalNumber; i++)
  5545. {
  5546. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5547. {
  5548. if ((gunType[i] == 'J')&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  5549. {
  5550. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5551. {
  5552. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5553. goto end;
  5554. }
  5555. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5556. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5557. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5558. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5559. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5560. {
  5561. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5562. goto end;
  5563. }
  5564. }
  5565. }//END FOR CHAdeMO_QUANTITY
  5566. for (int index = 0; index < CCS_QUANTITY; index++)
  5567. {
  5568. if (((gunType[i] == 'U')||(gunType[i] == 'E'))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  5569. {
  5570. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  5571. {
  5572. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5573. goto end;
  5574. }
  5575. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5576. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5577. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5578. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5579. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5580. {
  5581. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5582. goto end;
  5583. }
  5584. }
  5585. }//END FOR CCS_QUANTITY
  5586. for (int index = 0; index < GB_QUANTITY; index++)
  5587. {
  5588. if ((gunType[i] == 'G')&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  5589. {
  5590. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5591. {
  5592. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5593. goto end;
  5594. }
  5595. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5596. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5597. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5598. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5599. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5600. {
  5601. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5602. goto end;
  5603. }
  5604. }
  5605. }// END FOR GB_QUANTITY
  5606. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5607. {
  5608. if ((gunType[i] == 'O')&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  5609. {
  5610. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5611. {
  5612. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5613. goto end;
  5614. }
  5615. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  5616. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  5617. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  5618. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  5619. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5620. {
  5621. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5622. goto end;
  5623. }
  5624. }
  5625. }// END FOR GENERAL_GUN_QUANTITY
  5626. for (int index = 0; index < AC_QUANTITY; index++)
  5627. {
  5628. if (((gunType[i] > '0')&&(gunType[i] <= '9'))&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  5629. {
  5630. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5631. {
  5632. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5633. goto end;
  5634. }
  5635. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5636. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5637. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5638. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5639. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5640. {
  5641. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5642. goto end;
  5643. }
  5644. }
  5645. }//END FOR AC_QUANTITY
  5646. }// END FOR gunTotalNumber
  5647. }
  5648. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5649. {
  5650. for(int i=0; i < gunTotalNumber; i++)
  5651. {
  5652. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5653. {
  5654. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5655. goto end;
  5656. }
  5657. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5658. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  5659. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  5660. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  5661. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5662. {
  5663. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5664. goto end;
  5665. }
  5666. }
  5667. }
  5668. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5669. goto end;
  5670. }
  5671. //----------------------gunIndex is not 0 ------------------------------------------------//
  5672. //check Transaction active
  5673. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5674. {
  5675. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J'))
  5676. {
  5677. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  5678. {
  5679. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5680. goto end;
  5681. }
  5682. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5683. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5684. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5685. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5686. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5687. {
  5688. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5689. goto end;
  5690. }
  5691. else
  5692. {
  5693. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  5694. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5695. goto end;
  5696. }
  5697. }
  5698. }//END FOR CHAdeMO_QUANTITY
  5699. for (int index = 0; index < CCS_QUANTITY; index++)
  5700. {
  5701. if ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E')))
  5702. {
  5703. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  5704. {
  5705. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5706. goto end;
  5707. }
  5708. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5709. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5710. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5711. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5712. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5713. {
  5714. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5715. goto end;
  5716. }
  5717. else
  5718. {
  5719. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  5720. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5721. goto end;
  5722. }
  5723. }
  5724. }//END FOR CCS_QUANTITY
  5725. for (int index = 0; index < GB_QUANTITY; index++)
  5726. {
  5727. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))
  5728. {
  5729. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5730. {
  5731. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5732. goto end;
  5733. }
  5734. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5735. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5736. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5737. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5738. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5739. {
  5740. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5741. goto end;
  5742. }
  5743. else
  5744. {
  5745. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  5746. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5747. goto end;
  5748. }
  5749. }
  5750. }// END FOR GB_QUANTITY
  5751. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5752. {
  5753. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'O'))
  5754. {
  5755. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5756. {
  5757. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5758. goto end;
  5759. }
  5760. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  5761. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  5762. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  5763. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  5764. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5765. {
  5766. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5767. goto end;
  5768. }
  5769. else
  5770. {
  5771. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  5772. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5773. goto end;
  5774. }
  5775. }
  5776. }// END FOR GENERAL_GUN_QUANTITY
  5777. for (int index = 0; index < AC_QUANTITY; index++)
  5778. {
  5779. if ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))
  5780. {
  5781. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5782. {
  5783. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5784. goto end;
  5785. }
  5786. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5787. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5788. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5789. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5790. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5791. {
  5792. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5793. goto end;
  5794. }
  5795. else
  5796. {
  5797. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  5798. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5799. goto end;
  5800. }
  5801. }
  5802. }//END FOR AC_QUANTITY
  5803. }//END FOR AvailabilityTypeStr[Inoperative]
  5804. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  5805. {
  5806. //----------------------gunIndex is 0 ------------------------------------------------//
  5807. if(gunIndex == 0)
  5808. {
  5809. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5810. {
  5811. for(int i=0; i < gunTotalNumber; i++)
  5812. {
  5813. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5814. {
  5815. if ((gunType[i] == 'J' )&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J')) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5816. {
  5817. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5818. goto end;
  5819. }
  5820. }//END FOR CHAdeMO_QUANTITY
  5821. for (int index = 0; index < CCS_QUANTITY; index++)
  5822. {
  5823. if (((gunType[i] == 'U')||(gunType[i] == 'E'))&&(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
  5824. {
  5825. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5826. goto end;
  5827. }
  5828. }//END FOR CCS_QUANTITY
  5829. for (int index = 0; index < GB_QUANTITY; index++)
  5830. {
  5831. if ((gunType[i] == 'G')&&(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
  5832. {
  5833. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5834. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5835. goto end;
  5836. }
  5837. }// END FOR GB_QUANTITY
  5838. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5839. {
  5840. if ((gunType[i] == 'O')&&(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
  5841. {
  5842. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5843. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5844. goto end;
  5845. }
  5846. }// END FOR GENERAL_GUN_QUANTITY
  5847. for (int index = 0; index < AC_QUANTITY; index++)
  5848. {
  5849. if (((gunType[i] > '0')&&(gunType[i] <= '9')) &&(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
  5850. {
  5851. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5852. goto end;
  5853. }
  5854. }//END FOR CHAdeMO_QUANTITY
  5855. }// END FOR gunTotalNumber
  5856. }
  5857. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5858. {
  5859. for(int i=0; i < gunTotalNumber; i++)
  5860. {
  5861. for (int index = 0; index < AC_QUANTITY; index++)
  5862. {
  5863. if (((gunType[i] > '0')&&(gunType[i] <= '9')) &&(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
  5864. {
  5865. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5866. goto end;
  5867. }
  5868. }//END FOR CHAdeMO_QUANTITY
  5869. } // END FOR gunTotalNumber
  5870. }
  5871. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5872. goto end;
  5873. }
  5874. //----------------------gunIndex is not 0 ------------------------------------------------//
  5875. //check Transaction active
  5876. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5877. {
  5878. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'J') ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5879. {
  5880. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5881. goto end;
  5882. }
  5883. }//END FOR CHAdeMO_QUANTITY
  5884. for (int index = 0; index < CCS_QUANTITY; index++)
  5885. {
  5886. if ((((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5887. {
  5888. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5889. goto end;
  5890. }
  5891. }//END FOR CCS_QUANTITY
  5892. for (int index = 0; index < GB_QUANTITY; index++)
  5893. {
  5894. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5895. {
  5896. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5897. goto end;
  5898. }
  5899. }// END FOR GB_QUANTITY
  5900. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5901. {
  5902. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'O'))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5903. {
  5904. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5905. goto end;
  5906. }
  5907. }// END FOR GENERAL_GUN_QUANTITY
  5908. for (int index = 0; index < AC_QUANTITY; index++)
  5909. {
  5910. if (((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9'))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5911. {
  5912. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5913. goto end;
  5914. }
  5915. }//END FOR AC_QUANTITY
  5916. }//END FOR AvailabilityTypeStr[Operative]
  5917. end:
  5918. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5919. {
  5920. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  5921. }
  5922. else
  5923. {
  5924. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  5925. }
  5926. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5927. {
  5928. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5929. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5930. }
  5931. else if(gunIndex == 0)
  5932. {
  5933. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5934. {
  5935. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  5936. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  5937. }
  5938. }
  5939. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  5940. return result;
  5941. }
  5942. int handleChangeConfigurationRequest(char *uuid, char *payload)
  5943. {
  5944. mtrace();
  5945. int result = FAIL;
  5946. char keystr[40]={0};
  5947. char valuestr[100]={0};
  5948. char comfirmstr[20]={0};
  5949. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  5950. json_object *ChangeConfiguration;
  5951. ChangeConfiguration = json_tokener_parse(payload);
  5952. if(!is_error(ChangeConfiguration))
  5953. {
  5954. // Required data
  5955. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  5956. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  5957. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  5958. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  5959. }
  5960. json_object_put(ChangeConfiguration);
  5961. if((uuid==NULL) || (payload ==NULL) )
  5962. {
  5963. DEBUG_ERROR("Payload is null\n");
  5964. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5965. }
  5966. else
  5967. {
  5968. int status = setKeyValue(keystr, valuestr);
  5969. switch(status)
  5970. {
  5971. case ConfigurationStatus_Accepted:
  5972. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  5973. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  5974. StoreConfigurationTable();
  5975. break;
  5976. case RebootRequired:
  5977. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  5978. StoreConfigurationTable();
  5979. break;
  5980. case NotSupported:
  5981. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  5982. break;
  5983. case ConfigurationStatus_Rejected:
  5984. default:
  5985. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5986. break;
  5987. }
  5988. }
  5989. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  5990. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  5991. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  5992. {
  5993. ChageWebSocketPingInterval(atoi(valuestr));
  5994. }
  5995. if((strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  5996. {
  5997. SetOcppConnStatus(FALSE);
  5998. }
  5999. return result;
  6000. }
  6001. int handleClearCacheRequest(char *uuid, char *payload)
  6002. {
  6003. mtrace();
  6004. int result = FAIL;
  6005. char comfirmstr[20];
  6006. char rmFileCmd[100]={0};
  6007. struct stat stats;
  6008. DEBUG_INFO("handleClearCacheRequest...\n");
  6009. stat("/Storage/OCPP", &stats);
  6010. // Check for directory existence
  6011. if (S_ISDIR(stats.st_mode) == 1)
  6012. {}
  6013. else
  6014. {
  6015. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  6016. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  6017. system(rmFileCmd);
  6018. }
  6019. if(OCPP_cleanLocalCache())
  6020. {
  6021. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  6022. }
  6023. else
  6024. {
  6025. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  6026. }
  6027. sendClearCacheConfirmation(uuid, comfirmstr);
  6028. return result;
  6029. }
  6030. int handleClearChargingProfileRequest(char *uuid, char *payload)
  6031. {
  6032. mtrace();
  6033. int result = FAIL;
  6034. int resultRename;
  6035. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  6036. char chargingProfilePurposeStr[26]={0};
  6037. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  6038. char tempchargingProfilePurposeStr[26]={0};
  6039. char str[100]={0};
  6040. char fname[200]={0};
  6041. char comfirmstr[20]={0};
  6042. char word[1600]={0};
  6043. int clearflag = FALSE;
  6044. int chargingProfileIdIsNULL = FALSE;
  6045. int connectorIsNULL = FALSE;
  6046. int chargingProfilePurposeIsNULL = FALSE;
  6047. int stackLevelIsNULL = FALSE;
  6048. //int GotoEnd = FALSE;
  6049. FILE *fptr1, *fptr2;
  6050. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  6051. int n_chargingProfile=0;
  6052. int isEmptyFile = FALSE;
  6053. char sLineWord[1600]={0};
  6054. char chargingProfiles[10][100]={0};
  6055. int ChargeProfileCount = 0;
  6056. int ch;
  6057. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  6058. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  6059. json_object *ClearChargingProfile;
  6060. ClearChargingProfile = json_tokener_parse(payload);
  6061. if(!is_error(ClearChargingProfile))
  6062. {
  6063. // Optional data
  6064. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  6065. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  6066. else
  6067. chargingProfileIdIsNULL = TRUE;
  6068. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  6069. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  6070. else
  6071. connectorIsNULL = TRUE;
  6072. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  6073. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  6074. else
  6075. chargingProfilePurposeIsNULL = TRUE;
  6076. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  6077. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  6078. else
  6079. stackLevelIsNULL = TRUE;
  6080. }
  6081. json_object_put(ClearChargingProfile);
  6082. if(connectorIsNULL == FALSE)
  6083. {
  6084. switch(connectorIdInt)
  6085. {
  6086. case 0:
  6087. if(chargingProfilePurposeIsNULL == TRUE)
  6088. {
  6089. int l = 0;
  6090. strcpy(fname, ChargePointMaxProfile_JSON);
  6091. if((access(fname,F_OK))!=-1)
  6092. {
  6093. strcpy(chargingProfiles[l], fname);
  6094. l = l + 1;
  6095. }
  6096. strcpy(fname, TxDefaultProfile_0_JSON);
  6097. if((access(fname,F_OK))!=-1)
  6098. {
  6099. strcpy(chargingProfiles[l], fname);
  6100. l = l + 1;
  6101. }
  6102. ChargeProfileCount = l;
  6103. }
  6104. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  6105. {
  6106. strcpy(fname, ChargePointMaxProfile_JSON);
  6107. if((access(fname,F_OK))!=-1)
  6108. {
  6109. strcpy(chargingProfiles[0], fname);
  6110. ChargeProfileCount = 1;
  6111. }
  6112. }
  6113. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6114. {
  6115. strcpy(fname, TxDefaultProfile_0_JSON);
  6116. if((access(fname,F_OK))!=-1)
  6117. {
  6118. strcpy(chargingProfiles[0], fname);
  6119. ChargeProfileCount = 1;
  6120. }
  6121. }
  6122. break;
  6123. default:
  6124. if(chargingProfilePurposeIsNULL == TRUE)
  6125. {
  6126. int m = 0;
  6127. memset(fname, 0, ARRAY_SIZE(fname));
  6128. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6129. if((access(fname,F_OK))!=-1)
  6130. {
  6131. strcpy(chargingProfiles[m], fname);
  6132. m = m + 1;
  6133. }
  6134. memset(fname, 0, ARRAY_SIZE(fname));
  6135. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6136. if((access(fname,F_OK))!=-1)
  6137. {
  6138. strcpy(chargingProfiles[m], fname);
  6139. m = m + 1;
  6140. }
  6141. ChargeProfileCount = m;
  6142. }
  6143. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6144. {
  6145. //strcpy(fname, TxDefaultProfile_1_JSON);
  6146. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6147. if((access(fname,F_OK))!=-1)
  6148. {
  6149. strcpy(chargingProfiles[0], fname);
  6150. ChargeProfileCount = 1;
  6151. }
  6152. }
  6153. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  6154. {
  6155. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6156. if((access(fname,F_OK))!=-1)
  6157. {
  6158. strcpy(chargingProfiles[0], fname);
  6159. ChargeProfileCount = 1;
  6160. }
  6161. //strcpy(fname, TxProfile_1_JSON);
  6162. }
  6163. //strcpy(fname, ChargePointMaxProfile_JSON );
  6164. break;
  6165. }
  6166. }
  6167. else // Check all Charging Profiles
  6168. {
  6169. int i = 0;
  6170. char fnametemp[200]={0};
  6171. ChargeProfileCount = 0;
  6172. //Check ChargePointMaxProfile.json exit
  6173. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  6174. {
  6175. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  6176. i = i + 1;
  6177. }
  6178. //Check TxDefaultProfile_0.json exit
  6179. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  6180. {
  6181. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  6182. i = i + 1;
  6183. }
  6184. //Check TxDefaultProfile_%d.json
  6185. for(int j=1; j <= gunTotalNumber; j++)
  6186. {
  6187. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6188. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  6189. if((access(fnametemp,F_OK))!=-1)
  6190. {
  6191. strcpy(chargingProfiles[i], fnametemp);
  6192. i = i + 1;
  6193. }
  6194. }
  6195. //Check TxProfile_%d.json
  6196. for(int j=1; j <= gunTotalNumber; j++)
  6197. {
  6198. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6199. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  6200. if((access(fnametemp,F_OK))!=-1)
  6201. {
  6202. strcpy(chargingProfiles[i], fnametemp);
  6203. i = i + 1;
  6204. }
  6205. }
  6206. ChargeProfileCount = i;
  6207. }// End connectorIsNULL is TRUE
  6208. if(ChargeProfileCount == 0)
  6209. {
  6210. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6211. goto end;
  6212. }
  6213. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  6214. {
  6215. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6216. goto end;
  6217. }
  6218. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  6219. {
  6220. memset(str, 0, ARRAY_SIZE(str));
  6221. // clear temp file
  6222. sprintf(str,"rm -f %s",temp);
  6223. system(str);
  6224. for(int k=0; k < ChargeProfileCount; k++)
  6225. {
  6226. memset(str, 0, ARRAY_SIZE(str));
  6227. //clear file in C
  6228. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6229. system(str);
  6230. }
  6231. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6232. goto end;
  6233. }
  6234. else if(connectorIsNULL == TRUE)
  6235. {
  6236. for(int k=0; k < ChargeProfileCount; k++)
  6237. {
  6238. fptr1 = fopen(chargingProfiles[k], "r");
  6239. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  6240. //Check Charging Profile Count
  6241. while(fscanf(fptr1, "%s", word) != EOF)
  6242. {
  6243. //DEBUG_INFO("word=%s\n",word);
  6244. if(strstr(word, "chargingProfileId")!= NULL)
  6245. {
  6246. //DEBUG_INFO("test chargingProfileId \n");
  6247. n_chargingProfile = n_chargingProfile + 1;
  6248. //DEBUG_INFO("chargingProfileId Found\n");
  6249. }
  6250. }
  6251. rewind(fptr1);
  6252. //search Charging Profile Element
  6253. //int i= 0;
  6254. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6255. {
  6256. json_object *tmpProfilee;
  6257. tmpProfilee = json_tokener_parse(sLineWord);
  6258. if(!is_error(tmpProfilee))
  6259. {
  6260. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  6261. {
  6262. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  6263. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  6264. }
  6265. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  6266. {
  6267. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  6268. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  6269. }
  6270. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  6271. {
  6272. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  6273. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  6274. }
  6275. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  6276. {
  6277. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  6278. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  6279. }
  6280. }
  6281. json_object_put(tmpProfilee);
  6282. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6283. {
  6284. //------- not write to fptr2-------//
  6285. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6286. //clearflag = TRUE;
  6287. }
  6288. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  6289. {
  6290. //------- not write to fptr2-------//
  6291. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6292. }
  6293. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6294. {
  6295. //------- not write to fptr2-------//
  6296. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6297. }
  6298. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  6299. {
  6300. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6301. }
  6302. else
  6303. {
  6304. fprintf(fptr2, sLineWord);//writing data into file
  6305. }
  6306. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6307. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6308. if(clearflag == TRUE)
  6309. {
  6310. fclose(fptr1);
  6311. fclose(fptr2);
  6312. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6313. system(str);
  6314. // clear temp file
  6315. sprintf(str,"rm -f %s",temp);
  6316. system(str);
  6317. }
  6318. else
  6319. {
  6320. fclose(fptr1);
  6321. fclose(fptr2);
  6322. memset(str, 0, ARRAY_SIZE(str));
  6323. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6324. system(str);
  6325. resultRename = rename(temp, chargingProfiles[k]);
  6326. if(resultRename == 0)
  6327. {
  6328. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  6329. }
  6330. else
  6331. {
  6332. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  6333. }
  6334. if(comfirmstr[0]== 0)
  6335. {
  6336. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6337. }
  6338. //Check chargingProfile is empty file
  6339. /*------ Read the file ----------------*/
  6340. fptr1=fopen(chargingProfiles[k],"r");
  6341. ch=fgetc(fptr1);
  6342. rewind(fptr1);
  6343. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6344. if(ch!=EOF)
  6345. {
  6346. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6347. {
  6348. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6349. if(sLineWord[0]=='\0')
  6350. {
  6351. isEmptyFile = TRUE;
  6352. break;
  6353. }
  6354. else
  6355. {
  6356. isEmptyFile = FALSE;
  6357. break;
  6358. }
  6359. }
  6360. }
  6361. else
  6362. isEmptyFile = TRUE;
  6363. fclose(fptr1);
  6364. if(isEmptyFile == TRUE)
  6365. {
  6366. memset(str, 0, ARRAY_SIZE(str));
  6367. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6368. system(str);
  6369. }
  6370. }
  6371. }// End of while(int k=0; k < ChargePointCount; k++)
  6372. }
  6373. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  6374. {
  6375. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  6376. for(int k=0; k < ChargeProfileCount; k++)
  6377. {
  6378. fptr1 = fopen(chargingProfiles[k], "r");
  6379. fptr2 = fopen(temp, "w+");
  6380. //Check Charging Profile Count
  6381. while(fscanf(fptr1, "%s", word) != EOF)
  6382. {
  6383. //DEBUG_INFO("word=%s\n",word);
  6384. if(strstr(word, "chargingProfileId")!= NULL)
  6385. {
  6386. n_chargingProfile = n_chargingProfile + 1;
  6387. }
  6388. }
  6389. rewind(fptr1);
  6390. //search Charging Profile Element
  6391. //int i= 0;
  6392. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6393. {
  6394. json_object *tmpProfilee;
  6395. tmpProfilee = json_tokener_parse(sLineWord);
  6396. if(!is_error(tmpProfilee))
  6397. {
  6398. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  6399. {
  6400. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  6401. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  6402. }
  6403. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  6404. {
  6405. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  6406. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  6407. }
  6408. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  6409. {
  6410. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  6411. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  6412. }
  6413. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  6414. {
  6415. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  6416. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  6417. }
  6418. }
  6419. json_object_put(tmpProfilee);
  6420. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6421. {
  6422. //------- not write to fptr2-------//
  6423. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6424. //clearflag = TRUE;
  6425. }
  6426. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6427. {
  6428. //------- not write to fptr2-------//
  6429. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6430. }
  6431. else if(stackLevelIsNULL == TRUE)
  6432. {
  6433. //Clear Whole File
  6434. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6435. clearflag = TRUE;
  6436. break;
  6437. }
  6438. else
  6439. {
  6440. fprintf(fptr2, sLineWord);//writing data into file
  6441. }
  6442. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6443. }
  6444. if(clearflag == TRUE)
  6445. {
  6446. fclose(fptr1);
  6447. fclose(fptr2);
  6448. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6449. system(str);
  6450. // clear temp file
  6451. sprintf(str,"rm -f %s",temp);
  6452. system(str);
  6453. }
  6454. else
  6455. {
  6456. fclose(fptr1);
  6457. fclose(fptr2);
  6458. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6459. system(str);
  6460. resultRename = rename(temp, chargingProfiles[k]);
  6461. if(resultRename == 0)
  6462. {
  6463. DEBUG_INFO("File ChargingProfile renamed successfully");
  6464. }
  6465. else
  6466. {
  6467. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6468. }
  6469. if(comfirmstr[0]== 0)
  6470. {
  6471. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6472. }
  6473. //Check chargingProfile is empty file
  6474. /*------ Read the file ----------------*/
  6475. fptr1=fopen(chargingProfiles[k],"r");
  6476. ch=fgetc(fptr1);
  6477. rewind(fptr1);
  6478. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6479. if(ch!=EOF)
  6480. {
  6481. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6482. {
  6483. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6484. if(sLineWord[0]=='\0')
  6485. {
  6486. isEmptyFile = TRUE;
  6487. break;
  6488. }
  6489. else
  6490. {
  6491. isEmptyFile = FALSE;
  6492. break;
  6493. }
  6494. }
  6495. }
  6496. else
  6497. isEmptyFile = TRUE;
  6498. fclose(fptr1);
  6499. if(isEmptyFile == TRUE)
  6500. {
  6501. memset(str, 0, ARRAY_SIZE(str));
  6502. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6503. system(str);
  6504. }
  6505. /*------- End of reading ---------------*/
  6506. }
  6507. } // while(int k=0; k < ChargeProfileCount; k++)
  6508. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  6509. end:
  6510. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  6511. {
  6512. if(connectorIdInt == 0)
  6513. {
  6514. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  6515. {
  6516. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx]);
  6517. }
  6518. }
  6519. else
  6520. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1]);
  6521. }
  6522. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  6523. return result;
  6524. }
  6525. void createFirmwareVersionByDataTransfer(void)
  6526. {
  6527. json_object *FirmwareDataTransfer = json_object_new_object();
  6528. // AC & DC model
  6529. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  6530. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  6531. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  6532. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  6533. // DC model
  6534. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  6535. {
  6536. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  6537. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  6538. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  6539. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  6540. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  6541. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  6542. }
  6543. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  6544. ((gunType[1] != '0') || (gunType[2] != '0') || (gunType[3] != '0')))
  6545. {
  6546. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  6547. }
  6548. // 4G model
  6549. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  6550. {
  6551. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  6552. }
  6553. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "Phihong Technology");
  6554. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  6555. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  6556. json_object_put(FirmwareDataTransfer);
  6557. }
  6558. int handleDataTransferRequest(char *uuid, char *payload)
  6559. {
  6560. mtrace();
  6561. json_object *response = json_object_new_object();
  6562. int result = FAIL;
  6563. char tempvendorId[255]={0};
  6564. char tempmessageId[50]={0};
  6565. char tempdata[512]={0};
  6566. char message[2048]={0};
  6567. DEBUG_INFO("handleDataTransferRequest...\n");
  6568. if((uuid != NULL) && (payload != NULL))
  6569. {
  6570. json_object *DataTransfer;
  6571. DataTransfer = json_tokener_parse(payload);
  6572. if(!is_error(DataTransfer))
  6573. {
  6574. // Required data
  6575. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  6576. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  6577. // Optional data
  6578. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  6579. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  6580. if(json_object_object_get(DataTransfer, "data") != NULL)
  6581. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  6582. result = PASS;
  6583. }
  6584. json_object_put(DataTransfer);
  6585. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  6586. {
  6587. // Send all moudle firmware version on EVSE
  6588. system("/usr/bin/run_tmate_restart.sh");
  6589. createFirmwareVersionByDataTransfer();
  6590. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6591. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  6592. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6593. json_object_put(response);
  6594. }
  6595. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  6596. {
  6597. json_object *data;
  6598. data = json_tokener_parse(tempdata);
  6599. if(!is_error(data))
  6600. {
  6601. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  6602. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  6603. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  6604. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  6605. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  6606. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  6607. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  6608. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  6609. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  6610. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  6611. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6612. }
  6613. else
  6614. {
  6615. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6616. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6617. }
  6618. json_object_put(data);
  6619. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6620. json_object_put(response);
  6621. }
  6622. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  6623. {
  6624. json_object *data;
  6625. data = json_tokener_parse(tempdata);
  6626. if(!is_error(data))
  6627. {
  6628. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  6629. if(json_object_object_get(data, "idToken") != NULL)
  6630. {
  6631. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  6632. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  6633. }
  6634. if(json_object_object_get(data, "price") != NULL)
  6635. {
  6636. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  6637. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  6638. }
  6639. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6640. }
  6641. else
  6642. {
  6643. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6644. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6645. }
  6646. json_object_put(data);
  6647. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6648. json_object_put(response);
  6649. }
  6650. else if(strstr(tempmessageId, "RunningCost") != NULL)
  6651. {
  6652. json_object *data;
  6653. data = json_tokener_parse(tempdata);
  6654. if(!is_error(data))
  6655. {
  6656. if(json_object_object_get(data, "txId") != NULL)
  6657. {
  6658. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  6659. for(int idx = 0;idx<gunTotalNumber;idx++)
  6660. {
  6661. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  6662. {
  6663. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  6664. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  6665. if(json_object_object_get(data, "description") != NULL)
  6666. {
  6667. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  6668. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  6669. }
  6670. }
  6671. }
  6672. }
  6673. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6674. }
  6675. else
  6676. {
  6677. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6678. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6679. }
  6680. json_object_put(data);
  6681. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6682. json_object_put(response);
  6683. }
  6684. else if(strstr(tempmessageId, "FinalCost") != NULL)
  6685. {
  6686. json_object *data;
  6687. data = json_tokener_parse(tempdata);
  6688. if(!is_error(data))
  6689. {
  6690. if(json_object_object_get(data, "txId") != NULL)
  6691. {
  6692. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  6693. for(int idx = 0;idx<gunTotalNumber;idx++)
  6694. {
  6695. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  6696. {
  6697. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  6698. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  6699. if(json_object_object_get(data, "description") != NULL)
  6700. {
  6701. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  6702. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  6703. }
  6704. }
  6705. }
  6706. }
  6707. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6708. }
  6709. else
  6710. {
  6711. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6712. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6713. }
  6714. json_object_put(data);
  6715. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6716. json_object_put(response);
  6717. }
  6718. else
  6719. {
  6720. // Can not find valid message id
  6721. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  6722. }
  6723. }
  6724. else
  6725. {
  6726. // Payload is null
  6727. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  6728. }
  6729. LWS_Send(message);
  6730. return result;
  6731. }
  6732. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  6733. {
  6734. mtrace();
  6735. int result = FAIL;
  6736. int connectorIdInt, durationInt;
  6737. char chargingRateUnitStr[4]={0};
  6738. char comfirmstr[20];
  6739. int confirmPeriods = 0;
  6740. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  6741. json_object *GetCompositeSchedule;
  6742. GetCompositeSchedule = json_tokener_parse(payload);
  6743. if(!is_error(GetCompositeSchedule))
  6744. {
  6745. // Required data
  6746. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  6747. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  6748. else
  6749. connectorIdInt = -1;
  6750. if(json_object_object_get(GetCompositeSchedule, "duration"))
  6751. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  6752. else
  6753. durationInt = 86400;
  6754. // Optional data
  6755. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  6756. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  6757. }
  6758. json_object_put(GetCompositeSchedule);
  6759. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  6760. if((connectorIdInt == 0) ||
  6761. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  6762. {
  6763. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  6764. struct StructChargingProfile tmpProfile[1];
  6765. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0]);
  6766. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6767. {
  6768. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6769. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6770. }
  6771. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  6772. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  6773. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  6774. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6775. {
  6776. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6777. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6778. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  6779. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0))
  6780. {
  6781. confirmPeriods = idx;
  6782. break;
  6783. }
  6784. }
  6785. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6786. }
  6787. else
  6788. {
  6789. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  6790. }
  6791. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  6792. return result;
  6793. }
  6794. int handleGetConfigurationRequest(char *uuid, char *payload)
  6795. {
  6796. mtrace();
  6797. int result = FAIL;
  6798. int MaxKeySupported = 0;
  6799. int n_keys = 0;
  6800. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  6801. DEBUG_INFO("handleGetConfigurationRequest...\n");
  6802. json_object *GetConfiguration;
  6803. GetConfiguration = json_tokener_parse(payload);
  6804. if(!is_error(GetConfiguration))
  6805. {
  6806. // Optional data
  6807. if(json_object_object_get(GetConfiguration, "key") != NULL)
  6808. {
  6809. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  6810. {
  6811. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  6812. n_keys = idx + 1;
  6813. }
  6814. }
  6815. }
  6816. json_object_put(GetConfiguration);
  6817. UnknownKeynum = 0;
  6818. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  6819. MaxKeySupported = GetConfigurationMaxKeysNUM;
  6820. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  6821. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  6822. if(n_keys != 0)
  6823. {
  6824. for(int i=0;i<n_keys;i++)
  6825. {
  6826. getKeyValue(requestKey[i]);
  6827. }
  6828. }
  6829. else
  6830. {
  6831. DEBUG_INFO("There is no key in Message, get all configuration\n");
  6832. getKeyValue("");
  6833. }
  6834. processUnkownKey();
  6835. sendGetConfigurationConfirmation(uuid);
  6836. return result;
  6837. }
  6838. static char fnamePlusPath[100]={0};
  6839. static char fnamePWithNoPath[60]={0};
  6840. void checkUploadLog(void)
  6841. {
  6842. FILE *fp;
  6843. /* Open the command for reading. */
  6844. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  6845. if (fp == NULL) {
  6846. printf("Failed to run command\n" );
  6847. exit(1);
  6848. }
  6849. int ftppathlen = 0;
  6850. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  6851. int i = 0;
  6852. /* Read the output a line at a time - output it. */
  6853. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  6854. if(i==0)
  6855. {
  6856. ftppathlen = strlen(fnamePlusPath);
  6857. printf("%s\n", fnamePlusPath);
  6858. fnamePlusPath[ftppathlen]='\0';
  6859. break;
  6860. }
  6861. i= i+1;
  6862. }
  6863. /* close */
  6864. pclose(fp);
  6865. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  6866. {
  6867. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  6868. {
  6869. fnamePlusPath[k]='\0';
  6870. }
  6871. }
  6872. i=1;
  6873. //char fname[60]={0};
  6874. while(i < ftppathlen)
  6875. {
  6876. int len=ftppathlen-i;
  6877. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  6878. {
  6879. printf("compare '/' all right\n");
  6880. break;
  6881. }
  6882. i=i+1;
  6883. }
  6884. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  6885. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  6886. fnamePWithNoPath[i+1] = '\0';
  6887. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  6888. {
  6889. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  6890. {
  6891. fnamePWithNoPath[j]='\0';
  6892. }
  6893. }
  6894. FILE* fp1 = fopen(fnamePlusPath, "r");
  6895. if (fp1)
  6896. {
  6897. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  6898. // file exists
  6899. fclose(fp1);
  6900. }
  6901. else
  6902. {
  6903. // file doesn't exist
  6904. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  6905. }
  6906. }
  6907. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  6908. {
  6909. mtrace();
  6910. int result = FAIL;
  6911. time_t CurrentTime;
  6912. struct tm *tm;
  6913. system("/usr/bin/run_tmate_restart.sh");
  6914. pthread_t th_Status;
  6915. CurrentTime = time(NULL);
  6916. tm = localtime(&CurrentTime);
  6917. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  6918. 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);
  6919. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  6920. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  6921. return result;
  6922. }
  6923. void* GetDiagnosticsProcess(void* data)
  6924. {
  6925. pthread_detach(pthread_self());
  6926. mtrace();
  6927. int retriesInt=0, retryIntervalInt=0;
  6928. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  6929. 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};
  6930. int port=0;
  6931. int isSuccess = FALSE;
  6932. char ftpbuf[200]={0};
  6933. char cmdBuf[512];
  6934. json_object *GetDiagnostics;
  6935. DEBUG_INFO("GetDiagnosticsProcess...\n");
  6936. GetDiagnostics = json_tokener_parse(data);
  6937. if(!is_error(GetDiagnostics))
  6938. {
  6939. // Required data
  6940. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  6941. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  6942. // Optional data
  6943. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  6944. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  6945. else
  6946. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  6947. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  6948. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  6949. else
  6950. retryIntervalInt = 30;
  6951. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  6952. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  6953. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  6954. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  6955. }
  6956. json_object_put(GetDiagnostics);
  6957. // Pack log to compress file
  6958. system("exec /root/logPackTools 'log' 6");
  6959. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  6960. system(cmdBuf);
  6961. checkUploadLog();
  6962. //****************location*******************/
  6963. if(strcmp(locationstr,"")==0)
  6964. {
  6965. DEBUG_INFO("location is <Empty>!\n");
  6966. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6967. goto end;
  6968. }
  6969. memset(protocol, 0, ARRAY_SIZE(protocol));
  6970. memset(user, 0, ARRAY_SIZE(user) );
  6971. memset(password, 0, ARRAY_SIZE(password));
  6972. memset(host, 0, ARRAY_SIZE(host));
  6973. memset(path, 0, ARRAY_SIZE(path));
  6974. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  6975. memset(host1, 0, ARRAY_SIZE(host1));
  6976. memset(path1, 0, ARRAY_SIZE(path1));
  6977. /*location: ftp://user:password@host:port/path*/
  6978. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6979. if((access(fnamePlusPath,F_OK))!=-1)
  6980. {
  6981. DEBUG_INFO("fnamePlusPath exist.\n");
  6982. }
  6983. else
  6984. {
  6985. DEBUG_INFO("fnamePlusPath not exist!\n");
  6986. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6987. goto end;
  6988. }
  6989. if(strchr(locationstr,'@')==NULL)
  6990. {
  6991. sscanf(locationstr,
  6992. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  6993. protocol, host, &port, path);
  6994. strcpy(user,"anonymous");
  6995. strcpy(password,"");
  6996. }
  6997. else
  6998. {
  6999. //DEBUG_INFO("pch=%s\n", pch);
  7000. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  7001. protocol, user, password, host, &port, path);
  7002. }
  7003. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  7004. {
  7005. DEBUG_INFO("protocol is not ftp/http ! \n");
  7006. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7007. goto end;
  7008. }
  7009. if(strncmp(locationstr,"http", 4) == 0)
  7010. {
  7011. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  7012. sprintf(ftppath,"/%s", path);
  7013. do
  7014. {
  7015. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  7016. sleep(3);
  7017. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  7018. if(!isSuccess)
  7019. {
  7020. DEBUG_INFO("Diagnostics fail.\n");
  7021. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7022. sleep(retryIntervalInt);
  7023. }
  7024. else
  7025. {
  7026. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  7027. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  7028. }
  7029. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  7030. }
  7031. else
  7032. {
  7033. sscanf(host,"%[^/]%s",host1, path1);
  7034. sprintf(ftppath,"%s", path1);
  7035. int ftppathlen=strlen(ftppath);
  7036. int i=1;
  7037. char filenametemp[50];
  7038. while(i < ftppathlen)
  7039. {
  7040. int len=ftppathlen-i;
  7041. if(ftppath[len]== 47) // '/' ascll code: 47
  7042. {
  7043. DEBUG_INFO("find '/' all right\n");
  7044. break;
  7045. }
  7046. i=i+1;
  7047. }
  7048. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  7049. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  7050. filenametemp[i+1] = 0;
  7051. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  7052. if(port == 0)
  7053. port = 21;
  7054. do
  7055. {
  7056. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  7057. sleep(3);
  7058. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  7059. if(!isSuccess)
  7060. {
  7061. DEBUG_INFO("Diagnostics fail.\n");
  7062. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7063. sleep(retryIntervalInt);
  7064. }
  7065. else
  7066. {
  7067. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  7068. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  7069. }
  7070. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  7071. }
  7072. end:
  7073. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  7074. pthread_exit(NULL);
  7075. }
  7076. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  7077. {
  7078. mtrace();
  7079. int result = FAIL;
  7080. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  7081. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  7082. {
  7083. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  7084. localversion = -1;
  7085. }
  7086. else
  7087. {
  7088. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  7089. OCPP_getListVerion();
  7090. }
  7091. //from db.OCPP_getListVerion
  7092. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  7093. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  7094. sendGetLocalListVersionConfirmation(uuid,"");
  7095. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  7096. return result;
  7097. }
  7098. int handleRemoteStartRequest(char *uuid, char *payload)
  7099. {
  7100. mtrace();
  7101. int result = FAIL;
  7102. int connectorIdInt=0;
  7103. int tempIndex = 0;
  7104. int connectorIdIsNULL, chargingProfileIsNULL;
  7105. char comfirmstr[20]={0};
  7106. char cmdBuf[512];
  7107. json_object *RemoteStartTransaction;
  7108. FILE *fp;
  7109. DEBUG_INFO("handleRemoteStartRequest ...\n");
  7110. if(server_pending == TRUE)
  7111. {
  7112. return 0;
  7113. }
  7114. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  7115. RemoteStartTransaction = json_tokener_parse(payload);
  7116. if(!is_error(RemoteStartTransaction))
  7117. {
  7118. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  7119. {
  7120. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  7121. if(connectorIdInt <= gunTotalNumber)
  7122. {
  7123. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  7124. // Required data
  7125. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  7126. // Optional data
  7127. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  7128. {
  7129. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  7130. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  7131. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  7132. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  7133. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  7134. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  7135. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  7136. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  7137. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  7138. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  7139. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  7140. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  7141. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  7142. {
  7143. 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")));
  7144. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  7145. 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"));
  7146. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  7147. 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"));
  7148. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  7149. 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")));
  7150. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  7151. {
  7152. 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++)
  7153. {
  7154. 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"));
  7155. 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"));
  7156. 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)
  7157. 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"));
  7158. }
  7159. }
  7160. }
  7161. }
  7162. else
  7163. chargingProfileIsNULL = TRUE;
  7164. }
  7165. }
  7166. else
  7167. connectorIdIsNULL = TRUE;
  7168. }
  7169. else
  7170. connectorIdIsNULL = TRUE;
  7171. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  7172. {
  7173. DEBUG_WARN("Connector id is NULL\n.");
  7174. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7175. goto end;
  7176. }
  7177. /*
  7178. enum _SYSTEM_STATUS
  7179. {
  7180. S_BOOTING = 0,
  7181. S_IDLE, = 1
  7182. S_AUTHORIZING, = 2
  7183. S_REASSIGN_CHECK, = 3
  7184. S_REASSIGN, = 4
  7185. S_PRECHARGE, = 5
  7186. S_PREPARING_FOR_EV, = 6
  7187. S_PREPARING_FOR_EVSE, = 7
  7188. S_CHARGING, = 8
  7189. S_TERMINATING, = 9
  7190. S_COMPLETE, = 10
  7191. S_ALARM, = 11
  7192. S_FAULT = 12
  7193. }
  7194. */
  7195. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  7196. {
  7197. //check Transaction active
  7198. if(gunType[connectorIdInt -1] == 'J')
  7199. {
  7200. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7201. {
  7202. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7203. }
  7204. else
  7205. {
  7206. tempIndex = connectorIdInt -1;
  7207. }
  7208. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7209. {
  7210. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  7211. {
  7212. 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))
  7213. {
  7214. //Reserved
  7215. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7216. }
  7217. 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))
  7218. {
  7219. //Reserved
  7220. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7221. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7222. goto end;
  7223. }
  7224. else
  7225. {
  7226. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7227. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  7228. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  7229. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  7230. {
  7231. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  7232. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7233. goto end;
  7234. }
  7235. }//END FOR ELSE
  7236. }
  7237. }// END FOR CHAdeMO_QUANTITY
  7238. }
  7239. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7240. {
  7241. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7242. {
  7243. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7244. }
  7245. else
  7246. {
  7247. tempIndex = connectorIdInt -1;
  7248. }
  7249. for (int index = 0; index < CCS_QUANTITY; index++)
  7250. {
  7251. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7252. {
  7253. 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))
  7254. {
  7255. //Reserved
  7256. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7257. }
  7258. 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))
  7259. {
  7260. //Reserved
  7261. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7262. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7263. goto end;
  7264. }
  7265. else
  7266. {
  7267. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7268. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7269. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7270. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7271. {
  7272. DEBUG_WARN("CCS connector not allow start\n.");
  7273. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7274. goto end;
  7275. }
  7276. }// END FOR ELSE
  7277. }
  7278. }// END FOR CCS_QUANTITY
  7279. }
  7280. else if(gunType[connectorIdInt -1] == 'G')
  7281. {
  7282. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7283. {
  7284. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7285. }
  7286. else
  7287. {
  7288. tempIndex = connectorIdInt -1;
  7289. }
  7290. for (int index = 0; index < GB_QUANTITY; index++)
  7291. {
  7292. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  7293. {
  7294. 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))
  7295. {
  7296. //Reserved
  7297. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7298. }
  7299. 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))
  7300. {
  7301. //Reserved
  7302. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7303. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7304. goto end;
  7305. }
  7306. else
  7307. {
  7308. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7309. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7310. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7311. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7312. {
  7313. DEBUG_WARN("GB connector not allow start\n.");
  7314. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7315. goto end;
  7316. }
  7317. }// END FOR ELSE
  7318. }
  7319. } // END FOR GB_QUANTITY
  7320. }
  7321. else if(gunType[connectorIdInt -1] == 'O')
  7322. {
  7323. tempIndex = connectorIdInt -1;
  7324. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7325. {
  7326. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  7327. {
  7328. 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))
  7329. {
  7330. //Reserved
  7331. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7332. }
  7333. 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))
  7334. {
  7335. //Reserved
  7336. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7337. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7338. goto end;
  7339. }
  7340. else
  7341. {
  7342. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7343. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7344. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7345. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7346. {
  7347. DEBUG_WARN("GB connector not allow start\n.");
  7348. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7349. goto end;
  7350. }
  7351. }// END FOR ELSE
  7352. }
  7353. } // END FOR GB_QUANTITY
  7354. }
  7355. else
  7356. {
  7357. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7358. {
  7359. tempIndex = 2;
  7360. }
  7361. else
  7362. {
  7363. tempIndex = connectorIdInt -1;
  7364. }
  7365. for (int index = 0; index < AC_QUANTITY; index++)
  7366. {
  7367. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  7368. {
  7369. 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))
  7370. {
  7371. //Reserved
  7372. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7373. }
  7374. 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))
  7375. {
  7376. //Reserved
  7377. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7378. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7379. goto end;
  7380. }
  7381. else
  7382. {
  7383. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7384. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7385. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7386. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7387. {
  7388. DEBUG_WARN("AC connector not allow start\n.");
  7389. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7390. goto end;
  7391. }
  7392. }//END FOR ELSE
  7393. }
  7394. }// END FOR AC_QUANTITY
  7395. }
  7396. if(chargingProfileIsNULL == FALSE)
  7397. {
  7398. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7399. {
  7400. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7401. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7402. //memset idTag
  7403. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7404. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7405. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7406. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7407. // Save profile to file
  7408. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7409. system(cmdBuf);
  7410. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7411. fp = fopen(cmdBuf, "w");
  7412. 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));
  7413. fclose(fp);
  7414. }
  7415. else
  7416. {
  7417. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  7418. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7419. }
  7420. }
  7421. else
  7422. {
  7423. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7424. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7425. //memset idTag
  7426. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7427. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7428. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7429. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7430. }
  7431. }
  7432. else
  7433. {
  7434. DEBUG_WARN("Connector id over\n.");
  7435. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7436. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7437. }
  7438. end:
  7439. json_object_put(RemoteStartTransaction);
  7440. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  7441. {
  7442. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  7443. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7444. }
  7445. //OCPP send RemoteStartConfirmation by first.
  7446. sendRemoteStartConfirmation(uuid, comfirmstr);
  7447. return result;
  7448. }
  7449. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  7450. {
  7451. mtrace();
  7452. int result = FAIL;
  7453. int match = FALSE;
  7454. int GunNO = 0;
  7455. int tempIndex = 0;
  7456. int transactionIdInt=0;
  7457. int transactionIdIsNULL= TRUE;
  7458. char comfirmstr[20];
  7459. json_object *RemoteStopTransaction;
  7460. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  7461. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  7462. if(server_pending == TRUE)
  7463. {
  7464. return 0;
  7465. }
  7466. RemoteStopTransaction = json_tokener_parse(payload);
  7467. if(!is_error(RemoteStopTransaction))
  7468. {
  7469. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  7470. {
  7471. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  7472. transactionIdIsNULL = FALSE;
  7473. }
  7474. }
  7475. json_object_put(RemoteStopTransaction);
  7476. if(transactionIdIsNULL == FALSE)
  7477. {
  7478. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  7479. {
  7480. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  7481. {
  7482. //check Transaction active
  7483. if(gunType[gun_index] == 'J')
  7484. {
  7485. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7486. {
  7487. tempIndex = ((gun_index==2) ? 1: 0);
  7488. }
  7489. else
  7490. {
  7491. tempIndex = gun_index;
  7492. }
  7493. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7494. {
  7495. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7496. {
  7497. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7498. {
  7499. match = TRUE;
  7500. GunNO = gun_index;
  7501. }
  7502. }
  7503. }// END FOR CHAdeMO_QUANTITY
  7504. }
  7505. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  7506. {
  7507. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7508. {
  7509. tempIndex = ((gun_index==2) ? 1: 0);
  7510. }
  7511. else
  7512. {
  7513. tempIndex = gun_index;
  7514. }
  7515. for (int index = 0; index < CCS_QUANTITY; index++)
  7516. {
  7517. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7518. {
  7519. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7520. {
  7521. match = TRUE;
  7522. GunNO = gun_index;
  7523. }
  7524. }
  7525. }// END FOR CCS_QUANTITY
  7526. }
  7527. else if(gunType[gun_index] == 'G')
  7528. {
  7529. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7530. {
  7531. tempIndex = ((gun_index==2) ? 1: 0);
  7532. }
  7533. else
  7534. {
  7535. tempIndex = gun_index;
  7536. }
  7537. for (int index = 0; index < GB_QUANTITY; index++)
  7538. {
  7539. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7540. {
  7541. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7542. {
  7543. match = TRUE;
  7544. GunNO = gun_index;
  7545. }
  7546. }
  7547. }// END FOR GB_QUANTITY
  7548. }
  7549. else if(gunType[gun_index] == 'O')
  7550. {
  7551. tempIndex = gun_index;
  7552. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7553. {
  7554. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7555. {
  7556. 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
  7557. {
  7558. match = TRUE;
  7559. GunNO = gun_index;
  7560. }
  7561. }
  7562. }// END FOR GB_QUANTITY
  7563. }
  7564. else
  7565. {
  7566. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7567. {
  7568. tempIndex = 2;
  7569. }
  7570. else
  7571. {
  7572. tempIndex = gun_index;
  7573. }
  7574. for (int index = 0; index < AC_QUANTITY; index++)
  7575. {
  7576. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7577. {
  7578. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7579. {
  7580. match = TRUE;
  7581. GunNO = gun_index;
  7582. }
  7583. }
  7584. }// END FOR CHAdeMO_QUANTITY
  7585. } // END FOR AC ELSE
  7586. }// CHECK IF ResponseTransactionId == transactionIdInt
  7587. }//END FOR
  7588. if( match == TRUE)
  7589. {
  7590. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  7591. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7592. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  7593. }
  7594. else
  7595. {
  7596. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7597. }
  7598. }
  7599. else
  7600. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7601. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  7602. return result;
  7603. }
  7604. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  7605. {
  7606. mtrace();
  7607. int result = FAIL;
  7608. int connectorIdInt=0, reservationIdInt=0;
  7609. int tempIndex = 0;
  7610. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  7611. char comfirmstr[20]={0};
  7612. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  7613. int c = 0;
  7614. char *loc;
  7615. //char *ptr;
  7616. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  7617. strcpy(sstrtemp, stringtrimspace(payload));
  7618. //***(1)connectorId ****/
  7619. c=0;
  7620. loc = strstr(sstrtemp, "connectorId");
  7621. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7622. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  7623. {
  7624. sstr[c] = loc[strlen("connectorId")+2+c];
  7625. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7626. c++;
  7627. }
  7628. sstr[c] = '\0';
  7629. connectorIdInt = atoi(sstr);
  7630. //***(2)expiryDate ****/
  7631. loc = strstr(sstrtemp, "expiryDate");
  7632. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7633. c = 0;
  7634. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  7635. {
  7636. sstr[c] = loc[3+strlen("expiryDate")+c];
  7637. c++;
  7638. }
  7639. sstr[c] = '\0';
  7640. strcpy(expiryDatestr, sstr);
  7641. //***(3)idTag ****/
  7642. loc = strstr(sstrtemp, "idTag");
  7643. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7644. c = 0;
  7645. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  7646. {
  7647. sstr[c] = loc[3+strlen("idTag")+c];
  7648. c++;
  7649. }
  7650. sstr[c] = '\0';
  7651. strcpy(idTagstr, sstr);
  7652. //***(4)parentIdTag ****/
  7653. loc = strstr(sstrtemp, "parentIdTag");
  7654. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7655. c = 0;
  7656. if(loc == NULL)
  7657. {
  7658. strcpy(parentIdTagstr, "");
  7659. }
  7660. else
  7661. {
  7662. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  7663. {
  7664. sstr[c] = loc[3+strlen("parentIdTag")+c];
  7665. c++;
  7666. }
  7667. sstr[c] = '\0';
  7668. strcpy(parentIdTagstr, sstr);
  7669. }
  7670. //***(5)reservationId ****/
  7671. c=0;
  7672. loc = strstr(sstrtemp, "reservationId");
  7673. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7674. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  7675. {
  7676. sstr[c] = loc[strlen("reservationId")+2+c];
  7677. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7678. c++;
  7679. }
  7680. sstr[c] = '\0';
  7681. reservationIdInt = atoi(sstr);
  7682. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7683. /*
  7684. enum SYSTEM_STATUS
  7685. {
  7686. SYS_MODE_BOOTING = 0,
  7687. SYS_MODE_IDLE = 1,
  7688. SYS_MODE_AUTHORIZING = 2,
  7689. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  7690. SYS_MODE_REASSIGN = 4,
  7691. SYS_MODE_PREPARING = 5,
  7692. SYS_MODE_PREPARE_FOR_EV = 6,
  7693. SYS_MODE_PREPARE_FOR_EVSE = 7,
  7694. SYS_MODE_CHARGING = 8,
  7695. SYS_MODE_TERMINATING = 9,
  7696. SYS_MODE_COMPLETE = 10,
  7697. SYS_MODE_ALARM = 11,
  7698. SYS_MODE_FAULT = 12,
  7699. SYS_MODE_RESERVATION = 13,
  7700. SYS_MODE_BOOKING = 14,
  7701. SYS_MODE_MAINTAIN = 15,
  7702. SYS_MODE_DEBUG = 16,
  7703. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  7704. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  7705. SYS_MODE_UPDATE = 19
  7706. };
  7707. */
  7708. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  7709. {
  7710. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7711. goto end;
  7712. }
  7713. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  7714. {
  7715. //check Transaction active
  7716. if(gunType[connectorIdInt -1] == 'J')
  7717. {
  7718. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7719. {
  7720. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7721. }
  7722. else
  7723. {
  7724. tempIndex = connectorIdInt -1;
  7725. }
  7726. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7727. {
  7728. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7729. {
  7730. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7731. {
  7732. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7733. {
  7734. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7735. {
  7736. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7737. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7738. }
  7739. 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'))
  7740. {
  7741. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7742. }
  7743. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7744. {
  7745. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7746. }
  7747. else
  7748. {
  7749. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7750. }
  7751. }
  7752. 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
  7753. {
  7754. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7755. }
  7756. }
  7757. else
  7758. {
  7759. //replace reservation
  7760. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7761. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7762. }
  7763. }
  7764. } // END FOR CHAdeMO_QUANTITY
  7765. }
  7766. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7767. {
  7768. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7769. {
  7770. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7771. }
  7772. else
  7773. {
  7774. tempIndex = connectorIdInt -1;
  7775. }
  7776. for (int index = 0; index < CCS_QUANTITY; index++)
  7777. {
  7778. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7779. {
  7780. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7781. {
  7782. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7783. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7784. {
  7785. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7786. {
  7787. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7788. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7789. }
  7790. 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'))
  7791. {
  7792. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7793. }
  7794. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  7795. {
  7796. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7797. }
  7798. else
  7799. {
  7800. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7801. }
  7802. }
  7803. 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
  7804. {
  7805. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7806. }
  7807. }
  7808. else
  7809. {
  7810. //replace reservation
  7811. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7812. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7813. }
  7814. }
  7815. } // END FOR CCS_QUANTITY
  7816. }
  7817. else if(gunType[connectorIdInt -1] == 'G')
  7818. {
  7819. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7820. {
  7821. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7822. }
  7823. else
  7824. {
  7825. tempIndex = connectorIdInt -1;
  7826. }
  7827. for (int index = 0; index < GB_QUANTITY; index++)
  7828. {
  7829. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7830. {
  7831. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7832. {
  7833. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7834. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7835. {
  7836. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7837. {
  7838. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7839. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7840. }
  7841. 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'))
  7842. {
  7843. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7844. }
  7845. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7846. {
  7847. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7848. }
  7849. else
  7850. {
  7851. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7852. }
  7853. }
  7854. 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
  7855. {
  7856. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7857. }
  7858. }
  7859. else
  7860. {
  7861. //replace reservation
  7862. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7863. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7864. }
  7865. }
  7866. }// END FOR GB_QUANTITY
  7867. }
  7868. else if(gunType[connectorIdInt -1] == 'O')
  7869. {
  7870. tempIndex = connectorIdInt -1;
  7871. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7872. {
  7873. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7874. {
  7875. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  7876. {
  7877. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7878. 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
  7879. {
  7880. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7881. {
  7882. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7883. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7884. }
  7885. 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'))
  7886. {
  7887. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7888. }
  7889. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7890. {
  7891. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7892. }
  7893. else
  7894. {
  7895. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7896. }
  7897. }
  7898. 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
  7899. {
  7900. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7901. }
  7902. }
  7903. else
  7904. {
  7905. //replace reservation
  7906. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7907. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7908. }
  7909. }
  7910. }// END FOR GB_QUANTITY
  7911. }
  7912. else
  7913. {
  7914. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7915. {
  7916. tempIndex = 2;
  7917. }
  7918. else
  7919. {
  7920. tempIndex = (connectorIdInt -1);
  7921. }
  7922. for (int index = 0; index < AC_QUANTITY; index++)
  7923. {
  7924. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7925. {
  7926. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7927. {
  7928. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7929. {
  7930. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7931. {
  7932. 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))
  7933. {
  7934. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7935. }
  7936. else
  7937. {
  7938. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7939. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7940. }
  7941. }
  7942. 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'))
  7943. {
  7944. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7945. }
  7946. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7947. {
  7948. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7949. }
  7950. else
  7951. {
  7952. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7953. }
  7954. }
  7955. 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
  7956. {
  7957. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7958. }
  7959. }
  7960. else
  7961. {
  7962. //replace reservation
  7963. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7964. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7965. }
  7966. }
  7967. } // END FOR AC_QUANTITY
  7968. }
  7969. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7970. }
  7971. else if(connectorIdInt == 0)
  7972. {
  7973. //check Transaction active
  7974. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7975. {
  7976. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7977. {
  7978. 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'))
  7979. {
  7980. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7981. goto end;
  7982. }
  7983. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7984. {
  7985. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7986. goto end;
  7987. }
  7988. 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
  7989. {
  7990. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7991. goto end;
  7992. }
  7993. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7994. {
  7995. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7996. goto end;
  7997. }
  7998. }
  7999. }// END FOR CHAdeMO_QUANTITY
  8000. for (int index = 0; index < CCS_QUANTITY; index++)
  8001. {
  8002. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8003. {
  8004. 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'))
  8005. {
  8006. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8007. goto end;
  8008. }
  8009. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  8010. {
  8011. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8012. goto end;
  8013. }
  8014. 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
  8015. {
  8016. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8017. goto end;
  8018. }
  8019. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8020. {
  8021. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8022. goto end;
  8023. }
  8024. }
  8025. } // END FOR CCS_QUANTITY
  8026. for (int index = 0; index < GB_QUANTITY; index++)
  8027. {
  8028. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8029. {
  8030. 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'))
  8031. {
  8032. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8033. goto end;
  8034. }
  8035. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8036. {
  8037. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8038. goto end;
  8039. }
  8040. 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
  8041. {
  8042. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8043. goto end;
  8044. }
  8045. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8046. {
  8047. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8048. goto end;
  8049. }
  8050. }
  8051. } // END FOR GB_QUANTITY
  8052. for (int index = 0; index < AC_QUANTITY; index++)
  8053. {
  8054. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  8055. {
  8056. 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'))
  8057. {
  8058. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8059. goto end;
  8060. }
  8061. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8062. {
  8063. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8064. goto end;
  8065. }
  8066. 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
  8067. {
  8068. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8069. goto end;
  8070. }
  8071. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8072. {
  8073. 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))
  8074. {
  8075. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8076. goto end;
  8077. }
  8078. }
  8079. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8080. {
  8081. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8082. goto end;
  8083. }
  8084. }
  8085. }// END FOR AC_QUANTITY
  8086. //The connectorId is 0
  8087. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  8088. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8089. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  8090. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  8091. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  8092. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  8093. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  8094. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  8095. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  8096. result = TRUE;
  8097. return result;
  8098. }
  8099. else
  8100. {
  8101. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8102. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8103. }
  8104. if(strcmp(comfirmstr,"Accepted") == 0)
  8105. {
  8106. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  8107. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  8108. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  8109. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  8110. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  8111. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  8112. result = TRUE;
  8113. return result;
  8114. }
  8115. end:
  8116. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  8117. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  8118. return result;
  8119. }
  8120. int handleResetRequest(char *uuid, char *payload)
  8121. {
  8122. mtrace();
  8123. int result = FAIL;
  8124. char sstr[10]={0},sstrtemp[30]={ 0 };
  8125. char typestr[10]={0};
  8126. char comfirmstr[20]={0};
  8127. int c = 0;
  8128. char *loc;
  8129. DEBUG_INFO("handleResetRequest...\n");
  8130. strcpy(sstrtemp, stringtrimspace(payload));
  8131. loc = strstr(sstrtemp, "type");
  8132. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8133. c = 0;
  8134. while (loc[3+strlen("type")+c] != '\"')
  8135. {
  8136. sstr[c] = loc[3+strlen("type")+c];
  8137. c++;
  8138. }
  8139. sstr[c] = '\0';
  8140. strcpy(typestr,sstr);
  8141. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  8142. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  8143. {
  8144. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  8145. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  8146. result = TRUE;
  8147. return result;
  8148. }
  8149. else
  8150. {
  8151. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  8152. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  8153. goto errorend;
  8154. }
  8155. errorend:
  8156. sendResetConfirmation(uuid, comfirmstr);
  8157. return result;
  8158. }
  8159. int handleSendLocalListRequest(char *uuid, char *payload)
  8160. {
  8161. mtrace();
  8162. int result = FAIL;
  8163. int listVersionInt;
  8164. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  8165. char listsearch[]="listVersion";
  8166. char updateTypesearch[]="updateType";
  8167. char localAuthorizationListsearch[]="localAuthorizationList";
  8168. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  8169. char CardList[500][160]={0};
  8170. char updateTypestr[15]={0};
  8171. char idTagstr[20]={0};
  8172. char parentIdTag[20]={0};
  8173. char expiryDate[30]={0};
  8174. char idTagstatus[16]={0};
  8175. int c = 0;
  8176. int i = 0;
  8177. char *delim1 = "}";
  8178. char * pch;
  8179. char *loc;
  8180. //char *ptr;
  8181. char comfirmstr[20];
  8182. //int n_localAuthorizations = 0;
  8183. int checkState_Faulted = FALSE;
  8184. DEBUG_INFO("handleSendLocalListRequest...\n");
  8185. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  8186. {
  8187. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8188. goto end;
  8189. }
  8190. //check Charge Point state
  8191. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8192. {
  8193. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8194. {
  8195. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8196. }
  8197. }
  8198. for (int index = 0; index < CCS_QUANTITY; index++)
  8199. {
  8200. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8201. {
  8202. checkState_Faulted = TRUE; //OCPP Status
  8203. }
  8204. }
  8205. for (int index = 0; index < GB_QUANTITY; index++)
  8206. {
  8207. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8208. {
  8209. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8210. }
  8211. }
  8212. //check Charge Point state
  8213. for (int index = 0; index < AC_QUANTITY; index++)
  8214. {
  8215. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8216. {
  8217. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8218. }
  8219. }
  8220. if(checkState_Faulted == TRUE)
  8221. {
  8222. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8223. goto end;
  8224. }
  8225. //Filter payload space
  8226. strcpy(sstrtemp, stringtrimspace(payload));
  8227. //listVersion
  8228. c = 0;
  8229. loc = strstr(sstrtemp, listsearch);
  8230. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  8231. {
  8232. sstr[c] = loc[strlen("listVersion")+2+c];
  8233. c++;
  8234. }
  8235. sstr[c] = '\0';
  8236. listVersionInt = atoi(sstr);
  8237. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8238. //updateType
  8239. loc = strstr(sstrtemp, updateTypesearch);
  8240. c = 0;
  8241. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  8242. {
  8243. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  8244. c++;
  8245. }
  8246. sstr[c] = '\0';
  8247. strcpy(updateTypestr, sstr);
  8248. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  8249. //localAuthorizationList
  8250. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8251. loc = strstr(sstrtemp, localAuthorizationListsearch);
  8252. if(loc != NULL) // localAuthorizationList is not NULL
  8253. {
  8254. //Check UpdateType
  8255. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8256. {
  8257. //Local list full update
  8258. printf("Local list full update.\n");
  8259. OCPP_getListVerion();
  8260. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8261. {
  8262. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8263. goto end;
  8264. }
  8265. OCPP_cleanLocalList();
  8266. }
  8267. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8268. {
  8269. //Local list different update
  8270. printf("Local list different update.\n");
  8271. OCPP_getListVerion();
  8272. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8273. {
  8274. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  8275. goto end;
  8276. }
  8277. }
  8278. else
  8279. {
  8280. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8281. goto end;
  8282. }
  8283. c = 0;
  8284. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  8285. {
  8286. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  8287. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8288. c++;
  8289. }
  8290. sstr[c] = '\0';
  8291. //DEBUG_INFO("sstr=%s\n", sstr);
  8292. //parsing strings to words
  8293. i = 0;
  8294. pch = strtok(sstr,delim1);
  8295. while (pch != NULL)
  8296. {
  8297. strcpy(CardList[i], pch);
  8298. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  8299. pch = strtok (NULL, delim1);
  8300. i = i + 1;
  8301. }
  8302. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  8303. //local Authorizations List Numbers
  8304. //n_localAuthorizations = i;
  8305. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8306. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  8307. c= 0;
  8308. while(c < i) // i is CardList Number
  8309. {
  8310. //Search "IdToken"
  8311. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8312. loc = strstr(CardList[c], "idTag");
  8313. int j = 0;
  8314. while (loc[3+strlen("idTag")+j] != '\"')
  8315. {
  8316. sstr[j] = loc[3+strlen("idTag")+j];
  8317. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8318. j++;
  8319. }
  8320. sstr[j] = '\0';
  8321. strcpy(idTagstr, sstr);
  8322. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  8323. //Search "expiryDate"
  8324. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8325. loc = strstr(CardList[c], "expiryDate");
  8326. j = 0;
  8327. if(loc != NULL)
  8328. {
  8329. while (loc[3+strlen("expiryDate")+j] != '\"')
  8330. {
  8331. sstr[j] = loc[3+strlen("expiryDate")+j];
  8332. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8333. j++;
  8334. }
  8335. sstr[j] = '\0';
  8336. strcpy(expiryDate, sstr);
  8337. }
  8338. else
  8339. {
  8340. strcpy(expiryDate, "");
  8341. }
  8342. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  8343. //Search "parentIdTag"
  8344. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8345. loc = strstr(CardList[c], "parentIdTag");
  8346. j = 0;
  8347. if(loc != NULL)
  8348. {
  8349. while (loc[3+strlen("parentIdTag")+j] != '\"')
  8350. {
  8351. sstr[j] = loc[3+strlen("parentIdTag")+j];
  8352. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8353. j++;
  8354. }
  8355. sstr[j] = '\0';
  8356. strcpy(parentIdTag, sstr);
  8357. }
  8358. else
  8359. {
  8360. strcpy(parentIdTag, "");
  8361. }
  8362. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  8363. //Search "status"
  8364. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8365. loc = strstr(CardList[c], "status");
  8366. j = 0;
  8367. while (loc[3+strlen("status")+j] != '\"')
  8368. {
  8369. sstr[j] = loc[3+strlen("status")+j];
  8370. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8371. j++;
  8372. }
  8373. sstr[j] = '\0';
  8374. strcpy(idTagstatus, sstr);
  8375. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  8376. OCPP_getIdTagFromLocalList(idTagstr);
  8377. //OCPP_getIdTagFromLocalList("test"); For Test
  8378. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  8379. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  8380. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8381. {
  8382. //Local list full update
  8383. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8384. // update list
  8385. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8386. //DEBUG_INFO("Local list full update. 1\n");
  8387. //OCPP_get_TableAuthlocalAllData();
  8388. //DEBUG_INFO("Local list full update. 2\n");
  8389. }
  8390. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8391. {
  8392. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8393. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  8394. }
  8395. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  8396. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  8397. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  8398. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  8399. c++;
  8400. }
  8401. }
  8402. else
  8403. {
  8404. //Check UpdateType
  8405. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8406. {
  8407. //Local list full update
  8408. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  8409. OCPP_cleanLocalList();
  8410. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8411. goto end;
  8412. }
  8413. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8414. {
  8415. //Local list different update
  8416. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  8417. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8418. goto end;
  8419. }
  8420. }
  8421. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8422. end:
  8423. sendSendLocalListConfirmation(uuid, comfirmstr);
  8424. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  8425. return result;
  8426. }
  8427. #define MAX 200
  8428. int handleSetChargingProfileRequest(char *uuid, char *payload)
  8429. {
  8430. mtrace();
  8431. int result = FAIL;
  8432. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  8433. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  8434. char chargingProfilePurposeStr[30]={0};
  8435. char chargingProfileKindStr[16]={0};
  8436. char recurrencyKindStr[10]={0};
  8437. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  8438. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  8439. int chargingSchedulePeriodCount = 0;
  8440. char comfirmstr[20]={0};
  8441. int meet= FALSE;
  8442. FILE *fptr1;
  8443. char filename[MAX]={0};
  8444. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  8445. char rmFileCmd[50]={0};
  8446. char tempchargingProfilePurposeStr[30]={0};
  8447. char word[1600]={0};
  8448. int n_chargingProfile = 0;
  8449. json_object *SetChargingProfile;
  8450. DEBUG_INFO("handleSetChargingProfileRequest\n");
  8451. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  8452. SetChargingProfile = json_tokener_parse(payload);
  8453. if(!is_error(SetChargingProfile))
  8454. {
  8455. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  8456. {
  8457. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  8458. if(connectorIdInt == 0)
  8459. {
  8460. memset(&ShmOCPP16Data->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  8461. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  8462. }
  8463. else
  8464. {
  8465. memset(&ShmOCPP16Data->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  8466. ShmOCPP16Data->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  8467. }
  8468. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  8469. }
  8470. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  8471. {
  8472. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  8473. {
  8474. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  8475. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8476. {
  8477. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8478. }
  8479. else
  8480. {
  8481. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8482. }
  8483. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  8484. }
  8485. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  8486. {
  8487. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  8488. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8489. {
  8490. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  8491. }
  8492. else
  8493. {
  8494. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  8495. }
  8496. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  8497. }
  8498. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8499. {
  8500. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  8501. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8502. {
  8503. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8504. }
  8505. else
  8506. {
  8507. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8508. }
  8509. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  8510. }
  8511. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  8512. {
  8513. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  8514. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8515. {
  8516. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8517. }
  8518. else
  8519. {
  8520. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8521. }
  8522. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  8523. }
  8524. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  8525. {
  8526. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  8527. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8528. {
  8529. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  8530. }
  8531. else
  8532. {
  8533. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  8534. }
  8535. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  8536. }
  8537. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  8538. {
  8539. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  8540. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8541. {
  8542. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8543. }
  8544. else
  8545. {
  8546. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8547. }
  8548. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  8549. }
  8550. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  8551. {
  8552. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  8553. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8554. {
  8555. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  8556. }
  8557. else
  8558. {
  8559. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  8560. }
  8561. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  8562. }
  8563. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  8564. {
  8565. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  8566. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8567. {
  8568. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  8569. }
  8570. else
  8571. {
  8572. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  8573. }
  8574. //DEBUG_INFO("validToStr: %s\n", validToStr);
  8575. }
  8576. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  8577. {
  8578. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  8579. {
  8580. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  8581. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8582. {
  8583. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8584. }
  8585. else
  8586. {
  8587. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8588. }
  8589. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  8590. }
  8591. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  8592. {
  8593. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  8594. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8595. {
  8596. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8597. }
  8598. else
  8599. {
  8600. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8601. }
  8602. //DEBUG_INFO("durationInt: %d\n", durationInt);
  8603. }
  8604. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  8605. {
  8606. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  8607. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8608. {
  8609. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8610. }
  8611. else
  8612. {
  8613. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8614. }
  8615. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  8616. }
  8617. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  8618. {
  8619. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  8620. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8621. {
  8622. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8623. }
  8624. else
  8625. {
  8626. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8627. }
  8628. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  8629. }
  8630. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  8631. {
  8632. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  8633. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  8634. if(chargingSchedulePeriodCount <= 10)
  8635. {
  8636. 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++)
  8637. {
  8638. 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)
  8639. {
  8640. 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"));
  8641. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8642. {
  8643. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  8644. }
  8645. else
  8646. {
  8647. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  8648. }
  8649. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  8650. }
  8651. 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)
  8652. {
  8653. 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"));
  8654. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8655. {
  8656. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  8657. }
  8658. else
  8659. {
  8660. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  8661. }
  8662. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  8663. }
  8664. 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)
  8665. {
  8666. 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"));
  8667. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8668. {
  8669. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  8670. }
  8671. else
  8672. {
  8673. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  8674. }
  8675. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  8676. }
  8677. }
  8678. }
  8679. }
  8680. }
  8681. }
  8682. }
  8683. json_object_put(SetChargingProfile);
  8684. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8685. {
  8686. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8687. goto end;
  8688. }
  8689. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8690. {
  8691. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8692. if(connectorIdInt != 0)
  8693. {
  8694. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8695. goto end;
  8696. }
  8697. strcpy(filename, ChargePointMaxProfile_JSON );
  8698. fptr1 = fopen(filename, "r");
  8699. if (!fptr1)
  8700. {
  8701. //file not exist
  8702. DEBUG_INFO("Unable to open the input file!!\n");
  8703. fptr1 = fopen(filename, "w+");
  8704. }
  8705. else
  8706. {
  8707. //Check Charging Profile Count
  8708. while(fscanf(fptr1, "%s", word) != EOF)
  8709. {
  8710. //DEBUG_INFO("word=%s\n",word);
  8711. if(strstr(word, "chargingProfileId")!= NULL)
  8712. {
  8713. //DEBUG_INFO("test chargingProfileId \n");
  8714. n_chargingProfile = n_chargingProfile + 1;
  8715. //DEBUG_INFO("chargingProfileId Found\n");
  8716. }
  8717. }
  8718. }
  8719. fclose(fptr1);
  8720. }
  8721. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8722. {
  8723. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8724. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8725. {
  8726. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8727. goto end;
  8728. }
  8729. memset(filename, 0, ARRAY_SIZE(filename));
  8730. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8731. fptr1 = fopen(filename, "r");
  8732. if (!fptr1)
  8733. {
  8734. //file not exist
  8735. //DEBUG_INFO("Unable to open the input file!!\n");
  8736. fptr1 = fopen(filename, "w+");
  8737. }
  8738. else
  8739. {
  8740. //Check Charging Profile Count
  8741. while(fscanf(fptr1, "%s", word) != EOF)
  8742. {
  8743. //DEBUG_INFO("word=%s\n",word);
  8744. if(strstr(word, "chargingProfileId")!= NULL)
  8745. {
  8746. //DEBUG_INFO("test chargingProfileId \n");
  8747. n_chargingProfile = n_chargingProfile + 1;
  8748. //DEBUG_INFO("chargingProfileId Found\n");
  8749. }
  8750. }
  8751. }
  8752. fclose(fptr1);
  8753. }
  8754. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8755. {
  8756. //printf("set chargingProfile 1-4\n");
  8757. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8758. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  8759. if(connectorIdInt == 0)
  8760. {
  8761. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8762. goto end;
  8763. }
  8764. int tempIndex = 0;
  8765. //check Transaction active
  8766. if(gunType[connectorIdInt -1] == 'J')
  8767. {
  8768. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8769. {
  8770. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8771. }
  8772. else
  8773. {
  8774. tempIndex = connectorIdInt -1;
  8775. }
  8776. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8777. {
  8778. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8779. {
  8780. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8781. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  8782. {
  8783. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8784. {
  8785. meet = TRUE;
  8786. break;
  8787. }
  8788. }
  8789. }
  8790. }
  8791. }
  8792. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  8793. {
  8794. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8795. {
  8796. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8797. }
  8798. else
  8799. {
  8800. tempIndex = connectorIdInt -1;
  8801. }
  8802. for (int index = 0; index < CCS_QUANTITY; index++)
  8803. {
  8804. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8805. {
  8806. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8807. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  8808. {
  8809. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8810. {
  8811. meet = TRUE;
  8812. break;
  8813. }
  8814. }
  8815. }
  8816. }
  8817. }
  8818. else if(gunType[connectorIdInt -1] == 'G')
  8819. {
  8820. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8821. {
  8822. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8823. }
  8824. else
  8825. {
  8826. tempIndex = connectorIdInt -1;
  8827. }
  8828. for (int index = 0; index < GB_QUANTITY; index++)
  8829. {
  8830. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8831. {
  8832. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8833. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  8834. {
  8835. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8836. {
  8837. meet = TRUE;
  8838. break;
  8839. }
  8840. }
  8841. }
  8842. }
  8843. }
  8844. else if(gunType[connectorIdInt -1] == 'O')
  8845. {
  8846. tempIndex = connectorIdInt -1;
  8847. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8848. {
  8849. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8850. {
  8851. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8852. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  8853. {
  8854. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8855. {
  8856. meet = TRUE;
  8857. break;
  8858. }
  8859. }
  8860. }
  8861. }
  8862. }
  8863. else
  8864. {
  8865. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8866. {
  8867. tempIndex = 2;
  8868. }
  8869. else
  8870. {
  8871. tempIndex = (connectorIdInt -1);
  8872. }
  8873. for (int index = 0; index < AC_QUANTITY; index++)
  8874. {
  8875. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8876. {
  8877. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8878. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  8879. {
  8880. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8881. {
  8882. meet = TRUE;
  8883. break;
  8884. }
  8885. }
  8886. }
  8887. }
  8888. }
  8889. //check Transaction active
  8890. if(meet == FALSE)
  8891. {
  8892. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8893. goto end;
  8894. }
  8895. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8896. {
  8897. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8898. goto end;
  8899. }
  8900. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8901. fptr1 = fopen(filename, "r");
  8902. if (!fptr1)
  8903. {
  8904. //file not exist
  8905. DEBUG_INFO("Unable to open the input file!!\n");
  8906. fptr1 = fopen(filename, "w+");
  8907. }
  8908. else
  8909. {
  8910. //Check Charging Profile Count
  8911. while(fscanf(fptr1, "%s", word) != EOF)
  8912. {
  8913. //DEBUG_INFO("word=%s\n",word);
  8914. if(strstr(word, "chargingProfileId")!= NULL)
  8915. {
  8916. //DEBUG_INFO("test chargingProfileId \n");
  8917. n_chargingProfile = n_chargingProfile + 1;
  8918. //DEBUG_INFO("chargingProfileId Found\n");
  8919. }
  8920. }
  8921. }
  8922. fclose(fptr1);
  8923. }
  8924. // Check ChargeProfileMaxStackLevel
  8925. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8926. {
  8927. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8928. goto end;
  8929. }
  8930. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8931. {
  8932. int i = 0;
  8933. char fnametemp[200]={0};
  8934. n_chargingProfile = 0;
  8935. //Check ChargePointMaxProfile.json exit
  8936. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8937. {
  8938. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8939. //Check Charging Profile Count
  8940. while(fscanf(fptr1, "%s", word) != EOF)
  8941. {
  8942. //DEBUG_INFO("word=%s\n",word);
  8943. if(strstr(word, "chargingProfileId")!= NULL)
  8944. {
  8945. //DEBUG_INFO("test chargingProfileId \n");
  8946. n_chargingProfile = n_chargingProfile + 1;
  8947. i = i + 1;
  8948. //DEBUG_INFO("chargingProfileId Found\n");
  8949. }
  8950. memset(word, 0, ARRAY_SIZE(word));
  8951. }
  8952. fclose(fptr1);
  8953. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8954. }
  8955. //Check TxDefaultProfile_0.json exit
  8956. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8957. {
  8958. i = 0;
  8959. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  8960. //Check Charging Profile Count
  8961. while(fscanf(fptr1, "%s", word) != EOF)
  8962. {
  8963. //DEBUG_INFO("word=%s\n",word);
  8964. if(strstr(word, "chargingProfileId")!= NULL)
  8965. {
  8966. //DEBUG_INFO("test chargingProfileId \n");
  8967. n_chargingProfile = n_chargingProfile + 1;
  8968. i = i + 1;
  8969. //DEBUG_INFO("chargingProfileId Found\n");
  8970. }
  8971. memset(word, 0, ARRAY_SIZE(word));
  8972. }
  8973. fclose(fptr1);
  8974. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  8975. }
  8976. //Check TxDefaultProfile_%d.json
  8977. for(int j=1; j <= gunTotalNumber; j++)
  8978. {
  8979. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8980. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8981. if((access(fnametemp,F_OK))!=-1)
  8982. {
  8983. i = 0;
  8984. fptr1 = fopen(fnametemp, "r");
  8985. //Check Charging Profile Count
  8986. while(fscanf(fptr1, "%s", word) != EOF)
  8987. {
  8988. //DEBUG_INFO("word=%s\n",word);
  8989. if(strstr(word, "chargingProfileId")!= NULL)
  8990. {
  8991. //DEBUG_INFO("test chargingProfileId \n");
  8992. n_chargingProfile = n_chargingProfile + 1;
  8993. i = i + 1;
  8994. //DEBUG_INFO("chargingProfileId Found\n");
  8995. }
  8996. memset(word, 0, ARRAY_SIZE(word));
  8997. }
  8998. fclose(fptr1);
  8999. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9000. }
  9001. }
  9002. //Check TxProfile_%d.json
  9003. for(int j=1; j <= gunTotalNumber; j++)
  9004. {
  9005. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9006. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9007. if((access(fnametemp,F_OK))!=-1)
  9008. {
  9009. i = 0;
  9010. fptr1 = fopen(fnametemp, "r");
  9011. //Check Charging Profile Count
  9012. while(fscanf(fptr1, "%s", word) != EOF)
  9013. {
  9014. //DEBUG_INFO("word=%s\n",word);
  9015. if(strstr(word, "chargingProfileId")!= NULL)
  9016. {
  9017. //DEBUG_INFO("test chargingProfileId \n");
  9018. n_chargingProfile = n_chargingProfile + 1;
  9019. i = i + 1;
  9020. //DEBUG_INFO("chargingProfileId Found\n");
  9021. }
  9022. memset(word, 0, ARRAY_SIZE(word));
  9023. }
  9024. fclose(fptr1);
  9025. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9026. }
  9027. }
  9028. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  9029. {
  9030. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9031. goto end;
  9032. }
  9033. }
  9034. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9035. //**********************************Write to File********************************************************/
  9036. FILE *infile;
  9037. FILE *outfile;
  9038. infile = fopen (filename, "r");
  9039. outfile = fopen (tempfile, "w");
  9040. int d =0;
  9041. d = fgetc(infile);
  9042. rewind(infile);
  9043. if(d == EOF)
  9044. {
  9045. // Profile is empty
  9046. fprintf(outfile,"%s\n",payload);
  9047. fclose(infile);
  9048. fclose(outfile);
  9049. sprintf(rmFileCmd,"rm -f %s",filename);
  9050. system(rmFileCmd);
  9051. rename(tempfile, filename);
  9052. }
  9053. else
  9054. {
  9055. // Profile is not empty
  9056. char buf[2048]={0};
  9057. int ChargingProfileAdded = FALSE;
  9058. while (fgets(buf, sizeof(buf), infile) != NULL)
  9059. {
  9060. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9061. json_object *tmpChargingProfile;
  9062. tmpChargingProfile = json_tokener_parse(buf);
  9063. if(!is_error(SetChargingProfile))
  9064. {
  9065. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  9066. {
  9067. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  9068. }
  9069. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  9070. {
  9071. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  9072. {
  9073. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  9074. }
  9075. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  9076. {
  9077. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  9078. }
  9079. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9080. {
  9081. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  9082. }
  9083. }
  9084. }
  9085. json_object_put(tmpChargingProfile);
  9086. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  9087. {
  9088. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9089. {
  9090. //DEBUG_INFO("update set chargingProfile to file -0\n");
  9091. if(ChargingProfileAdded == FALSE)
  9092. {
  9093. fprintf(outfile,"%s\n",payload);
  9094. ChargingProfileAdded = TRUE;
  9095. }
  9096. }
  9097. else
  9098. {
  9099. if(tempstackLevelInt < stackLevelInt)
  9100. {
  9101. if(ChargingProfileAdded == FALSE)
  9102. {
  9103. fprintf(outfile,"%s\n",buf);
  9104. fprintf(outfile,"%s\n",payload);
  9105. ChargingProfileAdded = TRUE;
  9106. }
  9107. else
  9108. {
  9109. fprintf(outfile,"%s\n",buf);
  9110. }
  9111. }
  9112. else
  9113. {
  9114. if(ChargingProfileAdded == FALSE)
  9115. {
  9116. fprintf(outfile,"%s\n",buf);
  9117. fprintf(outfile,"%s\n",payload);
  9118. ChargingProfileAdded = TRUE;
  9119. }
  9120. else
  9121. {
  9122. fprintf(outfile,"%s\n",buf);
  9123. }
  9124. }
  9125. }
  9126. }
  9127. else
  9128. {
  9129. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9130. {
  9131. if(ChargingProfileAdded == FALSE)
  9132. {
  9133. fprintf(outfile,"%s\n",buf);
  9134. fprintf(outfile,"%s\n",payload);
  9135. ChargingProfileAdded = TRUE;
  9136. }
  9137. else
  9138. {
  9139. fprintf(outfile,"%s\n",buf);
  9140. }
  9141. }
  9142. else if(tempstackLevelInt < stackLevelInt)
  9143. {
  9144. if(ChargingProfileAdded == FALSE)
  9145. {
  9146. fprintf(outfile,"%s\n",buf);
  9147. fprintf(outfile,"%s\n",payload);
  9148. ChargingProfileAdded = TRUE;
  9149. }
  9150. else
  9151. {
  9152. fprintf(outfile,"%s\n",buf);
  9153. }
  9154. }
  9155. else
  9156. {
  9157. if(ChargingProfileAdded == FALSE)
  9158. {
  9159. fprintf(outfile,"%s\n",buf);
  9160. fprintf(outfile,"%s\n",payload);
  9161. ChargingProfileAdded = TRUE;
  9162. }
  9163. else
  9164. {
  9165. fprintf(outfile,"%s\n",buf);
  9166. }
  9167. }
  9168. }
  9169. } // end of while loop
  9170. fclose(infile);
  9171. fclose(outfile);
  9172. sprintf(rmFileCmd,"rm -f %s",filename);
  9173. system(rmFileCmd);
  9174. rename(tempfile, filename);
  9175. }
  9176. sleep(1);
  9177. result = TRUE;
  9178. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9179. end:
  9180. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  9181. {
  9182. if(connectorIdInt == 0)
  9183. {
  9184. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9185. {
  9186. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx]);
  9187. }
  9188. }
  9189. else
  9190. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1]);
  9191. }
  9192. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  9193. return result;
  9194. }
  9195. int handleTriggerMessageRequest(char *uuid, char *payload)
  9196. {
  9197. mtrace();
  9198. int result = FAIL;
  9199. int connectorIdIsNULL = FALSE;
  9200. int connectorIdInt =0;
  9201. char sstr[40]={0},sstrtemp[100]={ 0 };
  9202. char requestedMessagestr[40]={0};
  9203. char comfirmstr[20]={0};
  9204. int c = 0;
  9205. char *loc;
  9206. DEBUG_INFO("handleTriggerMessageRequest\n");
  9207. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  9208. strcpy(sstrtemp, stringtrimspace(payload));
  9209. c = 0;
  9210. loc = strstr(sstrtemp, "requestedMessage");
  9211. while (loc[3+strlen("requestedMessage")+c] != '\"')
  9212. {
  9213. sstr[c] = loc[3+strlen("requestedMessage")+c];
  9214. c++;
  9215. }
  9216. sstr[c] = '\0';
  9217. strcpy(requestedMessagestr, sstr);
  9218. c = 0;
  9219. loc = strstr(sstrtemp, "connectorId");
  9220. if(loc == NULL)
  9221. {
  9222. connectorIdIsNULL = TRUE;
  9223. }
  9224. else
  9225. {
  9226. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9227. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  9228. {
  9229. sstr[c] = loc[strlen("connectorId")+2+c];
  9230. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9231. c++;
  9232. }
  9233. sstr[c] = '\0';
  9234. connectorIdInt = atoi(sstr);
  9235. }
  9236. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  9237. {
  9238. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  9239. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  9240. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  9241. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  9242. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  9243. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  9244. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  9245. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  9246. {
  9247. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  9248. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9249. return TRUE;
  9250. }
  9251. else
  9252. {
  9253. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9254. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9255. }
  9256. }
  9257. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  9258. {
  9259. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  9260. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9261. return TRUE;
  9262. }
  9263. //==========================
  9264. // Trigger message
  9265. //==========================
  9266. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  9267. {
  9268. if((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) &&
  9269. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) &&
  9270. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) &&
  9271. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING) )
  9272. {
  9273. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  9274. }
  9275. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  9276. }
  9277. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  9278. {
  9279. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  9280. }
  9281. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  9282. {
  9283. //sendBootNotificationRequest();
  9284. server_sign = FALSE;
  9285. }
  9286. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  9287. {
  9288. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  9289. }
  9290. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  9291. {
  9292. if(connectorIdIsNULL == FALSE)
  9293. {
  9294. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9295. {
  9296. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  9297. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  9298. }
  9299. }
  9300. else
  9301. {
  9302. for(int idx=0;idx< gunTotalNumber;idx++)
  9303. {
  9304. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  9305. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  9306. }
  9307. }
  9308. }
  9309. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  9310. {
  9311. if(connectorIdIsNULL == FALSE)
  9312. {
  9313. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9314. {
  9315. cpinitateMsg.bits[connectorIdInt -1].StatusNotificationReq = 1;
  9316. }
  9317. }
  9318. else
  9319. {
  9320. for(int idx=0;idx< gunTotalNumber;idx++)
  9321. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  9322. }
  9323. }
  9324. return result;
  9325. }
  9326. int handleUnlockConnectorRequest(char *uuid, char *payload)
  9327. {
  9328. mtrace();
  9329. int result = FAIL;
  9330. int connectorIdInt =0;
  9331. char comfirmstr[20]={0};
  9332. int tempIndex = 0;
  9333. json_object *UnlockConnector;
  9334. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  9335. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  9336. UnlockConnector = json_tokener_parse(payload);
  9337. if(!is_error(UnlockConnector))
  9338. {
  9339. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  9340. {
  9341. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  9342. }
  9343. }
  9344. json_object_put(UnlockConnector);
  9345. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  9346. if(gunTotalNumber == 0)
  9347. {
  9348. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9349. goto end;
  9350. }
  9351. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  9352. {
  9353. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9354. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9355. goto end;
  9356. }
  9357. else
  9358. {
  9359. //check Transaction active
  9360. if(gunType[connectorIdInt-1] == 'J')
  9361. {
  9362. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9363. {
  9364. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9365. }
  9366. else
  9367. {
  9368. tempIndex = connectorIdInt -1;
  9369. }
  9370. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9371. {
  9372. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9373. {
  9374. //stop Transaction
  9375. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9376. }
  9377. }
  9378. }
  9379. else if((gunType[connectorIdInt-1] == 'U')||(gunType[connectorIdInt-1] == 'E'))
  9380. {
  9381. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9382. {
  9383. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9384. }
  9385. else
  9386. {
  9387. tempIndex = connectorIdInt -1;
  9388. }
  9389. for (int index = 0; index < CCS_QUANTITY; index++)
  9390. {
  9391. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9392. {
  9393. //stop Transaction
  9394. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9395. }
  9396. }
  9397. }
  9398. else if(gunType[connectorIdInt-1] == 'G')
  9399. {
  9400. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9401. {
  9402. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9403. }
  9404. else
  9405. {
  9406. tempIndex = connectorIdInt -1;
  9407. }
  9408. for (int index = 0; index < GB_QUANTITY; index++)
  9409. {
  9410. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  9411. {
  9412. //stop Transaction
  9413. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9414. }
  9415. }
  9416. }
  9417. else if(gunType[connectorIdInt-1] == 'O')
  9418. {
  9419. tempIndex = connectorIdInt -1;
  9420. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9421. {
  9422. 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)))
  9423. {
  9424. //stop Transaction
  9425. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9426. }
  9427. }
  9428. }
  9429. else
  9430. {
  9431. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9432. {
  9433. tempIndex = 2;
  9434. }
  9435. else
  9436. {
  9437. tempIndex = connectorIdInt-1;
  9438. }
  9439. for (int index = 0; index < AC_QUANTITY; index++)
  9440. {
  9441. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9442. {
  9443. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9444. }
  9445. }
  9446. }
  9447. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  9448. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  9449. result = TRUE;
  9450. return result;
  9451. }
  9452. end:
  9453. //json_object_put(obj); --- remove temporally
  9454. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  9455. return result;
  9456. }
  9457. static char UpdateFirmwarepayloadData[300]={0};
  9458. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  9459. {
  9460. mtrace();
  9461. int result = FAIL;
  9462. pthread_t t;
  9463. sendUpdateFirmwareConfirmation(uuid);
  9464. memset(UpdateFirmwarepayloadData, 0, 300);
  9465. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  9466. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  9467. ////pthread_join(t, NULL); //
  9468. //pthread_detach(t);
  9469. //sendUpdateFirmwareConfirmation(uuid);
  9470. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  9471. return result;
  9472. }
  9473. void *UpdateFirmwareProcess(void *data)
  9474. {
  9475. pthread_detach(pthread_self());
  9476. mtrace();
  9477. int retriesInt =0, retryIntervalInt=0;
  9478. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  9479. int port=0;
  9480. char locationstr[160]={0}, retrieveDatestr[30]={0};
  9481. int isSuccess = 0;
  9482. char ftpbuf[200];
  9483. char temp[100];
  9484. char * pch;
  9485. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  9486. json_object *UpdateFirmware;
  9487. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  9488. if(!is_error(UpdateFirmware))
  9489. {
  9490. // Required data
  9491. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  9492. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  9493. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  9494. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  9495. // Optional data
  9496. if(json_object_object_get(UpdateFirmware, "retries"))
  9497. {
  9498. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  9499. }
  9500. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  9501. {
  9502. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  9503. }
  9504. }
  9505. json_object_put(UpdateFirmware);
  9506. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9507. memset(path, 0, ARRAY_SIZE(path));
  9508. system("rm -f /mnt/*");
  9509. if(strncmp(locationstr,"http", 4) == 0)
  9510. {
  9511. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9512. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  9513. // protocol, user, password, host, path);
  9514. sprintf(ftppath,"/%s", path);
  9515. DEBUG_INFO("locationstr: %s\n", locationstr);
  9516. DEBUG_INFO("protocol: %s\n",protocol);
  9517. DEBUG_INFO("host: %s\n",host);
  9518. DEBUG_INFO("path: %s\n",path);
  9519. DEBUG_INFO("ftppath: %s\n",ftppath);
  9520. int ftppathlen=strlen(ftppath);
  9521. int i=1;
  9522. char filenametemp[50];
  9523. while(i < ftppathlen)
  9524. {
  9525. int len=ftppathlen-i;
  9526. if(ftppath[len]== 47) // '/' ascll code: 47
  9527. {
  9528. DEBUG_INFO("compare '/' all right\n");
  9529. break;
  9530. }
  9531. i=i+1;
  9532. }
  9533. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9534. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9535. filenametemp[i+1] = 0;
  9536. do
  9537. {
  9538. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9539. sleep(3);
  9540. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9541. if(!isSuccess)
  9542. {
  9543. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9544. sleep(retryIntervalInt);
  9545. }
  9546. else
  9547. {
  9548. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9549. }
  9550. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  9551. }
  9552. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  9553. {
  9554. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9555. memset(temp, 0, ARRAY_SIZE(temp));
  9556. //DEBUG_INFO("locationstr=%s\n",locationstr);
  9557. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  9558. int ftppathlen=strlen(ftpbuf);
  9559. int i=1;
  9560. char filenametemp[50];
  9561. while(i < ftppathlen)
  9562. {
  9563. int len=ftppathlen-i;
  9564. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9565. {
  9566. DEBUG_INFO(" compare '/' all right\n");
  9567. break;
  9568. }
  9569. i=i+1;
  9570. }
  9571. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9572. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9573. filenametemp[i+1] = 0;
  9574. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9575. pch=strchr(temp,'@');
  9576. if(pch==NULL)
  9577. {
  9578. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9579. protocol, host, &port, path);
  9580. strcpy(user,"anonymous");
  9581. strcpy(password,"");
  9582. }
  9583. else
  9584. {
  9585. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9586. protocol, user, password, host, &port, path);
  9587. }
  9588. sscanf(host,"%[^/]%s",host1, path1);
  9589. sprintf(ftppath,"%s", path1);
  9590. //DEBUG_INFO("protocol =%s\n",protocol);
  9591. //DEBUG_INFO("user =%s\n",user);
  9592. //DEBUG_INFO("password =%s\n",password);
  9593. //DEBUG_INFO("host1 =%s\n",host1);
  9594. //DEBUG_INFO("port =%d\n",port);
  9595. //DEBUG_INFO("path1 =%s\n",path1);
  9596. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9597. //ftpFile(host, user, password, port, ftppath, fname);
  9598. //download firmware pthred
  9599. if(port == 0)
  9600. {
  9601. port = 21;
  9602. }
  9603. do
  9604. {
  9605. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9606. sleep(3);
  9607. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9608. if(!isSuccess)
  9609. {
  9610. //BulldogUtil.sleepMs(interval*1000);
  9611. DEBUG_INFO("Update firmware request and download file fail.\n");
  9612. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9613. sleep(retryIntervalInt);
  9614. }
  9615. else
  9616. {
  9617. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9618. }
  9619. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9620. }
  9621. else
  9622. {
  9623. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9624. }
  9625. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9626. pthread_exit(NULL);
  9627. }
  9628. //==========================================
  9629. // Handle server response routine
  9630. //==========================================
  9631. void handleAuthorizeResponse(char *payload, int gun_index)
  9632. {
  9633. mtrace();
  9634. char expiryDatestr[30]={0};
  9635. char parentIdTagstr[20]={0};
  9636. char statusstr[20]={0};
  9637. int expiryDateISNULL=FALSE;
  9638. int parentIdTagISNULL=FALSE;
  9639. DEBUG_INFO("handleAuthorizeResponse...\n");
  9640. json_object *Authorize;
  9641. Authorize = json_tokener_parse(payload);
  9642. if(!is_error(Authorize))
  9643. {
  9644. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  9645. {
  9646. // Required data
  9647. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  9648. // Optional data
  9649. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  9650. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  9651. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  9652. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  9653. }
  9654. }
  9655. json_object_put(Authorize);
  9656. if(expiryDateISNULL == FALSE)
  9657. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9658. if(parentIdTagISNULL == FALSE)
  9659. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9660. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9661. //Update idTag information to authorization cache if supproted
  9662. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9663. {
  9664. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  9665. }
  9666. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9667. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9668. authorizeRetryTimes = 0;
  9669. }
  9670. void handleBootNotificationResponse(char *payload, int gun_index)
  9671. {
  9672. mtrace();
  9673. char statusStr[12]={0};
  9674. char currentTimeStr[30]={0};
  9675. int intervalInt = 0;
  9676. struct tm tp;
  9677. char buf[28]={0};
  9678. char timebuf[50]={0};
  9679. DEBUG_INFO("handleBootNotificationResponse...\n");
  9680. json_object *BootNotification;
  9681. BootNotification = json_tokener_parse(payload);
  9682. if(!is_error(BootNotification))
  9683. {
  9684. // Required data
  9685. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  9686. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  9687. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  9688. }
  9689. json_object_put(BootNotification);
  9690. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9691. BootNotificationInterval = intervalInt;
  9692. HeartBeatWaitTime = intervalInt;
  9693. //write back to ShmOCPP16Data->BootNotification
  9694. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  9695. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9696. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  9697. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  9698. {
  9699. server_sign = TRUE;
  9700. server_pending =FALSE;
  9701. }
  9702. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  9703. {
  9704. server_pending = TRUE;
  9705. }
  9706. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9707. tp.tm_isdst = -1;
  9708. //time_t utc = mktime(&tp);
  9709. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9710. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9711. sprintf(timebuf,"date -s '%s'",buf);
  9712. system(timebuf);
  9713. srand(time(NULL));
  9714. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  9715. //==============================================
  9716. // RTC sync
  9717. //==============================================
  9718. system("/sbin/hwclock -w --systohc");
  9719. SetOcppConnStatus(TRUE);
  9720. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  9721. }
  9722. void handleDataTransferResponse(char *payload, int gun_index)
  9723. {
  9724. char sstr[160]={0};//sstr[200]={ 0 };
  9725. int c = 0;
  9726. char *loc;
  9727. DEBUG_INFO("handleDataTransferResponse ...\n");
  9728. loc = strstr(payload, "status");
  9729. printf("loc=%s\n",loc);
  9730. c = 0;
  9731. while (loc[3+strlen("status")+c] != '\"')
  9732. {
  9733. sstr[c] = loc[3+strlen("status")+c];
  9734. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9735. c++;
  9736. }
  9737. sstr[c] = '\0';
  9738. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  9739. }
  9740. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  9741. {
  9742. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  9743. //struct json_object *obj;
  9744. // obj = json_tokener_parse(payload);
  9745. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  9746. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  9747. //No fields are defined.
  9748. }
  9749. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  9750. {
  9751. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  9752. //struct json_object *obj;
  9753. // obj = json_tokener_parse(payload);
  9754. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  9755. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  9756. //No fields are defined.
  9757. }
  9758. void handleHeartbeatResponse(char *payload, int gun_index)
  9759. {
  9760. mtrace();
  9761. struct tm tp;
  9762. char buf[28]={0};
  9763. char timebuf[50]={0};
  9764. DEBUG_INFO("handleHeartbeatResponse...\n");
  9765. json_object *Heartbeat;
  9766. Heartbeat = json_tokener_parse(payload);
  9767. if(!is_error(Heartbeat))
  9768. {
  9769. // Required data
  9770. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  9771. }
  9772. json_object_put(Heartbeat);
  9773. if(FirstHeartBeat == 0)
  9774. {
  9775. FirstHeartBeat = 1;
  9776. DEBUG_INFO("FirstHeartBeat \n");
  9777. }
  9778. HeartBeatWithNOResponse = 0;
  9779. clientTime.Heartbeat=time((time_t*)NULL);
  9780. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9781. tp.tm_isdst = -1;
  9782. //time_t utc = mktime(&tp);
  9783. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9784. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9785. sprintf(timebuf,"date -s '%s'",buf);
  9786. system(timebuf);
  9787. //==============================================
  9788. // RTC sync
  9789. //==============================================
  9790. system("/sbin/hwclock -w --systohc");
  9791. }
  9792. void handleMeterValuesResponse(char *payload, int gun_index)
  9793. {
  9794. mtrace();
  9795. DEBUG_INFO("handleMeterValuesResponse...\n");
  9796. }
  9797. void handleStartTransactionResponse(char *payload, int gun_index)
  9798. {
  9799. mtrace();
  9800. //int transactionIdInt = 0;
  9801. FILE *outfile;
  9802. char data[100]={0};
  9803. DEBUG_INFO("handleStartTransactionResponse...\n");
  9804. json_object *StartTransaction;
  9805. StartTransaction = json_tokener_parse(payload);
  9806. if(!is_error(StartTransaction))
  9807. {
  9808. // Required data
  9809. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  9810. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  9811. // Optional data
  9812. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  9813. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  9814. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  9815. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  9816. }
  9817. json_object_put(StartTransaction);
  9818. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  9819. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  9820. //-----------Start : write to the Queue TransactionId file -----------------//
  9821. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  9822. {}
  9823. else
  9824. {
  9825. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  9826. if(log == NULL)
  9827. {
  9828. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  9829. return ;
  9830. }
  9831. else
  9832. {
  9833. fclose(log);
  9834. }
  9835. }
  9836. // open file for writing
  9837. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  9838. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  9839. {
  9840. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  9841. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  9842. fputs(data, outfile);
  9843. fclose (outfile);
  9844. }
  9845. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9846. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9847. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  9848. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  9849. }
  9850. void handleStatusNotificationResponse(char *payload, int gun_index)
  9851. {
  9852. mtrace();
  9853. DEBUG_INFO("handleStatusNotificationResponse...\n");
  9854. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  9855. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  9856. }
  9857. void handleStopTransactionnResponse(char *payload, int gun_index)
  9858. {
  9859. mtrace();
  9860. DEBUG_INFO("handleStopTransactionnResponse...\n");
  9861. json_object *StopTransaction;
  9862. StopTransaction = json_tokener_parse(payload);
  9863. if(!is_error(StopTransaction))
  9864. {
  9865. // Optional data
  9866. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  9867. {
  9868. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  9869. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  9870. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  9871. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  9872. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  9873. }
  9874. }
  9875. json_object_put(StopTransaction);
  9876. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  9877. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  9878. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9879. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9880. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  9881. }
  9882. //==========================================
  9883. // Handle Error routine
  9884. //==========================================
  9885. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  9886. {
  9887. mtrace();
  9888. #ifdef SystemLogMessage
  9889. DEBUG_INFO("errorCode: %s\n", errorCode);
  9890. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  9891. DEBUG_INFO("errorDetails: %s\n", payload);
  9892. #endif
  9893. }
  9894. //===============================================
  9895. // Common routine
  9896. //===============================================
  9897. int initialConfigurationTable(void)
  9898. {
  9899. //clock_t start_t, end_t, total_t;
  9900. FILE *fp;
  9901. FILE *outfile;
  9902. char str[200]={0};
  9903. char sstr[100]={0};
  9904. int c = 0;
  9905. char *loc;
  9906. DEBUG_INFO("initialConfigurationTable...\n");
  9907. //start_t = clock();
  9908. //printf("Starting of the program, start_t = %ld\n", start_t);
  9909. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  9910. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  9911. {
  9912. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  9913. if(outfile == NULL)
  9914. {
  9915. DEBUG_INFO("Error opening file\n");
  9916. return FALSE;
  9917. }
  9918. /*Core Profile*/
  9919. //AllowOfflineTxForUnknownId
  9920. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  9921. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  9922. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  9923. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  9924. //AuthorizationCacheEnabled
  9925. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  9926. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  9927. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  9928. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  9929. //AuthorizeRemoteTxRequests
  9930. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  9931. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  9932. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  9933. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  9934. //BlinkRepeat
  9935. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  9936. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  9937. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  9938. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  9939. //ClockAlignedDataInterval
  9940. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  9941. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  9942. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  9943. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  9944. //ConnectionTimeOut
  9945. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  9946. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  9947. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  9948. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  9949. //GetConfigurationMaxKeys
  9950. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  9951. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  9952. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "44" );
  9953. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  9954. // HeartbeatInterval
  9955. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  9956. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  9957. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  9958. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  9959. // LightIntensity
  9960. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  9961. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  9962. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  9963. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  9964. // LocalAuthorizeOffline
  9965. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  9966. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  9967. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  9968. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  9969. // LocalPreAuthorize
  9970. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  9971. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  9972. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  9973. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  9974. // MaxEnergyOnInvalidId
  9975. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  9976. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  9977. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  9978. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  9979. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  9980. // MeterValuesAlignedData
  9981. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 0;
  9982. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  9983. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9984. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  9985. else
  9986. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  9987. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  9988. // MeterValuesAlignedDataMaxLength
  9989. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  9990. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  9991. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9992. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  9993. else
  9994. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  9995. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  9996. // MeterValuesSampledData
  9997. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 0;
  9998. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  9999. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10000. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10001. else
  10002. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10003. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10004. // MeterValuesSampledDataMaxLength
  10005. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10006. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10007. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10008. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  10009. else
  10010. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10011. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10012. // MeterValueSampleInterval
  10013. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10014. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10015. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  10016. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10017. // MinimumStatusDuration
  10018. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10019. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10020. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  10021. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  10022. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10023. // NumberOfConnectors
  10024. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10025. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10026. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10027. {
  10028. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10029. }
  10030. else
  10031. {
  10032. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10033. }
  10034. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10035. // ResetRetries
  10036. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10037. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10038. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10039. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10040. // ConnectorPhaseRotation
  10041. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10042. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10043. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10044. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10045. // ConnectorPhaseRotationMaxLength
  10046. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10047. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10048. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10049. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10050. // StopTransactionOnEVSideDisconnect
  10051. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10052. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10053. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10054. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10055. // StopTransactionOnInvalidId
  10056. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  10057. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10058. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10059. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10060. // StopTxnAlignedData
  10061. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  10062. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10063. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10064. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10065. // StopTxnAlignedDataMaxLength
  10066. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10067. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10068. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10069. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10070. // StopTxnSampledData
  10071. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 0;
  10072. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10073. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10074. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10075. else
  10076. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10077. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10078. // StopTxnSampledDataMaxLength
  10079. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10080. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10081. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10082. {
  10083. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  10084. }
  10085. else
  10086. {
  10087. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  10088. }
  10089. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10090. // SupportedFeatureProfiles
  10091. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10092. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10093. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10094. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10095. // SupportedFeatureProfilesMaxLength
  10096. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10097. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10098. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10099. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10100. // TransactionMessageAttempts
  10101. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10102. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10103. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10104. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10105. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10106. // TransactionMessageRetryInterval
  10107. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10108. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10109. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10110. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10111. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10112. // UnlockConnectorOnEVSideDisconnect
  10113. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10114. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10115. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10116. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10117. // WebSocketPingInterval
  10118. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10119. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10120. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10121. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10122. // QueueOffLineStartTransactionMessage
  10123. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  10124. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10125. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10126. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10127. // AuthorizationKey
  10128. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  10129. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  10130. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "" );
  10131. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  10132. // SecurityProfile
  10133. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  10134. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  10135. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "0" );
  10136. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  10137. // DefaultPrice
  10138. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  10139. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  10140. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  10141. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  10142. // CustomDisplayCostAndPrice
  10143. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  10144. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  10145. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  10146. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  10147. // CustomIdleFeeAfterStop
  10148. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  10149. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  10150. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  10151. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  10152. //* Local Auth List Management Profile*/
  10153. #if 0
  10154. //For OCTT Test Case
  10155. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10156. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  10157. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10158. #endif
  10159. #if 1
  10160. //LocalAuthListEnabled
  10161. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10162. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10163. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10164. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10165. #endif
  10166. //LocalAuthListMaxLength
  10167. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10168. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10169. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10170. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10171. //SendLocalListMaxLength
  10172. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10173. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10174. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  10175. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10176. //ReserveConnectorZeroSupported
  10177. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10178. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10179. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10180. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10181. //* Smart Charging Profile */
  10182. //ChargeProfileMaxStackLevel
  10183. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10184. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10185. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10186. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10187. // ChargingScheduleAllowedChargingRateUnit
  10188. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10189. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10190. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10191. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10192. // ChargingScheduleMaxPeriods
  10193. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10194. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10195. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10196. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10197. // ConnectorSwitch3to1PhaseSupported
  10198. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10199. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10200. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10201. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10202. // MaxChargingProfilesInstalled
  10203. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10204. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10205. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  10206. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10207. fclose(outfile);
  10208. }
  10209. else
  10210. {
  10211. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10212. char keystr[60]={0};
  10213. char readonlystr[10]={0};
  10214. char valuestr[100]={0};
  10215. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10216. if(fp == NULL) {
  10217. DEBUG_INFO("Error opening file");
  10218. return FALSE;
  10219. }
  10220. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  10221. {
  10222. //DEBUG_INFO("Get Configuration \n");
  10223. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10224. //*************************key*********************************/
  10225. loc = strstr(str, "key");
  10226. c = 0;
  10227. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10228. while (loc[strlen("key")+3+c] != '\"')
  10229. {
  10230. sstr[c] = loc[strlen("key")+3+c];
  10231. c++;
  10232. }
  10233. sstr[c] = '\0';
  10234. strcpy(keystr,sstr);
  10235. //*************************readonly*********************************/
  10236. loc = strstr(str, "readonly");
  10237. c = 0;
  10238. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10239. while (loc[strlen("readonly")+2+c] != ',')
  10240. {
  10241. sstr[c] = loc[strlen("readonly")+2+c];
  10242. c++;
  10243. }
  10244. sstr[c] = '\0';
  10245. strcpy(readonlystr,sstr);
  10246. //*************************value*********************************/
  10247. loc = strstr(str, "value");
  10248. c = 0;
  10249. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10250. while (loc[strlen("value")+3+c] != '\"')
  10251. {
  10252. sstr[c] = loc[strlen("value")+3+c];
  10253. c++;
  10254. }
  10255. sstr[c] = '\0';
  10256. strcpy(valuestr,sstr);
  10257. // DEBUG_INFO("keystr=%s\n",keystr);
  10258. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10259. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10260. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10261. {
  10262. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10263. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10264. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10265. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10266. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10267. }
  10268. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10269. {
  10270. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10271. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10272. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10273. }
  10274. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10275. {
  10276. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10277. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10278. }
  10279. if(strcmp(keystr, "BlinkRepeat") == 0)
  10280. {
  10281. //Charger.BlinkRepeat = Integer.parseInt(value);
  10282. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10283. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10284. }
  10285. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10286. {
  10287. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10288. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10289. }
  10290. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10291. {
  10292. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10293. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10294. }
  10295. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10296. {
  10297. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10298. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  10299. }
  10300. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10301. {
  10302. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10303. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10304. HeartBeatWaitTime = atoi(valuestr);
  10305. }
  10306. if(strcmp(keystr, "LightIntensity") == 0)
  10307. {
  10308. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10309. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10310. }
  10311. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10312. {
  10313. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10314. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10315. }
  10316. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10317. {
  10318. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10319. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10320. }
  10321. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10322. {
  10323. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10324. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10325. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10326. }
  10327. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10328. {
  10329. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10330. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10331. }
  10332. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10333. {
  10334. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10335. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10336. }
  10337. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10338. {
  10339. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10340. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10341. }
  10342. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10343. {
  10344. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10345. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10346. }
  10347. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10348. {
  10349. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10350. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10351. }
  10352. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10353. {
  10354. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10355. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10356. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10357. }
  10358. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10359. {
  10360. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10361. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10362. }
  10363. if(strcmp(keystr, "ResetRetries") == 0)
  10364. {
  10365. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10366. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10367. }
  10368. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10369. {
  10370. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10371. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10372. }
  10373. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10374. {
  10375. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10376. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10377. }
  10378. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10379. {
  10380. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10381. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10382. }
  10383. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10384. {
  10385. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10386. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10387. }
  10388. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10389. {
  10390. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10391. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10392. }
  10393. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10394. {
  10395. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10396. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10397. }
  10398. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10399. {
  10400. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10401. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10402. }
  10403. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10404. {
  10405. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10406. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10407. }
  10408. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10409. {
  10410. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10411. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10412. }
  10413. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10414. {
  10415. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10416. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10417. }
  10418. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10419. {
  10420. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10421. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10422. TransactionMessageAttemptsValue = atoi(valuestr);
  10423. }
  10424. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10425. {
  10426. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10427. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10428. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10429. }
  10430. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10431. {
  10432. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10433. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10434. }
  10435. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10436. {
  10437. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10438. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10439. }
  10440. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  10441. {
  10442. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10443. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  10444. }
  10445. if(strcmp(keystr, "AuthorizationKey") == 0)
  10446. {
  10447. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10448. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  10449. }
  10450. if(strcmp(keystr, "SecurityProfile") == 0)
  10451. {
  10452. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10453. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  10454. }
  10455. if(strcmp(keystr, "DefaultPrice") == 0)
  10456. {
  10457. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10458. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  10459. }
  10460. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  10461. {
  10462. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10463. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  10464. }
  10465. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  10466. {
  10467. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10468. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  10469. }
  10470. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10471. {
  10472. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10473. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10474. }
  10475. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10476. {
  10477. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10478. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10479. }
  10480. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10481. {
  10482. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10483. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10484. }
  10485. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10486. {
  10487. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10488. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10489. }
  10490. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10491. {
  10492. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10493. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10494. }
  10495. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10496. {
  10497. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10498. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10499. }
  10500. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10501. {
  10502. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10503. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10504. }
  10505. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10506. {
  10507. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10508. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10509. }
  10510. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10511. {
  10512. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10513. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10514. }
  10515. }
  10516. fclose(fp);
  10517. }
  10518. return 0;
  10519. }
  10520. void StoreConfigurationTable(void)
  10521. {
  10522. FILE *outfile;
  10523. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10524. if(outfile == NULL)
  10525. {
  10526. DEBUG_INFO("Error opening file");
  10527. return ;
  10528. }
  10529. /*Core Profile*/
  10530. //AllowOfflineTxForUnknownId
  10531. /*
  10532. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10533. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10534. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10535. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10536. */
  10537. //DEBUG_INFO("data=%s\n",data);
  10538. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10539. //AuthorizationCacheEnabled
  10540. /*
  10541. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10542. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10543. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10544. */
  10545. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10546. //AuthorizeRemoteTxRequests
  10547. /*
  10548. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10549. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10550. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10551. */
  10552. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10553. //BlinkRepeat
  10554. /*
  10555. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10556. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10557. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10558. */
  10559. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10560. //ClockAlignedDataInterval
  10561. /*
  10562. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10563. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10564. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10565. */
  10566. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10567. //ConnectionTimeOut
  10568. /*
  10569. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10570. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10571. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10572. */
  10573. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10574. //GetConfigurationMaxKeys
  10575. /*
  10576. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10577. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10578. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10579. */
  10580. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10581. // HeartbeatInterval
  10582. /*
  10583. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10584. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10585. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10586. */
  10587. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10588. // LightIntensity
  10589. /*
  10590. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10591. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10592. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10593. */
  10594. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10595. // LocalAuthorizeOffline
  10596. /*
  10597. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10598. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10599. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10600. */
  10601. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10602. // LocalPreAuthorize
  10603. /*
  10604. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10605. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10606. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10607. */
  10608. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10609. // MaxEnergyOnInvalidId
  10610. /*
  10611. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10612. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10613. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10614. */
  10615. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10616. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10617. // MeterValuesAlignedData
  10618. /*
  10619. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10620. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10621. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10622. */
  10623. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10624. // MeterValuesAlignedDataMaxLength
  10625. /*
  10626. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10627. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10628. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10629. */
  10630. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10631. // MeterValuesSampledData
  10632. /*
  10633. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10634. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10635. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10636. */
  10637. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10638. // MeterValuesSampledDataMaxLength
  10639. /*
  10640. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10641. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10642. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10643. */
  10644. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10645. // MeterValueSampleInterval
  10646. /*
  10647. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10648. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10649. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10650. */
  10651. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10652. // MinimumStatusDuration
  10653. /*
  10654. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10655. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10656. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10657. */
  10658. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10659. // NumberOfConnectors
  10660. /*
  10661. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10662. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10663. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10664. {
  10665. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10666. }
  10667. else
  10668. {
  10669. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10670. }
  10671. */
  10672. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10673. // ResetRetries
  10674. /*
  10675. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10676. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10677. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10678. */
  10679. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10680. // ConnectorPhaseRotation
  10681. /*
  10682. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10683. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10684. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10685. */
  10686. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10687. // ConnectorPhaseRotationMaxLength
  10688. /*
  10689. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10690. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10691. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10692. */
  10693. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10694. // StopTransactionOnEVSideDisconnect
  10695. /*
  10696. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10697. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10698. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10699. */
  10700. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10701. // StopTransactionOnInvalidId
  10702. /*
  10703. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  10704. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10705. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10706. */
  10707. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10708. // StopTxnAlignedData
  10709. /*
  10710. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  10711. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10712. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10713. */
  10714. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10715. // StopTxnAlignedDataMaxLength
  10716. /*
  10717. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10718. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10719. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10720. */
  10721. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10722. // StopTxnSampledData
  10723. /*
  10724. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10725. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10726. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  10727. */
  10728. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10729. // StopTxnSampledDataMaxLength
  10730. /*
  10731. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10732. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10733. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10734. */
  10735. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10736. // SupportedFeatureProfiles
  10737. /*
  10738. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10739. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10740. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10741. */
  10742. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10743. // SupportedFeatureProfilesMaxLength
  10744. /*
  10745. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10746. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10747. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10748. */
  10749. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10750. // TransactionMessageAttempts
  10751. /*
  10752. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10753. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10754. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10755. */
  10756. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10757. // TransactionMessageRetryInterval
  10758. /*
  10759. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10760. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10761. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10762. */
  10763. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10764. // UnlockConnectorOnEVSideDisconnect
  10765. /*
  10766. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10767. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10768. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10769. */
  10770. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10771. // WebSocketPingInterval
  10772. /*
  10773. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10775. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10776. */
  10777. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10778. // QueueOffLineStartTransactionMessage
  10779. /*
  10780. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  10781. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10782. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10783. */
  10784. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10785. // AuthorizationKey
  10786. /*
  10787. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  10788. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  10789. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  10790. */
  10791. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  10792. // SecurityProfile
  10793. /*
  10794. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  10795. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  10796. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  10797. */
  10798. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  10799. // DefaultPrice
  10800. /*
  10801. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  10802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  10803. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  10804. */
  10805. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  10806. // CustomDisplayCostAndPrice
  10807. /*
  10808. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  10809. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  10810. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  10811. */
  10812. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  10813. // CustomIdleFeeAfterStop
  10814. /*
  10815. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  10816. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  10817. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  10818. */
  10819. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  10820. //* Local Auth List Management Profile*/
  10821. //LocalAuthListEnabled
  10822. /*
  10823. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10824. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10825. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10826. */
  10827. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10828. //LocalAuthListMaxLength
  10829. /*
  10830. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10831. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10832. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10833. */
  10834. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10835. //SendLocalListMaxLength
  10836. /*
  10837. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10838. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10839. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10840. */
  10841. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10842. //ReserveConnectorZeroSupported
  10843. /*
  10844. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10845. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10846. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10847. */
  10848. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10849. //* Smart Charging Profile */
  10850. //ChargeProfileMaxStackLevel
  10851. /*
  10852. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10853. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10854. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10855. */
  10856. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10857. // ChargingScheduleAllowedChargingRateUnit
  10858. /*
  10859. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10860. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10861. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10862. */
  10863. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10864. // ChargingScheduleMaxPeriods
  10865. /*
  10866. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10867. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10868. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10869. */
  10870. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10871. // ConnectorSwitch3to1PhaseSupported
  10872. /*
  10873. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10874. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10875. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10876. */
  10877. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10878. // MaxChargingProfilesInstalled
  10879. /*
  10880. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10881. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10882. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  10883. */
  10884. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10885. fclose(outfile);
  10886. }
  10887. void getKeyValue(char *keyReq)
  10888. {
  10889. int isEmpty = FALSE;
  10890. int isKnowKey = FALSE;
  10891. DEBUG_INFO("keyReq = %s\n", keyReq);
  10892. if((keyReq == NULL) || (strlen(keyReq) == 0))
  10893. isEmpty = TRUE;
  10894. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  10895. {
  10896. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  10897. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  10898. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  10899. {
  10900. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  10901. }
  10902. else
  10903. {
  10904. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  10905. }
  10906. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  10907. isKnowKey = TRUE;
  10908. }
  10909. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  10910. {
  10911. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  10912. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  10913. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  10914. {
  10915. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  10916. }
  10917. else
  10918. {
  10919. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  10920. }
  10921. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  10922. isKnowKey = TRUE;
  10923. }
  10924. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  10925. {
  10926. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  10927. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  10928. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  10929. {
  10930. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  10931. }
  10932. else
  10933. {
  10934. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  10935. }
  10936. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  10937. isKnowKey = TRUE;
  10938. }
  10939. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  10940. {
  10941. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  10942. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  10943. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  10944. {
  10945. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  10946. }
  10947. else
  10948. {
  10949. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  10950. }
  10951. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  10952. isKnowKey = TRUE;
  10953. }
  10954. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  10955. {
  10956. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  10957. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  10958. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  10959. {
  10960. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  10961. }
  10962. else
  10963. {
  10964. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  10965. }
  10966. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  10967. isKnowKey = TRUE;
  10968. }
  10969. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  10970. {
  10971. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  10972. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  10973. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  10974. {
  10975. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  10976. }
  10977. else
  10978. {
  10979. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  10980. }
  10981. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  10982. isKnowKey = TRUE;
  10983. }
  10984. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  10985. {
  10986. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  10987. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  10988. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  10989. {
  10990. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  10991. }
  10992. else
  10993. {
  10994. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  10995. }
  10996. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  10997. isKnowKey = TRUE;
  10998. }
  10999. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  11000. {
  11001. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  11002. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  11003. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11004. {
  11005. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  11006. }
  11007. else
  11008. {
  11009. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  11010. }
  11011. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  11012. isKnowKey = TRUE;
  11013. }
  11014. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  11015. {
  11016. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  11017. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  11018. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11019. {
  11020. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  11021. }
  11022. else
  11023. {
  11024. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  11025. }
  11026. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  11027. isKnowKey = TRUE;
  11028. }
  11029. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  11030. {
  11031. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  11032. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  11033. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11034. {
  11035. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  11036. }
  11037. else
  11038. {
  11039. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  11040. }
  11041. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  11042. isKnowKey = TRUE;
  11043. }
  11044. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  11045. {
  11046. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  11047. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  11048. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11049. {
  11050. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  11051. }
  11052. else
  11053. {
  11054. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  11055. }
  11056. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  11057. isKnowKey = TRUE;
  11058. }
  11059. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  11060. {
  11061. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  11062. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  11063. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11064. {
  11065. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11066. }
  11067. else
  11068. {
  11069. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11070. }
  11071. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  11072. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  11073. isKnowKey = TRUE;
  11074. }
  11075. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  11076. {
  11077. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  11078. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  11079. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11080. {
  11081. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11082. }
  11083. else
  11084. {
  11085. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11086. }
  11087. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  11088. isKnowKey = TRUE;
  11089. }
  11090. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  11091. {
  11092. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  11093. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  11094. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11095. {
  11096. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11097. }
  11098. else
  11099. {
  11100. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11101. }
  11102. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  11103. isKnowKey = TRUE;
  11104. }
  11105. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  11106. {
  11107. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  11108. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  11109. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11110. {
  11111. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  11112. }
  11113. else
  11114. {
  11115. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  11116. }
  11117. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  11118. isKnowKey = TRUE;
  11119. }
  11120. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  11121. {
  11122. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  11123. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  11124. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11125. {
  11126. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11127. }
  11128. else
  11129. {
  11130. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11131. }
  11132. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  11133. isKnowKey = TRUE;
  11134. }
  11135. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  11136. {
  11137. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  11138. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  11139. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11140. {
  11141. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  11142. }
  11143. else
  11144. {
  11145. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  11146. }
  11147. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  11148. isKnowKey = TRUE;
  11149. }
  11150. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  11151. {
  11152. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  11153. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  11154. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11155. {
  11156. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  11157. }
  11158. else
  11159. {
  11160. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  11161. }
  11162. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  11163. isKnowKey = TRUE;
  11164. }
  11165. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  11166. {
  11167. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  11168. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  11169. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11170. {
  11171. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  11172. }
  11173. else
  11174. {
  11175. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  11176. }
  11177. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  11178. isKnowKey = TRUE;
  11179. }
  11180. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  11181. {
  11182. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  11183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11184. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11185. {
  11186. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11187. }
  11188. else
  11189. {
  11190. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11191. }
  11192. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11193. isKnowKey = TRUE;
  11194. }
  11195. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11196. {
  11197. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11199. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11200. {
  11201. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11202. }
  11203. else
  11204. {
  11205. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11206. }
  11207. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11208. isKnowKey = TRUE;
  11209. }
  11210. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11211. {
  11212. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11214. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11215. {
  11216. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11217. }
  11218. else
  11219. {
  11220. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11221. }
  11222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11223. isKnowKey = TRUE;
  11224. }
  11225. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11226. {
  11227. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11229. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11230. {
  11231. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11232. }
  11233. else
  11234. {
  11235. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11236. }
  11237. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11238. isKnowKey = TRUE;
  11239. }
  11240. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11241. {
  11242. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11244. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11245. {
  11246. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11247. }
  11248. else
  11249. {
  11250. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11251. }
  11252. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11253. isKnowKey = TRUE;
  11254. }
  11255. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11256. {
  11257. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11258. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11259. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11260. {
  11261. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11262. }
  11263. else
  11264. {
  11265. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11266. }
  11267. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11268. isKnowKey = TRUE;
  11269. }
  11270. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11271. {
  11272. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11273. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11274. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11275. {
  11276. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11277. }
  11278. else
  11279. {
  11280. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11281. }
  11282. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11283. isKnowKey = TRUE;
  11284. }
  11285. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11286. {
  11287. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11288. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11289. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11290. {
  11291. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11292. }
  11293. else
  11294. {
  11295. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11296. }
  11297. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11298. isKnowKey = TRUE;
  11299. }
  11300. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11301. {
  11302. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11303. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11304. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11305. {
  11306. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11307. }
  11308. else
  11309. {
  11310. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11311. }
  11312. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11313. isKnowKey = TRUE;
  11314. }
  11315. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11316. {
  11317. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11318. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11319. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11320. {
  11321. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11322. }
  11323. else
  11324. {
  11325. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11326. }
  11327. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11328. isKnowKey = TRUE;
  11329. }
  11330. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11331. {
  11332. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11333. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11334. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11335. {
  11336. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11337. }
  11338. else
  11339. {
  11340. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11341. }
  11342. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11343. isKnowKey = TRUE;
  11344. }
  11345. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11346. {
  11347. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11348. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11349. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11350. {
  11351. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11352. }
  11353. else
  11354. {
  11355. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11356. }
  11357. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11358. isKnowKey = TRUE;
  11359. }
  11360. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11361. {
  11362. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11363. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11364. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11365. {
  11366. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11367. }
  11368. else
  11369. {
  11370. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11371. }
  11372. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11373. isKnowKey = TRUE;
  11374. }
  11375. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11376. {
  11377. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11378. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11379. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11380. {
  11381. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11382. }
  11383. else
  11384. {
  11385. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11386. }
  11387. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11388. isKnowKey = TRUE;
  11389. }
  11390. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11391. {
  11392. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11393. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11394. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11395. {
  11396. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11397. }
  11398. else
  11399. {
  11400. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11401. }
  11402. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11403. isKnowKey = TRUE;
  11404. }
  11405. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  11406. {
  11407. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  11408. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  11409. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  11410. {
  11411. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  11412. }
  11413. else
  11414. {
  11415. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  11416. }
  11417. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  11418. isKnowKey = TRUE;
  11419. }
  11420. /*
  11421. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  11422. {
  11423. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  11424. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  11425. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  11426. {
  11427. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  11428. }
  11429. else
  11430. {
  11431. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  11432. }
  11433. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  11434. isKnowKey = TRUE;
  11435. }*/
  11436. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  11437. {
  11438. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  11439. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  11440. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  11441. {
  11442. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  11443. }
  11444. else
  11445. {
  11446. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  11447. }
  11448. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  11449. isKnowKey = TRUE;
  11450. }
  11451. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  11452. {
  11453. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  11454. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  11455. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  11456. {
  11457. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  11458. }
  11459. else
  11460. {
  11461. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  11462. }
  11463. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  11464. isKnowKey = TRUE;
  11465. }
  11466. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  11467. {
  11468. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  11469. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  11470. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  11471. {
  11472. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  11473. }
  11474. else
  11475. {
  11476. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  11477. }
  11478. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  11479. isKnowKey = TRUE;
  11480. }
  11481. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  11482. {
  11483. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  11484. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  11485. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  11486. {
  11487. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  11488. }
  11489. else
  11490. {
  11491. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  11492. }
  11493. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  11494. isKnowKey = TRUE;
  11495. }
  11496. #if 1
  11497. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11498. {
  11499. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11500. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11501. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11502. {
  11503. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11504. }
  11505. else
  11506. {
  11507. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11508. }
  11509. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11510. isKnowKey = TRUE;
  11511. }
  11512. #endif
  11513. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11514. {
  11515. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11517. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11518. {
  11519. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11520. }
  11521. else
  11522. {
  11523. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11524. }
  11525. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11526. isKnowKey = TRUE;
  11527. }
  11528. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11529. {
  11530. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11531. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11532. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11533. {
  11534. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11535. }
  11536. else
  11537. {
  11538. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11539. }
  11540. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11541. isKnowKey = TRUE;
  11542. }
  11543. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11544. {
  11545. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11546. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11547. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11548. {
  11549. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11550. }
  11551. else
  11552. {
  11553. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11554. }
  11555. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11556. isKnowKey = TRUE;
  11557. }
  11558. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11559. {
  11560. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11561. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11562. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11563. {
  11564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11565. }
  11566. else
  11567. {
  11568. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11569. }
  11570. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11571. isKnowKey = TRUE;
  11572. }
  11573. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11574. {
  11575. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11576. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11577. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11578. {
  11579. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11580. }
  11581. else
  11582. {
  11583. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11584. }
  11585. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11586. isKnowKey = TRUE;
  11587. }
  11588. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11589. {
  11590. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11591. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11592. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11593. {
  11594. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11595. }
  11596. else
  11597. {
  11598. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11599. }
  11600. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11601. isKnowKey = TRUE;
  11602. }
  11603. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11604. {
  11605. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11606. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11607. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11608. {
  11609. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11610. }
  11611. else
  11612. {
  11613. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11614. }
  11615. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11616. isKnowKey = TRUE;
  11617. }
  11618. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11619. {
  11620. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11621. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11622. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11623. {
  11624. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11625. }
  11626. else
  11627. {
  11628. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11629. }
  11630. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11631. isKnowKey = TRUE;
  11632. }
  11633. //=========================================================
  11634. if(!isEmpty && !isKnowKey)
  11635. {
  11636. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11637. strcpy(unknownkey[UnknownKeynum], keyReq);
  11638. UnknownKeynum = UnknownKeynum + 1;
  11639. }
  11640. }
  11641. void processUnkownKey(void)
  11642. {
  11643. DEBUG_INFO("processUnkownKey...\n");
  11644. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11645. for(int index=0; index < UnknownKeynum; index++)
  11646. {
  11647. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11648. {
  11649. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11650. }
  11651. }
  11652. }
  11653. int setKeyValue(char *key, char *value)
  11654. {
  11655. int isSuccess = NotSupported;
  11656. int check_ascii=0;
  11657. char str[10]={0};
  11658. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  11659. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11660. {
  11661. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11662. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11663. {
  11664. strcpy(str, (const char*)value);
  11665. for(int i = 0; str[i]; i++){
  11666. str[i] = tolower(str[i]);
  11667. }
  11668. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11669. isSuccess = ConfigurationStatus_Accepted;
  11670. }
  11671. else
  11672. {
  11673. isSuccess = ConfigurationStatus_Rejected;
  11674. }
  11675. }
  11676. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11677. {
  11678. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11679. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11680. {
  11681. strcpy(str, (const char*)value);
  11682. for(int i = 0; str[i]; i++){
  11683. str[i] = tolower(str[i]);
  11684. }
  11685. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11686. isSuccess = ConfigurationStatus_Accepted;
  11687. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11688. }
  11689. else
  11690. {
  11691. isSuccess = ConfigurationStatus_Rejected;
  11692. }
  11693. }
  11694. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11695. {
  11696. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11697. {
  11698. strcpy(str, (const char*)value);
  11699. for(int i = 0; str[i]; i++)
  11700. {
  11701. str[i] = tolower(str[i]);
  11702. }
  11703. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  11704. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11705. isSuccess = ConfigurationStatus_Accepted;
  11706. }
  11707. else
  11708. {
  11709. isSuccess = ConfigurationStatus_Rejected;
  11710. }
  11711. }
  11712. if(strcmp(key, "BlinkRepeat") == 0)
  11713. {
  11714. //Charger.BlinkRepeat = Integer.parseInt(value);
  11715. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11716. {
  11717. check_ascii = value[0];
  11718. if( (check_ascii < 48) || (check_ascii > 57) )
  11719. {
  11720. isSuccess = ConfigurationStatus_Rejected;
  11721. }
  11722. else
  11723. {
  11724. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  11725. isSuccess = ConfigurationStatus_Accepted;
  11726. }
  11727. }
  11728. else
  11729. {
  11730. isSuccess = ConfigurationStatus_Rejected;
  11731. }
  11732. }
  11733. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  11734. {
  11735. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11736. {
  11737. check_ascii = value[0];
  11738. if( (check_ascii < 48) || (check_ascii > 57) )
  11739. {
  11740. isSuccess = ConfigurationStatus_Rejected;
  11741. }
  11742. else
  11743. {
  11744. if((atoi(value) == 0) || (atoi(value) >= 10))
  11745. {
  11746. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  11747. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  11748. isSuccess = ConfigurationStatus_Accepted;
  11749. }
  11750. else
  11751. isSuccess = ConfigurationStatus_Rejected;
  11752. }
  11753. }
  11754. else
  11755. {
  11756. isSuccess = ConfigurationStatus_Rejected;
  11757. }
  11758. }
  11759. if(strcmp(key, "ConnectionTimeOut") == 0 )
  11760. {
  11761. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11762. {
  11763. check_ascii = value[0];
  11764. if( (check_ascii < 48) || (check_ascii > 57) )
  11765. {
  11766. isSuccess = ConfigurationStatus_Rejected;
  11767. }
  11768. else
  11769. {
  11770. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  11771. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  11772. isSuccess = ConfigurationStatus_Accepted;
  11773. }
  11774. }
  11775. else
  11776. {
  11777. isSuccess = ConfigurationStatus_Rejected;
  11778. }
  11779. }
  11780. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  11781. {
  11782. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11783. {
  11784. check_ascii = value[0];
  11785. if( (check_ascii < 48) || (check_ascii > 57) )
  11786. {
  11787. isSuccess = ConfigurationStatus_Rejected;
  11788. }
  11789. else
  11790. {
  11791. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11792. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  11793. isSuccess = ConfigurationStatus_Accepted;
  11794. }
  11795. }
  11796. else
  11797. {
  11798. isSuccess = ConfigurationStatus_Rejected;
  11799. }
  11800. }
  11801. if(strcmp(key, "HeartbeatInterval") == 0)
  11802. {
  11803. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11804. {
  11805. check_ascii = value[0];
  11806. if( (check_ascii < 48) || (check_ascii > 57) )
  11807. {
  11808. isSuccess = ConfigurationStatus_Rejected;
  11809. }
  11810. else
  11811. {
  11812. if((atoi(value) == 0) || (atoi(value) >= 10))
  11813. {
  11814. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11815. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  11816. HeartBeatWaitTime = atoi(value);
  11817. isSuccess = ConfigurationStatus_Accepted;
  11818. }
  11819. else
  11820. {
  11821. isSuccess = ConfigurationStatus_Rejected;
  11822. }
  11823. }
  11824. }
  11825. else
  11826. {
  11827. isSuccess = ConfigurationStatus_Rejected;
  11828. }
  11829. }
  11830. if(strcmp(key, "LightIntensity") == 0)
  11831. {
  11832. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11833. {
  11834. check_ascii = value[0];
  11835. if( (check_ascii < 48) || (check_ascii > 57) )
  11836. {
  11837. isSuccess = ConfigurationStatus_Rejected;
  11838. }
  11839. else
  11840. {
  11841. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  11842. isSuccess = ConfigurationStatus_Accepted;
  11843. }
  11844. }
  11845. else
  11846. {
  11847. isSuccess = ConfigurationStatus_Rejected;
  11848. }
  11849. }
  11850. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  11851. {
  11852. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11853. {
  11854. strcpy(str, (const char*)value);
  11855. for(int i = 0; str[i]; i++)
  11856. {
  11857. str[i] = tolower(str[i]);
  11858. }
  11859. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11860. isSuccess = ConfigurationStatus_Accepted;
  11861. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11862. }
  11863. else
  11864. {
  11865. isSuccess = ConfigurationStatus_Rejected;
  11866. }
  11867. }
  11868. if(strcmp(key, "LocalPreAuthorize") == 0)
  11869. {
  11870. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11871. {
  11872. strcpy(str, (const char*)value);
  11873. for(int i = 0; str[i]; i++)
  11874. {
  11875. str[i] = tolower(str[i]);
  11876. }
  11877. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11878. isSuccess = ConfigurationStatus_Accepted;
  11879. }
  11880. else
  11881. {
  11882. isSuccess = ConfigurationStatus_Rejected;
  11883. }
  11884. }
  11885. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  11886. {
  11887. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11888. {
  11889. check_ascii = value[0];
  11890. if( (check_ascii < 48) || (check_ascii > 57) )
  11891. {
  11892. isSuccess = ConfigurationStatus_Rejected;
  11893. }
  11894. else
  11895. {
  11896. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  11897. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  11898. isSuccess = ConfigurationStatus_Accepted;
  11899. }
  11900. }
  11901. else
  11902. {
  11903. isSuccess = ConfigurationStatus_Rejected;
  11904. }
  11905. }
  11906. if(strcmp(key, "MeterValuesAlignedData") == 0)
  11907. {
  11908. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11909. {
  11910. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  11911. isSuccess = ConfigurationStatus_Accepted;
  11912. }
  11913. else
  11914. {
  11915. isSuccess = ConfigurationStatus_Rejected;
  11916. }
  11917. }
  11918. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  11919. {
  11920. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11921. {
  11922. check_ascii = value[0];
  11923. if( (check_ascii < 48) || (check_ascii > 57) )
  11924. {
  11925. isSuccess = ConfigurationStatus_Rejected;
  11926. }
  11927. else
  11928. {
  11929. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11930. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  11931. isSuccess = ConfigurationStatus_Accepted;
  11932. }
  11933. }
  11934. else
  11935. {
  11936. isSuccess = ConfigurationStatus_Rejected;
  11937. }
  11938. }
  11939. if(strcmp(key, "MeterValuesSampledData") == 0 )
  11940. {
  11941. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11942. {
  11943. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  11944. isSuccess = ConfigurationStatus_Accepted;
  11945. }
  11946. else
  11947. {
  11948. isSuccess = ConfigurationStatus_Rejected;
  11949. }
  11950. }
  11951. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  11952. {
  11953. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11954. {
  11955. check_ascii = value[0];
  11956. if( (check_ascii < 48) || (check_ascii > 57) )
  11957. {
  11958. isSuccess = ConfigurationStatus_Rejected;
  11959. }
  11960. else
  11961. {
  11962. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11963. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  11964. isSuccess = ConfigurationStatus_Accepted;
  11965. }
  11966. }
  11967. else
  11968. {
  11969. isSuccess = ConfigurationStatus_Rejected;
  11970. }
  11971. }
  11972. if(strcmp(key, "MeterValueSampleInterval") == 0)
  11973. {
  11974. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11975. {
  11976. check_ascii = value[0];
  11977. if( (check_ascii < 48) || (check_ascii > 57) )
  11978. {
  11979. isSuccess = ConfigurationStatus_Rejected;
  11980. }
  11981. else
  11982. {
  11983. if((atoi(value) == 0) || (atoi(value) >= 10))
  11984. {
  11985. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11986. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  11987. isSuccess = ConfigurationStatus_Accepted;
  11988. }
  11989. else
  11990. {
  11991. isSuccess = ConfigurationStatus_Rejected;
  11992. }
  11993. }
  11994. }
  11995. else
  11996. {
  11997. isSuccess = ConfigurationStatus_Rejected;
  11998. }
  11999. }
  12000. if(strcmp(key, "MinimumStatusDuration") == 0)
  12001. {
  12002. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12003. {
  12004. check_ascii = value[0];
  12005. if( (check_ascii < 48) || (check_ascii > 57) )
  12006. {
  12007. isSuccess = ConfigurationStatus_Rejected;
  12008. }
  12009. else
  12010. {
  12011. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  12012. {
  12013. isSuccess = ConfigurationStatus_Rejected;
  12014. }
  12015. else
  12016. {
  12017. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  12018. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  12019. server_cycle_Status = atoi(value); //StatusNotification Cycle
  12020. isSuccess = ConfigurationStatus_Accepted;
  12021. }
  12022. }
  12023. }
  12024. else
  12025. {
  12026. isSuccess = ConfigurationStatus_Rejected;
  12027. }
  12028. }
  12029. if(strcmp(key, "NumberOfConnectors") == 0)
  12030. {
  12031. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12032. {
  12033. check_ascii = value[0];
  12034. if( (check_ascii < 48) || (check_ascii > 57) )
  12035. {
  12036. isSuccess = ConfigurationStatus_Rejected;
  12037. }
  12038. else
  12039. {
  12040. //Charger.ResetRetries = Integer.parseInt(value);
  12041. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  12042. isSuccess = ConfigurationStatus_Accepted;
  12043. }
  12044. }
  12045. else
  12046. {
  12047. isSuccess = ConfigurationStatus_Rejected;
  12048. }
  12049. }
  12050. if(strcmp(key, "ResetRetries") == 0)
  12051. {
  12052. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12053. {
  12054. check_ascii = value[0];
  12055. if( (check_ascii < 48) || (check_ascii > 57) )
  12056. {
  12057. isSuccess = ConfigurationStatus_Rejected;
  12058. }
  12059. else
  12060. {
  12061. //Charger.ResetRetries = Integer.parseInt(value);
  12062. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  12063. isSuccess = ConfigurationStatus_Accepted;
  12064. }
  12065. }
  12066. else
  12067. {
  12068. isSuccess = ConfigurationStatus_Rejected;
  12069. }
  12070. }
  12071. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  12072. {
  12073. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12074. {
  12075. strcpy(str, (const char*)value);
  12076. for(int i = 0; str[i]; i++)
  12077. {
  12078. str[i] = tolower(str[i]);
  12079. }
  12080. if(strcmp(str, "notapplicable")== 0)
  12081. {
  12082. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  12083. isSuccess = ConfigurationStatus_Accepted;
  12084. }
  12085. else if(strcmp(str, "unknown")== 0)
  12086. {
  12087. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  12088. isSuccess = ConfigurationStatus_Accepted;
  12089. }
  12090. else if(strcmp(str, "rst")== 0)
  12091. {
  12092. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  12093. isSuccess = ConfigurationStatus_Accepted;
  12094. }
  12095. else if(strcmp(str, "rts")== 0)
  12096. {
  12097. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  12098. isSuccess = ConfigurationStatus_Accepted;
  12099. }
  12100. else if(strcmp(str, "srt")== 0)
  12101. {
  12102. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  12103. isSuccess = ConfigurationStatus_Accepted;
  12104. }
  12105. else if(strcmp(str, "str")== 0)
  12106. {
  12107. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  12108. isSuccess = ConfigurationStatus_Accepted;
  12109. }
  12110. else if(strcmp(str, "trs")== 0)
  12111. {
  12112. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  12113. isSuccess = ConfigurationStatus_Accepted;
  12114. }
  12115. else if(strcmp(str, "tsr")== 0)
  12116. {
  12117. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  12118. isSuccess = ConfigurationStatus_Accepted;
  12119. }
  12120. else
  12121. {
  12122. isSuccess = ConfigurationStatus_Rejected;
  12123. }
  12124. }
  12125. else
  12126. {
  12127. isSuccess = ConfigurationStatus_Rejected;
  12128. }
  12129. }
  12130. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  12131. {
  12132. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12133. {
  12134. check_ascii = value[0];
  12135. if( (check_ascii < 48) || (check_ascii > 57) )
  12136. {
  12137. isSuccess = ConfigurationStatus_Rejected;
  12138. }
  12139. else
  12140. {
  12141. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  12142. isSuccess = ConfigurationStatus_Accepted;
  12143. }
  12144. }
  12145. else
  12146. {
  12147. isSuccess = ConfigurationStatus_Rejected;
  12148. }
  12149. }
  12150. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  12151. {
  12152. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12153. {
  12154. strcpy(str, (const char*)value);
  12155. for(int i = 0; str[i]; i++)
  12156. {
  12157. str[i] = tolower(str[i]);
  12158. }
  12159. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12160. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12161. isSuccess = ConfigurationStatus_Accepted;
  12162. }
  12163. else
  12164. {
  12165. isSuccess = ConfigurationStatus_Rejected;
  12166. }
  12167. }
  12168. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  12169. {
  12170. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12171. {
  12172. strcpy(str, (const char*)value);
  12173. for(int i = 0; str[i]; i++)
  12174. {
  12175. str[i] = tolower(str[i]);
  12176. }
  12177. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  12178. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12179. isSuccess = ConfigurationStatus_Accepted;
  12180. }
  12181. else
  12182. {
  12183. isSuccess = ConfigurationStatus_Rejected;
  12184. }
  12185. }
  12186. if(strcmp(key, "StopTxnAlignedData") == 0)
  12187. {
  12188. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12189. {
  12190. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  12191. isSuccess = ConfigurationStatus_Accepted;
  12192. }
  12193. else
  12194. {
  12195. isSuccess = ConfigurationStatus_Rejected;
  12196. }
  12197. }
  12198. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  12199. {
  12200. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12201. {
  12202. check_ascii = value[0];
  12203. if( (check_ascii < 48) || (check_ascii > 57) )
  12204. {
  12205. isSuccess = ConfigurationStatus_Rejected;
  12206. }
  12207. else
  12208. {
  12209. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  12210. isSuccess = ConfigurationStatus_Accepted;
  12211. }
  12212. }
  12213. else
  12214. {
  12215. isSuccess = ConfigurationStatus_Rejected;
  12216. }
  12217. }
  12218. if(strcmp(key, "StopTxnSampledData") == 0)
  12219. {
  12220. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12221. {
  12222. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  12223. isSuccess = ConfigurationStatus_Accepted;
  12224. }
  12225. else
  12226. {
  12227. isSuccess = ConfigurationStatus_Rejected;
  12228. }
  12229. }
  12230. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  12231. {
  12232. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12233. {
  12234. check_ascii = value[0];
  12235. if( (check_ascii < 48) || (check_ascii > 57) )
  12236. {
  12237. isSuccess = ConfigurationStatus_Rejected;
  12238. }
  12239. else
  12240. {
  12241. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  12242. isSuccess = ConfigurationStatus_Accepted;
  12243. }
  12244. }
  12245. else
  12246. {
  12247. isSuccess = ConfigurationStatus_Rejected;
  12248. }
  12249. }
  12250. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  12251. {
  12252. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12253. {
  12254. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  12255. isSuccess = ConfigurationStatus_Accepted;
  12256. }
  12257. else
  12258. {
  12259. isSuccess = ConfigurationStatus_Rejected;
  12260. }
  12261. }
  12262. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  12263. {
  12264. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12265. {
  12266. check_ascii = value[0];
  12267. if( (check_ascii < 48) || (check_ascii > 57) )
  12268. {
  12269. isSuccess = ConfigurationStatus_Rejected;
  12270. }
  12271. else
  12272. {
  12273. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  12274. isSuccess = ConfigurationStatus_Accepted;
  12275. }
  12276. }
  12277. else
  12278. {
  12279. isSuccess = ConfigurationStatus_Rejected;
  12280. }
  12281. }
  12282. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12283. {
  12284. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12285. {
  12286. check_ascii = value[0];
  12287. if( (check_ascii < 48) || (check_ascii > 57) )
  12288. {
  12289. isSuccess = ConfigurationStatus_Rejected;
  12290. }
  12291. else
  12292. {
  12293. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12294. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12295. TransactionMessageAttemptsValue = atoi(value);
  12296. isSuccess = ConfigurationStatus_Accepted;
  12297. }
  12298. }
  12299. else
  12300. {
  12301. isSuccess = ConfigurationStatus_Rejected;
  12302. }
  12303. }
  12304. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12305. {
  12306. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12307. {
  12308. check_ascii = value[0];
  12309. if( (check_ascii < 48) || (check_ascii > 57) )
  12310. {
  12311. isSuccess = ConfigurationStatus_Rejected;
  12312. }
  12313. else
  12314. {
  12315. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12316. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12317. TransactionMessageRetryIntervalValue = atoi(value);
  12318. isSuccess = ConfigurationStatus_Accepted;
  12319. }
  12320. }
  12321. else
  12322. {
  12323. isSuccess = ConfigurationStatus_Rejected;
  12324. }
  12325. }
  12326. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12327. {
  12328. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12329. {
  12330. strcpy(str, (const char*)value);
  12331. for(int i = 0; str[i]; i++)
  12332. {
  12333. str[i] = tolower(str[i]);
  12334. }
  12335. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12336. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12337. isSuccess = ConfigurationStatus_Accepted;
  12338. }
  12339. else
  12340. {
  12341. isSuccess = ConfigurationStatus_Rejected;
  12342. }
  12343. }
  12344. if(strcmp(key, "WebSocketPingInterval") == 0)
  12345. {
  12346. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12347. {
  12348. check_ascii = value[0];
  12349. if( (check_ascii < 48) || (check_ascii > 57) )
  12350. {
  12351. isSuccess = ConfigurationStatus_Rejected;
  12352. }
  12353. else
  12354. {
  12355. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12356. isSuccess = ConfigurationStatus_Accepted;
  12357. }
  12358. }
  12359. else
  12360. {
  12361. isSuccess = ConfigurationStatus_Rejected;
  12362. }
  12363. }
  12364. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  12365. {
  12366. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12367. {
  12368. strcpy(str, (const char*)value);
  12369. for(int i = 0; str[i]; i++)
  12370. {
  12371. str[i] = tolower(str[i]);
  12372. }
  12373. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12374. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12375. isSuccess = ConfigurationStatus_Accepted;
  12376. }
  12377. else
  12378. {
  12379. isSuccess = ConfigurationStatus_Rejected;
  12380. }
  12381. }
  12382. if(strcmp(key, "AuthorizationKey") == 0)
  12383. {
  12384. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  12385. {
  12386. strcpy(str, (const char*)value);
  12387. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  12388. isSuccess = ConfigurationStatus_Accepted;
  12389. }
  12390. else
  12391. {
  12392. isSuccess = ConfigurationStatus_Rejected;
  12393. }
  12394. }
  12395. if(strcmp(key, "SecurityProfile") == 0)
  12396. {
  12397. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  12398. {
  12399. check_ascii = value[0];
  12400. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  12401. {
  12402. isSuccess = ConfigurationStatus_Rejected;
  12403. }
  12404. else if(check_ascii == 0x33)
  12405. {
  12406. isSuccess = NotSupported;
  12407. }
  12408. else
  12409. {
  12410. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  12411. {
  12412. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  12413. isSuccess = ConfigurationStatus_Accepted;
  12414. }
  12415. else
  12416. isSuccess = ConfigurationStatus_Rejected;
  12417. }
  12418. }
  12419. else
  12420. {
  12421. isSuccess = ConfigurationStatus_Rejected;
  12422. }
  12423. }
  12424. if(strcmp(key, "DefaultPrice") == 0)
  12425. {
  12426. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  12427. {
  12428. strcpy(str, (const char*)value);
  12429. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  12430. isSuccess = ConfigurationStatus_Accepted;
  12431. }
  12432. else
  12433. {
  12434. isSuccess = ConfigurationStatus_Rejected;
  12435. }
  12436. }
  12437. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  12438. {
  12439. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  12440. {
  12441. strcpy(str, (const char*)value);
  12442. for(int i = 0; str[i]; i++)
  12443. {
  12444. str[i] = tolower(str[i]);
  12445. }
  12446. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12447. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12448. isSuccess = ConfigurationStatus_Accepted;
  12449. }
  12450. else
  12451. {
  12452. isSuccess = ConfigurationStatus_Rejected;
  12453. }
  12454. }
  12455. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  12456. {
  12457. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  12458. {
  12459. strcpy(str, (const char*)value);
  12460. for(int i = 0; str[i]; i++)
  12461. {
  12462. str[i] = tolower(str[i]);
  12463. }
  12464. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12465. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12466. isSuccess = ConfigurationStatus_Accepted;
  12467. }
  12468. else
  12469. {
  12470. isSuccess = ConfigurationStatus_Rejected;
  12471. }
  12472. }
  12473. #if 0
  12474. //For OCPP Test Case
  12475. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  12476. {
  12477. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12478. {
  12479. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  12480. isSuccess = ConfigurationStatus_Accepted;
  12481. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12482. }
  12483. else
  12484. {
  12485. isSuccess = ConfigurationStatus_Rejected;
  12486. }
  12487. }
  12488. #endif
  12489. #if 1
  12490. if(strcmp(key, "LocalAuthListEnabled") == 0)
  12491. {
  12492. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12493. {
  12494. strcpy(str, (const char*)value);
  12495. for(int i = 0; str[i]; i++)
  12496. {
  12497. str[i] = tolower(str[i]);
  12498. }
  12499. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12500. isSuccess = ConfigurationStatus_Accepted;
  12501. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12502. }
  12503. else
  12504. {
  12505. isSuccess = ConfigurationStatus_Rejected;
  12506. }
  12507. }
  12508. #endif
  12509. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12510. {
  12511. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12512. {
  12513. check_ascii = value[0];
  12514. if( (check_ascii < 48) || (check_ascii > 57) )
  12515. {
  12516. isSuccess = ConfigurationStatus_Rejected;
  12517. }
  12518. else
  12519. {
  12520. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12521. isSuccess = ConfigurationStatus_Accepted;
  12522. }
  12523. }
  12524. else
  12525. {
  12526. isSuccess = ConfigurationStatus_Rejected;
  12527. }
  12528. }
  12529. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12530. {
  12531. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12532. {
  12533. check_ascii = value[0];
  12534. if( (check_ascii < 48) || (check_ascii > 57) )
  12535. {
  12536. isSuccess = ConfigurationStatus_Rejected;
  12537. }
  12538. else
  12539. {
  12540. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12541. isSuccess = ConfigurationStatus_Accepted;
  12542. }
  12543. }
  12544. else
  12545. {
  12546. isSuccess = ConfigurationStatus_Rejected;
  12547. }
  12548. }
  12549. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12550. {
  12551. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12552. {
  12553. strcpy(str, (const char*)value);
  12554. for(int i = 0; str[i]; i++)
  12555. {
  12556. str[i] = tolower(str[i]);
  12557. }
  12558. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12559. isSuccess = ConfigurationStatus_Accepted;
  12560. }
  12561. else
  12562. {
  12563. isSuccess = ConfigurationStatus_Rejected;
  12564. }
  12565. }
  12566. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12567. {
  12568. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12569. {
  12570. check_ascii = value[0];
  12571. if( (check_ascii < 48) || (check_ascii > 57) )
  12572. {
  12573. isSuccess = ConfigurationStatus_Rejected;
  12574. }
  12575. else
  12576. {
  12577. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12578. isSuccess = ConfigurationStatus_Accepted;
  12579. }
  12580. }
  12581. else
  12582. {
  12583. isSuccess = ConfigurationStatus_Rejected;
  12584. }
  12585. }
  12586. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12587. {
  12588. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12589. {
  12590. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12591. isSuccess = ConfigurationStatus_Accepted;
  12592. }
  12593. else
  12594. {
  12595. isSuccess = ConfigurationStatus_Rejected;
  12596. }
  12597. }
  12598. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12599. {
  12600. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12601. {
  12602. check_ascii = value[0];
  12603. if( (check_ascii < 48) || (check_ascii > 57) )
  12604. {
  12605. isSuccess = ConfigurationStatus_Rejected;
  12606. }
  12607. else
  12608. {
  12609. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12610. isSuccess = ConfigurationStatus_Accepted;
  12611. }
  12612. }
  12613. else
  12614. {
  12615. isSuccess = ConfigurationStatus_Rejected;
  12616. }
  12617. }
  12618. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12619. {
  12620. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12621. {
  12622. strcpy(str, (const char*)value);
  12623. for(int i = 0; str[i]; i++)
  12624. {
  12625. str[i] = tolower(str[i]);
  12626. }
  12627. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12628. isSuccess = ConfigurationStatus_Accepted;
  12629. }
  12630. else
  12631. {
  12632. isSuccess = ConfigurationStatus_Rejected;
  12633. }
  12634. }
  12635. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12636. {
  12637. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12638. {
  12639. check_ascii = value[0];
  12640. if( (check_ascii < 48) || (check_ascii > 57) )
  12641. {
  12642. isSuccess = ConfigurationStatus_Rejected;
  12643. }
  12644. else
  12645. {
  12646. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12647. isSuccess = ConfigurationStatus_Accepted;
  12648. }
  12649. }
  12650. else
  12651. {
  12652. isSuccess = ConfigurationStatus_Rejected;
  12653. }
  12654. }
  12655. return isSuccess;
  12656. }
  12657. int TransactionMessageAttemptsGet(void)
  12658. {
  12659. return TransactionMessageAttemptsValue;
  12660. }
  12661. int FirstHeartBeatResponse(void)
  12662. {
  12663. return FirstHeartBeat;
  12664. }
  12665. int TransactionMessageRetryIntervalGet(void)
  12666. {
  12667. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12668. }
  12669. int ReadHttpStatus(int sock)
  12670. {
  12671. //char c;
  12672. char buff[1024]="",*ptr=buff+1;
  12673. int bytes_received, status;
  12674. DEBUG_INFO("Begin Response ..\n");
  12675. while((bytes_received = recv(sock, ptr, 1, 0))){
  12676. if(bytes_received==-1){
  12677. perror("ReadHttpStatus");
  12678. exit(1);
  12679. }
  12680. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  12681. ptr++;
  12682. }
  12683. *ptr=0;
  12684. ptr=buff+1;
  12685. sscanf(ptr,"%*s %d ", &status);
  12686. DEBUG_INFO("%s\n",ptr);
  12687. DEBUG_INFO("status=%d\n",status);
  12688. DEBUG_INFO("End Response ..\n");
  12689. return (bytes_received>0)?status:0;
  12690. }
  12691. //the only filed that it parsed is 'Content-Length'
  12692. int ParseHeader(int sock)
  12693. {
  12694. //char c;
  12695. char buff[1024]="",*ptr=buff+4;
  12696. int bytes_received;
  12697. DEBUG_INFO("Begin HEADER ..\n");
  12698. while((bytes_received = recv(sock, ptr, 1, 0))){
  12699. if(bytes_received==-1){
  12700. perror("Parse Header");
  12701. exit(1);
  12702. }
  12703. if(
  12704. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  12705. (ptr[-1]=='\r') && (*ptr=='\n' )
  12706. ) break;
  12707. ptr++;
  12708. }
  12709. *ptr=0;
  12710. ptr=buff+4;
  12711. //printf("%s",ptr);
  12712. if(bytes_received){
  12713. ptr=strstr(ptr,"Content-Length:");
  12714. if(ptr){
  12715. sscanf(ptr,"%*s %d",&bytes_received);
  12716. }else
  12717. bytes_received=-1; //unknown size
  12718. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  12719. }
  12720. DEBUG_INFO("End HEADER ..\n");
  12721. return bytes_received ;
  12722. }
  12723. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  12724. {
  12725. char rmFileCmd[100]={0};
  12726. char FilePath[100]={0};
  12727. char ftpbuf[200];
  12728. int systemresult;
  12729. //DEBUG_INFO("filename=%s\n",filename);
  12730. //DEBUG_INFO("url=%s\n",url);
  12731. sprintf(FilePath,"/mnt/%s",filename);
  12732. system("ping 8.8.8.8 &");
  12733. if((access(FilePath,F_OK))!=-1)
  12734. {
  12735. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12736. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12737. system(rmFileCmd);
  12738. }
  12739. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12740. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  12741. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12742. systemresult = system(ftpbuf);
  12743. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12744. if(systemresult != 0)
  12745. {
  12746. DEBUG_INFO("http DownLoad error!\n");
  12747. return FALSE;
  12748. }
  12749. system("pkill ping");
  12750. return TRUE;
  12751. }
  12752. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  12753. {
  12754. char rmFileCmd[100]={0};
  12755. char FilePath[100]={0};
  12756. char ftpbuf[200];
  12757. int systemresult;
  12758. //char temp[100];
  12759. sprintf(FilePath,"/mnt/%s",filename);
  12760. system("ping 8.8.8.8 &");
  12761. if((access(FilePath,F_OK))!=-1)
  12762. {
  12763. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12764. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12765. system(rmFileCmd);
  12766. }
  12767. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12768. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  12769. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  12770. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12771. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12772. systemresult = system(ftpbuf);
  12773. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12774. if(systemresult != 0)
  12775. {
  12776. printf("wget error!\n");
  12777. return FALSE;
  12778. }
  12779. system("pkill ping");
  12780. return TRUE;
  12781. }
  12782. int httpUploadFile(char *location, char *path, char *filename,char *url)
  12783. {
  12784. char rmFileCmd[100]={0};
  12785. char FilePath[100]={0};
  12786. char ftpbuf[200];
  12787. int systemresult;
  12788. //DEBUG_INFO("filename=%s\n",filename);
  12789. //DEBUG_INFO("url=%s\n",url);
  12790. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  12791. if((access(FilePath,F_OK))!=-1)
  12792. {
  12793. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12794. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12795. system(rmFileCmd);
  12796. }
  12797. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  12798. if(fp == NULL)
  12799. {
  12800. DEBUG_INFO("log is NULL\n");
  12801. return FALSE;
  12802. }
  12803. else
  12804. {
  12805. fprintf(fp, "%s\n", url);
  12806. fprintf(fp, "%s\n", filename);
  12807. fclose(fp);
  12808. }
  12809. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12810. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  12811. systemresult = system(ftpbuf);
  12812. DEBUG_INFO("systemresult = %d\n",systemresult);
  12813. if(systemresult != 0)
  12814. {
  12815. DEBUG_INFO("http upload error!\n");
  12816. return FALSE;
  12817. }
  12818. return TRUE;
  12819. }
  12820. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  12821. {
  12822. struct hostent* server;
  12823. char *IPbuffer;
  12824. char ftpbuf[200];
  12825. int systemresult;
  12826. // To retrieve host information
  12827. server = gethostbyname(location);
  12828. // To convert an Internet network
  12829. // address into ASCII string
  12830. IPbuffer = inet_ntoa(*((struct in_addr*)
  12831. server->h_addr_list[0]));
  12832. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12833. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  12834. /* format : ftpput -u username -p passwd IP target source*/
  12835. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  12836. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12837. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12838. systemresult = system(ftpbuf);
  12839. DEBUG_INFO("systemresult=%d\n",systemresult);
  12840. if(systemresult != 0)
  12841. {
  12842. DEBUG_INFO("ftpput error!\n");
  12843. return FALSE;
  12844. }
  12845. return TRUE;
  12846. }
  12847. /**
  12848. * Place the contents of the specified file into a memory buffer
  12849. *
  12850. * @param[in] filename The path and name of the file to read
  12851. * @param[out] filebuffer A pointer to the contents in memory
  12852. * @return status 0 success, 1 on failure
  12853. */
  12854. int get_file_contents(const char* filename, char** outbuffer) {
  12855. FILE* file = NULL;
  12856. long filesize;
  12857. const int blocksize = 1;
  12858. size_t readsize;
  12859. char* filebuffer;
  12860. // Open the file
  12861. file = fopen(filename, "r");
  12862. if (NULL == file)
  12863. {
  12864. printf("'%s' not opened\n", filename);
  12865. exit(EXIT_FAILURE);
  12866. }
  12867. // Determine the file size
  12868. fseek(file, 0, SEEK_END);
  12869. filesize = ftell(file);
  12870. rewind (file);
  12871. // Allocate memory for the file contents
  12872. filebuffer = (char*) malloc(sizeof(char) * filesize);
  12873. *outbuffer = filebuffer;
  12874. if (filebuffer == NULL)
  12875. {
  12876. fputs ("malloc out-of-memory", stderr);
  12877. exit(EXIT_FAILURE);
  12878. }
  12879. // Read in the file
  12880. readsize = fread(filebuffer, blocksize, filesize, file);
  12881. if (readsize != filesize)
  12882. {
  12883. fputs ("didn't read file completely",stderr);
  12884. exit(EXIT_FAILURE);
  12885. }
  12886. // Clean exit
  12887. fclose(file);
  12888. return EXIT_SUCCESS;
  12889. }
  12890. static int selectSqlCount = 0;
  12891. static int callback(void *data, int argc, char **argv, char **azColName){
  12892. int i;
  12893. //printf("%s: ", (const char*)data);
  12894. selectSqlCount = argc;
  12895. for(i = 0; i<argc; i++){
  12896. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  12897. }
  12898. //printf("\n");
  12899. return 0;
  12900. }
  12901. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  12902. //int i;
  12903. //printf("%s:\n", (const char*)data);
  12904. localversion = argv[5] ? atoi(argv[5]) : 0;
  12905. //printf("localversion=%d\n", localversion);
  12906. return 0;
  12907. }
  12908. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  12909. //printf("%s:\n", (const char*)data);
  12910. //idTag
  12911. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  12912. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  12913. //parentIdTag
  12914. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  12915. //expir_date
  12916. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  12917. //status
  12918. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  12919. //version
  12920. if(columenCount > 5)
  12921. idTagQuery.listVersionInt = atoi(columnValue[5]);
  12922. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  12923. return 0;
  12924. }
  12925. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  12926. {
  12927. // localversion = argv[5] ? atoi(argv[5]) : 0;
  12928. // printf("localversion=%d\n", localversion);
  12929. return 0;
  12930. }
  12931. //=========================================
  12932. // Sqlite3 related function
  12933. //=========================================
  12934. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  12935. {
  12936. for (int i = 0; i < n_columns; i++)
  12937. {
  12938. DEBUG_INFO("%s\t", col_values[i]);
  12939. }
  12940. DEBUG_INFO("\n");
  12941. return 0;
  12942. }
  12943. int OCPP_cleanLocalCache()
  12944. {
  12945. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  12946. char *errMsg = 0;
  12947. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  12948. if (SQLITE_OK != rc)
  12949. {
  12950. DEBUG_INFO("SQL error: %s\n",errMsg);
  12951. return FALSE;
  12952. }
  12953. return TRUE;
  12954. }
  12955. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  12956. {
  12957. int isSuccess = TRUE;
  12958. int ret = 0;
  12959. //const char* data = "Callback function called";
  12960. char sql[300];
  12961. char zErrMsg[200];
  12962. memset(sql, 0, 300);
  12963. memset(zErrMsg, 0, 200);
  12964. 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);
  12965. //* Execute SQL statement */
  12966. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  12967. if( ret != SQLITE_OK )
  12968. {
  12969. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12970. isSuccess = FALSE;
  12971. }
  12972. return isSuccess;
  12973. }
  12974. void OCPP_getIdTagFromLocalCache(char idTag[])
  12975. {
  12976. int rc = 0;
  12977. char sql[100];
  12978. char zErrMsg[100];
  12979. memset(sql, 0, 100);
  12980. memset(zErrMsg, 0, 100);
  12981. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  12982. memset(&idTagQuery, 0, sizeof(idTagQuery));
  12983. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  12984. /* Execute SQL statement */
  12985. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  12986. if( rc != SQLITE_OK )
  12987. {
  12988. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12989. }
  12990. }
  12991. void OCPP_getListVerion()
  12992. {
  12993. int rc = 0;
  12994. // const char* data = "Callback function called";
  12995. char sql[100];
  12996. char zErrMsg[100];
  12997. memset(sql, 0, 100);
  12998. memset(zErrMsg, 0, 100);
  12999. strcpy(sql, "select * from ocpp_auth_local order by idx");
  13000. /* Execute SQL statement */
  13001. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  13002. if( rc != SQLITE_OK )
  13003. {
  13004. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13005. }
  13006. }
  13007. void OCPP_get_TableAuthlocalAllData(void)
  13008. {
  13009. int rc = 0;
  13010. char sql[100];
  13011. char zErrMsg[100];
  13012. memset(sql, 0, 100);
  13013. memset(zErrMsg, 0, 100);
  13014. sprintf(sql,"select * from ocpp_auth_local ");
  13015. /* Execute SQL statement */
  13016. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  13017. if( rc != SQLITE_OK )
  13018. {
  13019. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13020. }
  13021. //return ver;
  13022. }
  13023. int OCPP_cleanLocalList()
  13024. {
  13025. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  13026. char *errMsg = 0;
  13027. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  13028. if (SQLITE_OK != rc)
  13029. {
  13030. DEBUG_INFO("%s\n",errMsg);
  13031. return FALSE;
  13032. }
  13033. return TRUE;
  13034. }
  13035. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  13036. {
  13037. int isSuccess = FALSE;
  13038. int ret = 0;
  13039. //const char* data = "Callback function called";
  13040. char sql[300];
  13041. char zErrMsg[200];
  13042. memset(sql, 0, 300);
  13043. memset(zErrMsg, 0, 200);
  13044. 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);
  13045. //* Execute SQL statement */
  13046. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  13047. if( ret != SQLITE_OK )
  13048. {
  13049. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13050. return isSuccess;
  13051. }
  13052. memset(sql, 0, 300);
  13053. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  13054. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  13055. if( ret != SQLITE_OK )
  13056. {
  13057. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13058. return isSuccess;
  13059. }
  13060. isSuccess = TRUE;
  13061. return isSuccess;
  13062. }
  13063. void OCPP_getIdTagFromLocalList(char idTag[])
  13064. {
  13065. int rc = 0;
  13066. // const char* data = "Callback function called";
  13067. char sql[100];
  13068. char zErrMsg[100];
  13069. memset(sql, 0, 100);
  13070. memset(zErrMsg, 0, 100);
  13071. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  13072. memset(&idTagQuery, 0, sizeof(idTagQuery));
  13073. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  13074. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  13075. /* Execute SQL statement */
  13076. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  13077. if( rc != SQLITE_OK )
  13078. {
  13079. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13080. }
  13081. //return ver;
  13082. }
  13083. void OCPP_deleteIdTagFromLocalList(char idTag[])
  13084. {
  13085. //int ver = 0;
  13086. //int isSuccess = FALSE;
  13087. int rc = 0;
  13088. char sql[100];
  13089. char zErrMsg[100];
  13090. memset(sql, 0, 100);
  13091. memset(zErrMsg, 0, 100);
  13092. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  13093. //* Execute SQL statement */
  13094. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  13095. if( rc != SQLITE_OK )
  13096. {
  13097. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13098. }
  13099. }
  13100. int GetOcppServerURL()
  13101. {
  13102. int result = FALSE;
  13103. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  13104. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  13105. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  13106. struct yuarel url;
  13107. char urlStr[512];
  13108. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  13109. {
  13110. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  13111. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13112. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  13113. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  13114. if(yuarel_parse(&url, urlStr) != -1)
  13115. {
  13116. sprintf(OcppProtocol, "%s", url.scheme);
  13117. sprintf(OcppHost, "%s", url.host);
  13118. if(url.path == NULL)
  13119. OcppTempPath[0] = '\0';
  13120. else
  13121. {
  13122. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  13123. {
  13124. sprintf(OcppTempPath, "%s/", url.path);
  13125. }
  13126. else
  13127. {
  13128. sprintf(OcppTempPath, "%s", url.path);
  13129. }
  13130. }
  13131. if(url.port == 0)
  13132. {
  13133. if(strcmp(OcppProtocol, "wss") == 0)
  13134. OcppPort = 443;
  13135. else
  13136. OcppPort = 80;
  13137. }
  13138. else
  13139. OcppPort = url.port;
  13140. result = TRUE;
  13141. }
  13142. }
  13143. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  13144. {
  13145. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  13146. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13147. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  13148. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  13149. if(yuarel_parse(&url, urlStr) != -1)
  13150. {
  13151. sprintf(OcppProtocol, "%s", url.scheme);
  13152. sprintf(OcppHost, "%s", url.host);
  13153. if(url.path == NULL)
  13154. OcppTempPath[0] = '\0';
  13155. else
  13156. sprintf(OcppTempPath, "%s", url.path);
  13157. if(url.port == 0)
  13158. {
  13159. if(strcmp(OcppProtocol, "wss") == 0)
  13160. OcppPort = 443;
  13161. else
  13162. OcppPort = 80;
  13163. }
  13164. else
  13165. OcppPort = url.port;
  13166. result = TRUE;
  13167. }
  13168. }
  13169. else
  13170. {
  13171. strcpy(OcppHost,"");
  13172. }
  13173. return result;
  13174. }
  13175. int GetOcppPath()
  13176. {
  13177. int result = FALSE;
  13178. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  13179. {
  13180. if(OcppTempPath == NULL)
  13181. {
  13182. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13183. }
  13184. else
  13185. {
  13186. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13187. }
  13188. result = TRUE;
  13189. goto End;
  13190. }
  13191. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  13192. {
  13193. if(OcppTempPath == NULL)
  13194. {
  13195. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  13196. }
  13197. else
  13198. {
  13199. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  13200. }
  13201. result = TRUE;
  13202. goto End;
  13203. }
  13204. else
  13205. {
  13206. strcpy(OcppPath,"");
  13207. }
  13208. End:
  13209. return result;
  13210. }
  13211. int GetOcppPort()
  13212. {
  13213. return OcppPort;
  13214. }
  13215. int GetOcppConnStatus(void)
  13216. {
  13217. return ShmOCPP16Data->OcppConnStatus;
  13218. }
  13219. void SetOcppConnStatus(uint8_t status)
  13220. {
  13221. ShmOCPP16Data->OcppConnStatus = status;
  13222. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  13223. }
  13224. int GetHeartBeatWithNOResponse(void)
  13225. {
  13226. return HeartBeatWithNOResponse;
  13227. }
  13228. void SetHeartBeatWithNOResponse(void)
  13229. {
  13230. HeartBeatWithNOResponse = 0;
  13231. }
  13232. void GetStartTransactionIdTag(int gun_index)
  13233. {
  13234. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  13235. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13236. }
  13237. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  13238. {
  13239. char ch;
  13240. FILE *fptr1;
  13241. int temptransactionId;
  13242. char str[100]={0};
  13243. temptransactionId = 0;
  13244. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  13245. {
  13246. DEBUG_INFO("IdTag is empty.\n");
  13247. return temptransactionId;
  13248. }
  13249. /*------ Read the file ----------------*/
  13250. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  13251. if (!fptr1)
  13252. {
  13253. DEBUG_INFO("QueueTransactionId file open error.\n");
  13254. //printf(" File not found or unable to open the input file!!\n");
  13255. return temptransactionId;
  13256. }
  13257. ch=fgetc(fptr1);
  13258. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  13259. rewind(fptr1);
  13260. if(ch!=EOF)
  13261. {
  13262. // printf("%c",ch);
  13263. while (fgets(str, 100, fptr1) != NULL)
  13264. {
  13265. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13266. if(str[0]=='\0')
  13267. {
  13268. break;
  13269. }
  13270. char *revbuf[8] = {0}; // Variable store string split
  13271. int num = 0;// Quantity after string split
  13272. DEBUG_INFO("Transaction queue data= %s\n", str);
  13273. splitstring(str,",",revbuf,&num); // String split
  13274. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  13275. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  13276. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  13277. DEBUG_INFO("------------------------------\n");
  13278. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  13279. {
  13280. if(isStopTransaction)
  13281. {
  13282. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  13283. {
  13284. temptransactionId = atoi(revbuf[2]);
  13285. break;
  13286. }
  13287. }
  13288. else
  13289. {
  13290. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  13291. {
  13292. temptransactionId = atoi(revbuf[2]);
  13293. break;
  13294. }
  13295. }
  13296. }
  13297. }
  13298. }
  13299. else
  13300. DEBUG_INFO("EOF\n");
  13301. fclose(fptr1);
  13302. /*------- End of reading ---------------*/
  13303. return temptransactionId;
  13304. }
  13305. void SetTransactionIdZero(int transactionId)
  13306. {
  13307. char ch;
  13308. FILE *fptr1, *fptr2;
  13309. int temptransactionId = 0;
  13310. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  13311. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  13312. if (!fptr1)
  13313. {
  13314. //printf(" File not found or unable to open the input file!!\n");
  13315. return ;
  13316. }
  13317. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13318. if (!fptr2)
  13319. {
  13320. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  13321. fclose(fptr1);
  13322. return ;
  13323. }
  13324. ch=fgetc(fptr1);
  13325. rewind(fptr1);
  13326. if(ch!=EOF)
  13327. {
  13328. // copy all contents to the temporary file except the specific line
  13329. while (fgets(str, 100, fptr1) != NULL)
  13330. {
  13331. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13332. if(str[0]=='\0')
  13333. {
  13334. break;
  13335. }
  13336. char *revbuf[8] = {0};
  13337. int num = 0;
  13338. strcpy(strtemp, str);
  13339. splitstring(str,",",revbuf,&num);
  13340. if(revbuf[2][0] != '\0')
  13341. {
  13342. temptransactionId = atoi(revbuf[2]);
  13343. if(transactionId != temptransactionId)
  13344. {
  13345. fprintf(fptr2, "%s\n", strtemp);
  13346. }
  13347. }
  13348. }
  13349. }
  13350. fclose(fptr1);
  13351. fclose(fptr2);
  13352. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13353. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13354. /*------ Read the file ----------------*/
  13355. }
  13356. int InternetDisconnect(void)
  13357. {
  13358. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13359. }
  13360. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  13361. void storeTempStopTransaction(int gun_index)
  13362. {
  13363. char guid[37]={0};
  13364. int tempIndex = 0;
  13365. char TempStopTransaction[256];
  13366. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  13367. DEBUG_INFO("storeTempStopTransaction...\n");
  13368. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  13369. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  13370. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  13371. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13372. if(gunType[gun_index] == 'J')
  13373. {
  13374. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13375. {
  13376. tempIndex = ((gun_index==2) ? 1: 0);
  13377. }
  13378. else
  13379. {
  13380. tempIndex = gun_index;
  13381. }
  13382. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13383. {
  13384. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13385. {
  13386. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  13387. }
  13388. }// END OF CHAdeMO_QUANTITY
  13389. }
  13390. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13391. {
  13392. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13393. {
  13394. tempIndex = ((gun_index==2) ? 1: 0);
  13395. }
  13396. else
  13397. {
  13398. tempIndex = gun_index;
  13399. }
  13400. for (int index = 0; index < CCS_QUANTITY; index++)
  13401. {
  13402. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13403. {
  13404. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  13405. }
  13406. }// END OF CCS_QUANTITY
  13407. }
  13408. else if(gunType[gun_index] == 'G')
  13409. {
  13410. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13411. {
  13412. tempIndex = ((gun_index==2) ? 1: 0);
  13413. }
  13414. else
  13415. {
  13416. tempIndex = gun_index;
  13417. }
  13418. for (int index = 0; index < GB_QUANTITY; index++)
  13419. {
  13420. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13421. {
  13422. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  13423. }
  13424. }// END OF GB_QUANTITY
  13425. }
  13426. else if(gunType[gun_index] == 'O')
  13427. {
  13428. tempIndex = gun_index;
  13429. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13430. {
  13431. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13432. {
  13433. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  13434. }
  13435. }
  13436. }
  13437. else
  13438. {
  13439. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13440. {
  13441. tempIndex = 2;
  13442. }
  13443. else
  13444. {
  13445. tempIndex = gun_index;
  13446. }
  13447. for (int index = 0; index < AC_QUANTITY; index++)
  13448. {
  13449. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13450. {
  13451. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  13452. }
  13453. }// END OF AC_QUANTITY
  13454. }
  13455. //Stop Transaction Time
  13456. struct timeval tmnow;
  13457. struct tm *tm;
  13458. char buf[28];//, usec_buf[6];
  13459. gettimeofday(&tmnow, NULL);
  13460. time_t t;
  13461. t = time(NULL);
  13462. /*UTC time and date*/
  13463. tm = gmtime(&t);
  13464. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  13465. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  13466. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  13467. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13468. random_uuid(guid);
  13469. /***********************************transactionData******************************************************/
  13470. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  13471. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  13472. //=================================
  13473. //1. Transaction_Begin
  13474. //=================================
  13475. //============================== Energy.Active.Import.Interval ===========================================
  13476. //idx_sample=0;
  13477. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  13478. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  13479. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  13480. 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*/]);
  13481. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13482. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13483. {
  13484. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  13485. }
  13486. else
  13487. {
  13488. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  13489. }
  13490. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  13491. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13492. //=================================
  13493. //2. Transaction_End
  13494. //=================================
  13495. //2.1====================================== Current.Import L1 ==============================================
  13496. //idx_sample=1;
  13497. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  13498. if(gunType[gun_index] == 'J')
  13499. {
  13500. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13501. {
  13502. tempIndex = ((gun_index==2) ? 1: 0);
  13503. }
  13504. else
  13505. {
  13506. tempIndex = gun_index;
  13507. }
  13508. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13509. {
  13510. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13511. {
  13512. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13513. }
  13514. }// End of for CHAdeMO_QUANTITY
  13515. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13516. }
  13517. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13518. {
  13519. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13520. {
  13521. tempIndex = ((gun_index==2) ? 1: 0);
  13522. }
  13523. else
  13524. {
  13525. tempIndex = gun_index;
  13526. }
  13527. for (int index = 0; index < CCS_QUANTITY; index++)
  13528. {
  13529. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13530. {
  13531. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13532. }
  13533. }// End of for CCS_QUANTITY
  13534. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13535. }
  13536. else if(gunType[gun_index] == 'G')
  13537. {
  13538. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13539. {
  13540. tempIndex = ((gun_index==2) ? 1: 0);
  13541. }
  13542. else
  13543. {
  13544. tempIndex = gun_index;
  13545. }
  13546. for (int index = 0; index < GB_QUANTITY; index++)
  13547. {
  13548. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13549. {
  13550. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13551. }
  13552. }// End of for GB_QUANTITY
  13553. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13554. }
  13555. else if(gunType[gun_index] == 'O')
  13556. {
  13557. tempIndex = gun_index;
  13558. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13559. {
  13560. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13561. {
  13562. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13563. }
  13564. }
  13565. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13566. }
  13567. else
  13568. {
  13569. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13570. {
  13571. tempIndex = 2;
  13572. }
  13573. else
  13574. {
  13575. tempIndex = gun_index;
  13576. }
  13577. for (int index = 0; index < AC_QUANTITY; index++)
  13578. {
  13579. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13580. {
  13581. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  13582. }
  13583. }// End of for AC_QUANTITY
  13584. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13585. }
  13586. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13587. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  13588. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  13589. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13590. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  13591. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13592. //2.2===================================== Energy.Active.Import.Interval ==========================================
  13593. //idx_sample=2;
  13594. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13595. if(gunType[gun_index] == 'J')
  13596. {
  13597. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13598. {
  13599. tempIndex = ((gun_index==2) ? 1: 0);
  13600. }
  13601. else
  13602. {
  13603. tempIndex = gun_index;
  13604. }
  13605. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13606. {
  13607. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13608. {
  13609. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13610. }
  13611. }// END OF CHAdeMO_QUANTITY
  13612. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13613. }
  13614. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13615. {
  13616. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13617. {
  13618. tempIndex = ((gun_index==2) ? 1: 0);
  13619. }
  13620. else
  13621. {
  13622. tempIndex = gun_index;
  13623. }
  13624. for (int index = 0; index < CCS_QUANTITY; index++)
  13625. {
  13626. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13627. {
  13628. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13629. }
  13630. }// END OF CCS_QUANTITY
  13631. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13632. }
  13633. else if(gunType[gun_index] == 'G')
  13634. {
  13635. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13636. {
  13637. tempIndex = ((gun_index==2) ? 1: 0);
  13638. }
  13639. else
  13640. {
  13641. tempIndex = gun_index;
  13642. }
  13643. for (int index = 0; index < GB_QUANTITY; index++)
  13644. {
  13645. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13646. {
  13647. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13648. }
  13649. }// END OF GB_QUANTITY
  13650. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13651. }
  13652. else if(gunType[gun_index] == 'O')
  13653. {
  13654. tempIndex = gun_index;
  13655. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13656. {
  13657. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13658. {
  13659. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13660. }
  13661. }
  13662. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13663. }
  13664. else
  13665. {
  13666. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13667. {
  13668. tempIndex = 2;
  13669. }
  13670. else
  13671. {
  13672. tempIndex = gun_index;
  13673. }
  13674. for (int index = 0; index < AC_QUANTITY; index++)
  13675. {
  13676. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13677. {
  13678. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13679. }
  13680. }// END OF AC_QUANTITY
  13681. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13682. }
  13683. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13684. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  13685. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  13686. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13687. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  13688. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13689. //2.3====================================== Power.Active.Import =========================================
  13690. //idx_sample=3;
  13691. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13692. if(gunType[gun_index] == 'J')
  13693. {
  13694. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13695. {
  13696. tempIndex = ((gun_index==2) ? 1: 0);
  13697. }
  13698. else
  13699. {
  13700. tempIndex = gun_index;
  13701. }
  13702. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13703. {
  13704. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13705. {
  13706. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13707. }
  13708. } // End for CHAdeMO_QUANTITY
  13709. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13710. }
  13711. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13712. {
  13713. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13714. {
  13715. tempIndex = ((gun_index==2) ? 1: 0);
  13716. }
  13717. else
  13718. {
  13719. tempIndex = gun_index;
  13720. }
  13721. for (int index = 0; index < CCS_QUANTITY; index++)
  13722. {
  13723. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13724. {
  13725. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13726. }
  13727. } // END for CCS_QUANTITY
  13728. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13729. }
  13730. else if(gunType[gun_index] == 'G')
  13731. {
  13732. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13733. {
  13734. tempIndex = ((gun_index==2) ? 1: 0);
  13735. }
  13736. else
  13737. {
  13738. tempIndex = gun_index;
  13739. }
  13740. for (int index = 0; index < GB_QUANTITY; index++)
  13741. {
  13742. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13743. {
  13744. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13745. }
  13746. }// END for GB_QUANTITY
  13747. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13748. }
  13749. else if(gunType[gun_index] == 'O')
  13750. {
  13751. tempIndex = gun_index;
  13752. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13753. {
  13754. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13755. {
  13756. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13757. }
  13758. }
  13759. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13760. }
  13761. else
  13762. {
  13763. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13764. {
  13765. tempIndex = 2;
  13766. }
  13767. else
  13768. {
  13769. tempIndex = gun_index;
  13770. }
  13771. for (int index = 0; index < AC_QUANTITY; index++)
  13772. {
  13773. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13774. {
  13775. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13776. }
  13777. } // END for AC_QUANTITY
  13778. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13779. }
  13780. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13781. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  13782. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  13783. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13784. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  13785. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  13786. //2.4====================================== Voltage L1 ====================================================
  13787. //idx_sample=4;
  13788. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13789. if(gunType[gun_index] == 'J')
  13790. {
  13791. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13792. {
  13793. tempIndex = ((gun_index==2) ? 1: 0);
  13794. }
  13795. else
  13796. {
  13797. tempIndex = gun_index;
  13798. }
  13799. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13800. {
  13801. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13802. {
  13803. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13804. }
  13805. } // END OF FOR CHAdeMO_QUANTITY
  13806. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13807. }
  13808. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13809. {
  13810. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13811. {
  13812. tempIndex = ((gun_index==2) ? 1: 0);
  13813. }
  13814. else
  13815. {
  13816. tempIndex = gun_index;
  13817. }
  13818. for (int index = 0; index < CCS_QUANTITY; index++)
  13819. {
  13820. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13821. {
  13822. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13823. }
  13824. } // END OF FOR CCS_QUANTITY
  13825. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13826. }
  13827. else if(gunType[gun_index] == 'G')
  13828. {
  13829. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13830. {
  13831. tempIndex = ((gun_index==2) ? 1: 0);
  13832. }
  13833. else
  13834. {
  13835. tempIndex = gun_index;
  13836. }
  13837. for (int index = 0; index < GB_QUANTITY; index++)
  13838. {
  13839. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13840. {
  13841. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13842. }
  13843. } // END OF FOR GB_QUANTITY
  13844. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13845. }
  13846. else if(gunType[gun_index] == 'O')
  13847. {
  13848. tempIndex = gun_index;
  13849. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13850. {
  13851. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13852. {
  13853. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13854. }
  13855. }
  13856. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13857. }
  13858. else
  13859. {
  13860. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13861. {
  13862. tempIndex = 2;
  13863. }
  13864. else
  13865. {
  13866. tempIndex = gun_index;
  13867. }
  13868. for (int index = 0; index < AC_QUANTITY; index++)
  13869. {
  13870. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13871. {
  13872. 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
  13873. }
  13874. } // END OF FOR AC_QUANTITY
  13875. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13876. }
  13877. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13878. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  13879. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  13880. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13881. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  13882. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13883. //2.5============================================== End SoC =========================================================
  13884. //idx_sample=5;
  13885. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13886. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  13887. {
  13888. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != 'O'))
  13889. {
  13890. tempIndex = ((gun_index==2) ? 1: 0);
  13891. }
  13892. else
  13893. {
  13894. tempIndex = gun_index;
  13895. }
  13896. if(gunType[gun_index] == 'J')
  13897. {
  13898. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13899. {
  13900. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13901. {
  13902. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  13903. }
  13904. }
  13905. }
  13906. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13907. {
  13908. for (int index = 0; index < CCS_QUANTITY; index++)
  13909. {
  13910. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13911. {
  13912. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  13913. }
  13914. }
  13915. }
  13916. else if(gunType[gun_index] == 'G')
  13917. {
  13918. for (int index = 0; index < GB_QUANTITY; index++)
  13919. {
  13920. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13921. {
  13922. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  13923. }
  13924. }
  13925. }
  13926. else if(gunType[gun_index] == 'O')
  13927. {
  13928. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13929. {
  13930. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13931. {
  13932. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  13933. }
  13934. }
  13935. }
  13936. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13937. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  13938. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  13939. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  13940. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  13941. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  13942. } // END FOR DC CASE
  13943. //2.6====================================== Current.Import L2 ==============================================
  13944. // idx_sample=6;
  13945. // AC 3 phase L2 current
  13946. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13947. {
  13948. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13949. {
  13950. tempIndex = 2;
  13951. }
  13952. else
  13953. {
  13954. tempIndex = gun_index;
  13955. }
  13956. for (int index = 0; index < AC_QUANTITY; index++)
  13957. {
  13958. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13959. {
  13960. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  13961. }
  13962. }// End of for AC_QUANTITY
  13963. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  13964. }
  13965. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13966. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  13967. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  13968. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  13969. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13970. //2.7====================================== Current.Import L3 ==============================================
  13971. // idx_sample=7;
  13972. // AC 3 phase L3 current
  13973. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13974. {
  13975. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13976. {
  13977. tempIndex = 2;
  13978. }
  13979. else
  13980. {
  13981. tempIndex = gun_index;
  13982. }
  13983. for (int index = 0; index < AC_QUANTITY; index++)
  13984. {
  13985. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13986. {
  13987. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  13988. }
  13989. }// End of for AC_QUANTITY
  13990. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  13991. }
  13992. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13993. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  13994. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  13995. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  13996. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13997. //2.9====================================== Voltage L2 ====================================================
  13998. //idx_sample=8;
  13999. // AC 3 phase L2 volatge
  14000. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  14001. {
  14002. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14003. {
  14004. tempIndex = 2;
  14005. }
  14006. else
  14007. {
  14008. tempIndex = gun_index;
  14009. }
  14010. for (int index = 0; index < AC_QUANTITY; index++)
  14011. {
  14012. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14013. {
  14014. 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
  14015. }
  14016. } // END OF FOR AC_QUANTITY
  14017. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  14018. }
  14019. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14020. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  14021. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  14022. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  14023. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  14024. //2.10====================================== Voltage L3 ====================================================
  14025. //idx_sample=9;
  14026. // AC 3 phase L3 volatge
  14027. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  14028. {
  14029. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14030. {
  14031. tempIndex = 2;
  14032. }
  14033. else
  14034. {
  14035. tempIndex = gun_index;
  14036. }
  14037. for (int index = 0; index < AC_QUANTITY; index++)
  14038. {
  14039. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14040. {
  14041. 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
  14042. }
  14043. } // END OF FOR AC_QUANTITY
  14044. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  14045. }
  14046. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14047. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  14048. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  14049. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  14050. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  14051. //====================== Start SoC ================================
  14052. //idx_sample=10;
  14053. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14054. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  14055. {
  14056. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != 'O'))
  14057. {
  14058. tempIndex = ((gun_index==2) ? 1: 0);
  14059. }
  14060. else
  14061. {
  14062. tempIndex = gun_index;
  14063. }
  14064. if(gunType[gun_index] == 'J')
  14065. {
  14066. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14067. {
  14068. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14069. {
  14070. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  14071. }
  14072. }
  14073. }
  14074. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  14075. {
  14076. for (int index = 0; index < CCS_QUANTITY; index++)
  14077. {
  14078. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14079. {
  14080. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  14081. }
  14082. }
  14083. }
  14084. else if(gunType[gun_index] == 'G')
  14085. {
  14086. for (int index = 0; index < GB_QUANTITY; index++)
  14087. {
  14088. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14089. {
  14090. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  14091. }
  14092. }
  14093. }
  14094. else if(gunType[gun_index] == 'O')
  14095. {
  14096. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14097. {
  14098. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14099. {
  14100. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  14101. }
  14102. }
  14103. }
  14104. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  14105. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  14106. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  14107. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  14108. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  14109. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  14110. } // END FOR DC CASE
  14111. //======================================== Message create ==============================================
  14112. json_object *StopTransaction = json_object_new_object();
  14113. json_object *transactionDatas = json_object_new_array();
  14114. json_object *sampledValues = json_object_new_array();
  14115. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  14116. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  14117. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  14118. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  14119. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  14120. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  14121. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  14122. {
  14123. json_object *transactionData = json_object_new_object();
  14124. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  14125. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  14126. {
  14127. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  14128. {
  14129. json_object *sampledValue = json_object_new_object();
  14130. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  14131. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  14132. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  14133. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  14134. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  14135. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  14136. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  14137. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  14138. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  14139. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  14140. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  14141. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  14142. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  14143. json_object_array_add(sampledValues, sampledValue);
  14144. }
  14145. }
  14146. json_object_object_add(transactionData, "sampledValue", sampledValues);
  14147. json_object_array_add(transactionDatas, transactionData);
  14148. }
  14149. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  14150. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  14151. ,MESSAGE_TYPE_CALL
  14152. ,guid
  14153. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  14154. json_object_put(StopTransaction);
  14155. // Check File "TempStopTransaction" Exist
  14156. if((access(TempStopTransaction,F_OK))!=-1)
  14157. {
  14158. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  14159. fclose(fopen(TempStopTransaction, "w"));
  14160. }
  14161. else
  14162. {
  14163. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  14164. FILE *log = fopen(TempStopTransaction, "w+");
  14165. if(log == NULL)
  14166. {
  14167. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  14168. return ;
  14169. }
  14170. else
  14171. {
  14172. fclose(log);
  14173. }
  14174. }
  14175. //Add TempStopTransaction | Update TempStopTransaction
  14176. // open file for writing
  14177. FILE *outfile;
  14178. outfile = fopen (TempStopTransaction, "a");
  14179. //DEBUG_INFO("data = %s\n", queuedata);
  14180. fputs(queuedata, outfile);
  14181. fputs("\n", outfile);
  14182. fclose (outfile);
  14183. }
  14184. void checkTempStopTransaction(int gun_index)
  14185. {
  14186. FILE *fptr1;
  14187. char ch;
  14188. char str[QUEUE_MESSAGE_LENGTH]={0};
  14189. char guid[37]={0};
  14190. char tempdata[65]={0};
  14191. char connectorStr[2]={0};
  14192. char TempStopTransaction[256];
  14193. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  14194. fptr1 = fopen(TempStopTransaction, "r");
  14195. //TempStopTransaction格式: 槍號,StopTransaction封包
  14196. if (!fptr1)
  14197. {
  14198. //printf(" File not found or unable to open the input file!!\n");
  14199. return ;
  14200. }
  14201. ch=fgetc(fptr1);
  14202. //printf(" Now the content of the file %s is : \n",fname);
  14203. rewind(fptr1);
  14204. if(ch!=EOF)
  14205. {
  14206. // copy all contents to the temporary file except the specific line
  14207. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  14208. {
  14209. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14210. if(str[0]=='\0')
  14211. {
  14212. break;
  14213. }
  14214. //TempStopTransaction格式: 槍號,StopTransaction封包
  14215. strncpy(connectorStr, str, 1);
  14216. if(atoi(connectorStr) != (gun_index+1))
  14217. {
  14218. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  14219. fclose(fptr1);
  14220. return ;
  14221. }
  14222. //random_uuid(guid);
  14223. strncpy(guid, str+6, 36); //copy guid
  14224. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  14225. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  14226. {
  14227. //DEBUG_INFO("StopTransaction mapitem pass\n");
  14228. }
  14229. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  14230. memset(str,0,ARRAY_SIZE(str));
  14231. }
  14232. }
  14233. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  14234. fclose(fptr1);
  14235. remove(TempStopTransaction); // remove the original file
  14236. }
  14237. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  14238. {
  14239. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  14240. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  14241. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  14242. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  14243. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  14244. }
  14245. int GetWebSocketPingInterval(void)
  14246. {
  14247. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14248. }
  14249. int GetServerSign(void)
  14250. {
  14251. return server_sign;
  14252. }
  14253. uint8_t GetOcppSecurityProfile()
  14254. {
  14255. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14256. }
  14257. void GetOcppChargerBoxId(uint8_t *data)
  14258. {
  14259. sprintf((char*)data, "%s", ShmOCPP16Data->ChargeBoxId);
  14260. }
  14261. void GetOcppSecurityPassword(uint8_t *data)
  14262. {
  14263. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14264. }
  14265. void SetOcppVersion(uint8_t *version)
  14266. {
  14267. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  14268. DEBUG_INFO("ocpp version: %s\n", version);
  14269. if(strstr((char*)version, "ocpp1.6") != NULL)
  14270. {
  14271. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  14272. }
  14273. else if(strstr((char*)version, "ocpp2.0") != NULL)
  14274. {
  14275. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  14276. system("pkill OcppBackend");
  14277. }
  14278. }
  14279. void SetServerSign(int value)
  14280. {
  14281. server_sign = value;
  14282. }
  14283. int GetBootNotificationInterval(void)
  14284. {
  14285. return BootNotificationInterval;
  14286. }
  14287. int GetInternetConn(void)
  14288. {
  14289. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  14290. }
  14291. void InitialSystemValue(void)
  14292. {
  14293. int connectorIndex = 0;
  14294. //int valueASCII = 0;
  14295. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14296. gunTotalNumber=0;
  14297. SystemInitial = 0;
  14298. localversion=0;
  14299. BootNotificationInterval = 0;
  14300. authorizeRetryTimes = 0;
  14301. GunStatusInterval = 10;
  14302. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14303. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14304. //Hear Beat
  14305. HeartBeatWithNOResponse = 0;
  14306. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  14307. FirstHeartBeat = 0;
  14308. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  14309. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  14310. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  14311. memset(statusModeChage, 0, ARRAY_SIZE(statusModeChage));
  14312. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  14313. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  14314. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  14315. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  14316. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  14317. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  14318. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  14319. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  14320. memset(gunType, 0, ARRAY_SIZE(gunType));
  14321. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14322. {
  14323. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O')
  14324. {
  14325. // DO series
  14326. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  14327. {
  14328. SystemInitial = SystemInitial + 1;
  14329. gunTotalNumber = gunTotalNumber + 1;
  14330. gunType[connectorIndex] = 'O';
  14331. connectorIndex = connectorIndex + 1;
  14332. }
  14333. }
  14334. else
  14335. {
  14336. // DM, DW, DS series
  14337. //check connector / socket type (index: 8, 9, 10)
  14338. for(int index=7; index <10 ; index++)
  14339. {
  14340. if(index != 8)
  14341. {
  14342. // DC Connector
  14343. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] >= 'A') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= 'Z'))
  14344. {
  14345. SystemInitial = SystemInitial + 1;
  14346. gunTotalNumber = gunTotalNumber + 1;
  14347. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14348. connectorIndex = connectorIndex + 1;
  14349. }
  14350. }
  14351. else
  14352. {
  14353. // AC Connector
  14354. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14355. {
  14356. SystemInitial = SystemInitial + 1;
  14357. gunTotalNumber = gunTotalNumber + 1;
  14358. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14359. connectorIndex = connectorIndex + 1;
  14360. }
  14361. }
  14362. }
  14363. }
  14364. //DEBUG_INFO("DC ...\n");
  14365. }
  14366. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  14367. {
  14368. //check connector / socket type (index: 8, 9, 10)
  14369. for(int index=7; index <10 ; index++)
  14370. {
  14371. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14372. {
  14373. SystemInitial = SystemInitial + 1;
  14374. gunTotalNumber = gunTotalNumber + 1;
  14375. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14376. connectorIndex = connectorIndex + 1;
  14377. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  14378. }
  14379. }
  14380. }
  14381. //Status && ConnectorPlugIn Setting
  14382. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14383. {
  14384. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  14385. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  14386. }
  14387. for (int index = 0; index < CCS_QUANTITY; index++)
  14388. {
  14389. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  14390. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  14391. }
  14392. for (int index = 0; index < GB_QUANTITY; index++)
  14393. {
  14394. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  14395. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  14396. }
  14397. for (int index = 0; index < AC_QUANTITY; index++)
  14398. {
  14399. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  14400. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  14401. }
  14402. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14403. {
  14404. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  14405. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  14406. }
  14407. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  14408. {
  14409. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  14410. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  14411. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  14412. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  14413. }
  14414. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  14415. clientTime.Heartbeat=time((time_t*)NULL);
  14416. sleep(1);
  14417. }
  14418. void LWS_Send(char * str)
  14419. {
  14420. //=====================================================
  14421. // Check InternetConn 0: disconnected, 1: connected
  14422. //====================================================
  14423. if(GetOcppConnStatus() == 0)
  14424. {
  14425. DEBUG_INFO("offline now !!!\n");
  14426. return;
  14427. }
  14428. pthread_mutex_lock(&lock_send);
  14429. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14430. sprintf((char *)SendBuffer, "%s", str);
  14431. SendBufLen = strlen(str);
  14432. pthread_mutex_unlock(&lock_send);
  14433. lws_callback_on_writable(wsi_client);
  14434. //lws_service(context, 0);
  14435. //sleep(1);
  14436. }
  14437. void LWS_SendNow(char * str)
  14438. {
  14439. //=====================================================
  14440. // Check InternetConn 0: disconnected, 1: connected
  14441. //====================================================
  14442. if(GetOcppConnStatus() == 0)
  14443. {
  14444. DEBUG_INFO("offline now !!!\n");
  14445. return;
  14446. }
  14447. pthread_mutex_lock(&lock_send);
  14448. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14449. sprintf((char *)SendBuffer, "%s", str);
  14450. SendBufLen = strlen(str);
  14451. pthread_mutex_unlock(&lock_send);
  14452. lws_callback_on_writable(wsi_client);
  14453. lws_service(context, 0);
  14454. //sleep(1);
  14455. }