MessageHandler.c 687 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532
  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. //==========================================
  388. // GetCompositeSchedule logic related function
  389. //==========================================
  390. int DiffTimebSec(struct timeb ST, struct timeb ET)
  391. {
  392. //return milli-second
  393. unsigned int StartTime,StopTime;
  394. StartTime=(unsigned int)ST.time;
  395. StopTime=(unsigned int)ET.time;
  396. return (StopTime-StartTime);
  397. }
  398. int DiffTimebWithNowSec(struct timeb ST)
  399. {
  400. //return milli-second
  401. struct timeb ET;
  402. unsigned int StartTime,StopTime;
  403. ftime(&ET);
  404. StartTime=(unsigned int)ST.time;
  405. StopTime=(unsigned int)ET.time;
  406. return (StopTime-StartTime);
  407. }
  408. int getStartStop(uint8_t *start, uint8_t *stop)
  409. {
  410. int result = -1;
  411. struct tm tmStart;
  412. struct timeb tbStart;
  413. struct tm tmStop;
  414. struct timeb tbStop;
  415. 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) &&
  416. (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))
  417. {
  418. //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);
  419. //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);
  420. tmStart.tm_year -= 1900;
  421. tmStart.tm_mon -= 1;
  422. tbStart.time = mktime(&tmStart);
  423. tbStart.millitm = 0;
  424. tmStop.tm_year -= 1900;
  425. tmStop.tm_mon -= 1;
  426. tbStop.time = mktime(&tmStop);
  427. tbStop.millitm = 0;
  428. result = DiffTimebSec(tbStart, tbStop);
  429. //DEBUG_INFO("getStartStop(): %d\n", result);
  430. }
  431. else
  432. {
  433. DEBUG_WARN("Start or stop date parsing error.\r\n");
  434. }
  435. return result;
  436. }
  437. int isOvertNow(uint8_t *start)
  438. {
  439. int result = YES;
  440. struct tm tmStart;
  441. struct timeb tbStart;
  442. 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))
  443. {
  444. //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);
  445. tmStart.tm_year -= 1900;
  446. tmStart.tm_mon -= 1;
  447. tbStart.time = mktime(&tmStart);
  448. tbStart.millitm = 0;
  449. if(DiffTimebWithNowSec(tbStart) <= 0)
  450. result = NO;
  451. }
  452. else
  453. {
  454. DEBUG_WARN("Start date parsing error.\r\n");
  455. }
  456. return result;
  457. }
  458. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  459. {
  460. int result = -1;
  461. struct tm tmStart;
  462. struct timeb tbStart;
  463. struct tm tmStop;
  464. struct timeb tbStop;
  465. 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) &&
  466. (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))
  467. {
  468. tmStart.tm_year -= 1900;
  469. tmStart.tm_mon -= 1;
  470. tbStart.time = mktime(&tmStart);
  471. tbStart.millitm = 0;
  472. tmStop.tm_year -= 1900;
  473. tmStop.tm_mon -= 1;
  474. tbStop.time = mktime(&tmStop);
  475. tbStop.millitm = 0;
  476. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  477. }
  478. return result;
  479. }
  480. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile)
  481. {
  482. FILE *fp;
  483. char profileFileName[128];
  484. char *line = NULL;
  485. size_t len = 0;
  486. time_t CurrentTime;
  487. struct tm *tmComposite;
  488. struct StructChargingProfile maxProfile;
  489. struct StructChargingProfile defaultTxProfile;
  490. struct StructChargingProfile txProfile;
  491. struct StructChargingSchedulePeriod tmpPeriod;
  492. uint8_t limitMax=0;
  493. uint8_t limitDef=0;
  494. uint8_t limitTx=0;
  495. int compositePeriodIdx = 0;
  496. CurrentTime = time(NULL);
  497. tmComposite=localtime(&CurrentTime);
  498. 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);
  499. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  500. compositeProfile->ChargingSchedule.Duration = durationReq;
  501. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  502. {
  503. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  504. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  505. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  506. }
  507. compositeProfile->ChargingProfileId = 0;
  508. compositeProfile->StackLevel = 99 ;
  509. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  510. maxProfile.ChargingProfileId = -1;
  511. defaultTxProfile.ChargingProfileId = -1;
  512. txProfile.ChargingProfileId = -1;
  513. maxProfile.ChargingSchedule.Duration = -1;
  514. defaultTxProfile.ChargingSchedule.Duration = -1;
  515. txProfile.ChargingSchedule.Duration = -1;
  516. system("yes|rm /tmp/*.json");
  517. system("cp /Storage/OCPP/*.json /tmp");
  518. /*
  519. * Search valid charging profile
  520. */
  521. //DEBUG_INFO("====================================\n");
  522. // Search tx profile
  523. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  524. if((access(profileFileName, F_OK))!=-1)
  525. {
  526. fp = fopen(profileFileName, "r");
  527. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  528. {
  529. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  530. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  531. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  532. }
  533. txProfile.ChargingProfileId = -1;
  534. txProfile.StackLevel = -1;
  535. while(getline(&line, &len, fp) != -1)
  536. {
  537. json_object *obj = NULL;
  538. obj = json_tokener_parse(line);
  539. if(is_error(obj))
  540. {
  541. DEBUG_ERROR("Parse txProfile from file error.\n");
  542. }
  543. else
  544. {
  545. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  546. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  547. )
  548. {
  549. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  550. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  551. )
  552. {
  553. struct tm tmFrom, tmTo;
  554. struct timeb tbFrom, tbTo;
  555. 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) &&
  556. (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))
  557. {
  558. tmFrom.tm_year -= 1900;
  559. tmFrom.tm_mon -= 1;
  560. tbFrom.time = mktime(&tmFrom);
  561. tmTo.tm_year -= 1900;
  562. tmTo.tm_mon -= 1;
  563. tbTo.time = mktime(&tmTo);
  564. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  565. {
  566. if(txProfile.ChargingProfileId == -1)
  567. DEBUG_INFO("TxProfile found.\n");
  568. else
  569. DEBUG_INFO("TxProfile updated.\n");
  570. // Required item
  571. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  572. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  573. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  574. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  575. 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++)
  576. {
  577. 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"));
  578. 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")));
  579. 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?
  580. 3:
  581. 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")));
  582. }
  583. // Optional item
  584. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  585. {
  586. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  587. }
  588. else
  589. {
  590. sprintf((char*)txProfile.ValidFrom, " ");
  591. }
  592. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  593. {
  594. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  595. }
  596. else
  597. {
  598. sprintf((char*)txProfile.ValidTo, " ");
  599. }
  600. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  601. {
  602. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  603. }
  604. else
  605. {
  606. sprintf((char*)txProfile.RecurrencyKind, " ");
  607. }
  608. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  609. {
  610. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  611. }
  612. else
  613. {
  614. txProfile.TransactionId = -1;
  615. }
  616. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  617. {
  618. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  619. }
  620. else
  621. {
  622. txProfile.ChargingSchedule.Duration = 86400;
  623. }
  624. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  625. {
  626. 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")));
  627. }
  628. else
  629. {
  630. 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));
  631. }
  632. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  633. {
  634. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  635. }
  636. else
  637. {
  638. txProfile.ChargingSchedule.MinChargingRate = -1;
  639. }
  640. }
  641. }
  642. }
  643. else
  644. {
  645. if(txProfile.ChargingProfileId == -1)
  646. DEBUG_INFO("TxProfile found.\n");
  647. else
  648. DEBUG_INFO("TxProfile updated.\n");
  649. // Required item
  650. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  651. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  652. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  653. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  654. 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++)
  655. {
  656. 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"));
  657. 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")));
  658. 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?
  659. 3:
  660. 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")));
  661. }
  662. // Optional item
  663. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  664. {
  665. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  666. }
  667. else
  668. {
  669. sprintf((char*)txProfile.ValidFrom, " ");
  670. }
  671. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  672. {
  673. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  674. }
  675. else
  676. {
  677. sprintf((char*)txProfile.ValidTo, " ");
  678. }
  679. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  680. {
  681. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  682. }
  683. else
  684. {
  685. sprintf((char*)txProfile.RecurrencyKind, " ");
  686. }
  687. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  688. {
  689. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  690. }
  691. else
  692. {
  693. txProfile.TransactionId = -1;
  694. }
  695. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  696. {
  697. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  698. }
  699. else
  700. {
  701. txProfile.ChargingSchedule.Duration = 86400;
  702. }
  703. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  704. {
  705. 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")));
  706. }
  707. else
  708. {
  709. 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));
  710. }
  711. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  712. {
  713. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  714. }
  715. else
  716. {
  717. txProfile.ChargingSchedule.MinChargingRate = -1;
  718. }
  719. }
  720. }
  721. }
  722. json_object_put(obj);
  723. }
  724. fclose(fp);
  725. /*
  726. if(txProfile.ChargingProfileId != -1)
  727. {
  728. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  729. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  730. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  731. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  732. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  733. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  734. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  735. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  736. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  737. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  738. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  739. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  740. {
  741. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  742. {
  743. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  744. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  745. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  746. }
  747. }
  748. }
  749. else
  750. DEBUG_INFO("TxProfile not found.\n");*/
  751. }
  752. // Search default tx profile
  753. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  754. if((access(profileFileName, F_OK))==-1)
  755. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  756. if((access(profileFileName, F_OK))!=-1)
  757. {
  758. fp = fopen(profileFileName, "r");
  759. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  760. {
  761. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  762. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  763. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  764. }
  765. defaultTxProfile.ChargingProfileId = -1;
  766. defaultTxProfile.StackLevel = -1;
  767. while(getline(&line, &len, fp) != -1)
  768. {
  769. json_object *obj = NULL;
  770. obj = json_tokener_parse(line);
  771. if(is_error(obj))
  772. {
  773. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  774. }
  775. else
  776. {
  777. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  778. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  779. )
  780. {
  781. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  782. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  783. )
  784. {
  785. struct tm tmFrom, tmTo;
  786. struct timeb tbFrom, tbTo;
  787. 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) &&
  788. (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))
  789. {
  790. tmFrom.tm_year -= 1900;
  791. tmFrom.tm_mon -= 1;
  792. tbFrom.time = mktime(&tmFrom);
  793. tmTo.tm_year -= 1900;
  794. tmTo.tm_mon -= 1;
  795. tbTo.time = mktime(&tmTo);
  796. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  797. {
  798. if(defaultTxProfile.ChargingProfileId == -1)
  799. DEBUG_INFO("TxDefaultProfile found.\n");
  800. else
  801. DEBUG_INFO("TxDefaultProfile updated.\n");
  802. // Required item
  803. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  804. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  805. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  806. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  807. 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++)
  808. {
  809. 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"));
  810. 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")));
  811. 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?
  812. 3:
  813. 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")));
  814. }
  815. // Optional item
  816. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  817. {
  818. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  819. }
  820. else
  821. {
  822. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  823. }
  824. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  825. {
  826. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  827. }
  828. else
  829. {
  830. sprintf((char*)defaultTxProfile.ValidTo, " ");
  831. }
  832. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  833. {
  834. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  835. }
  836. else
  837. {
  838. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  839. }
  840. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  841. {
  842. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  843. }
  844. else
  845. {
  846. defaultTxProfile.TransactionId = -1;
  847. }
  848. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  849. {
  850. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  851. }
  852. else
  853. {
  854. defaultTxProfile.ChargingSchedule.Duration = 86400;
  855. }
  856. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  857. {
  858. 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")));
  859. }
  860. else
  861. {
  862. 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));
  863. }
  864. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  865. {
  866. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  867. }
  868. else
  869. {
  870. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  871. }
  872. }
  873. }
  874. }
  875. else
  876. {
  877. if(defaultTxProfile.ChargingProfileId == -1)
  878. DEBUG_INFO("TxDefaultProfile found.\n");
  879. else
  880. DEBUG_INFO("TxDefaultProfile updated.\n");
  881. // Required item
  882. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  883. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  884. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  885. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  886. 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++)
  887. {
  888. 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"));
  889. 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")));
  890. 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?
  891. 3:
  892. 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")));
  893. }
  894. // Optional item
  895. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  896. {
  897. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  898. }
  899. else
  900. {
  901. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  902. }
  903. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  904. {
  905. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  906. }
  907. else
  908. {
  909. sprintf((char*)defaultTxProfile.ValidTo, " ");
  910. }
  911. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  912. {
  913. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  914. }
  915. else
  916. {
  917. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  918. }
  919. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  920. {
  921. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  922. }
  923. else
  924. {
  925. defaultTxProfile.TransactionId = -1;
  926. }
  927. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  928. {
  929. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  930. }
  931. else
  932. {
  933. defaultTxProfile.ChargingSchedule.Duration = 86400;
  934. }
  935. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  936. {
  937. 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")));
  938. }
  939. else
  940. {
  941. 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));
  942. }
  943. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  944. {
  945. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  946. }
  947. else
  948. {
  949. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  950. }
  951. }
  952. }
  953. }
  954. json_object_put(obj);
  955. }
  956. fclose(fp);
  957. /*
  958. if(defaultTxProfile.ChargingProfileId != -1)
  959. {
  960. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  961. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  962. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  963. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  964. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  965. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  966. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  967. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  968. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  969. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  970. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  971. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  972. {
  973. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  974. {
  975. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  976. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  977. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  978. }
  979. }
  980. }
  981. else
  982. DEBUG_INFO("TxDefaultProfile not found.\n");
  983. DEBUG_INFO("------------------------------------\n");*/
  984. }
  985. // Search max profile
  986. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  987. if((access(profileFileName, F_OK))!=-1)
  988. {
  989. fp = fopen(profileFileName, "r");
  990. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  991. {
  992. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  993. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  994. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  995. }
  996. maxProfile.ChargingProfileId = -1;
  997. maxProfile.StackLevel = -1;
  998. while(getline(&line, &len, fp) != -1)
  999. {
  1000. json_object *obj = NULL;
  1001. obj = json_tokener_parse(line);
  1002. if(is_error(obj))
  1003. {
  1004. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1005. }
  1006. else
  1007. {
  1008. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  1009. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1010. )
  1011. {
  1012. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1013. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1014. )
  1015. {
  1016. struct tm tmFrom, tmTo;
  1017. struct timeb tbFrom, tbTo;
  1018. 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) &&
  1019. (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))
  1020. {
  1021. tmFrom.tm_year -= 1900;
  1022. tmFrom.tm_mon -= 1;
  1023. tbFrom.time = mktime(&tmFrom);
  1024. tmTo.tm_year -= 1900;
  1025. tmTo.tm_mon -= 1;
  1026. tbTo.time = mktime(&tmTo);
  1027. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1028. {
  1029. if(maxProfile.ChargingProfileId == -1)
  1030. DEBUG_INFO("MaxProfile found.\n");
  1031. else
  1032. DEBUG_INFO("MaxProfile updated.\n");
  1033. // Required item
  1034. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1035. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1036. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1037. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1038. 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++)
  1039. {
  1040. 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"));
  1041. 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")));
  1042. 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?
  1043. 3:
  1044. 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")));
  1045. }
  1046. // Optional item
  1047. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1048. {
  1049. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1050. }
  1051. else
  1052. {
  1053. sprintf((char*)maxProfile.ValidFrom, " ");
  1054. }
  1055. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1056. {
  1057. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1058. }
  1059. else
  1060. {
  1061. sprintf((char*)maxProfile.ValidTo, " ");
  1062. }
  1063. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1064. {
  1065. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1066. }
  1067. else
  1068. {
  1069. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1070. }
  1071. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1072. {
  1073. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1074. }
  1075. else
  1076. {
  1077. maxProfile.TransactionId = -1;
  1078. }
  1079. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1080. {
  1081. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1082. }
  1083. else
  1084. {
  1085. maxProfile.ChargingSchedule.Duration = 86400;
  1086. }
  1087. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1088. {
  1089. 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")));
  1090. }
  1091. else
  1092. {
  1093. 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));
  1094. }
  1095. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1096. {
  1097. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1098. }
  1099. else
  1100. {
  1101. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1102. }
  1103. }
  1104. }
  1105. }
  1106. else
  1107. {
  1108. if(maxProfile.ChargingProfileId == -1)
  1109. DEBUG_INFO("MaxProfile found.\n");
  1110. else
  1111. DEBUG_INFO("MaxProfile updated.\n");
  1112. // Required item
  1113. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1114. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1115. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1116. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1117. 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++)
  1118. {
  1119. 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"));
  1120. 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")));
  1121. 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?
  1122. 3:
  1123. 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")));
  1124. }
  1125. // Optional item
  1126. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1127. {
  1128. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1129. }
  1130. else
  1131. {
  1132. sprintf((char*)maxProfile.ValidFrom, " ");
  1133. }
  1134. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1135. {
  1136. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1137. }
  1138. else
  1139. {
  1140. sprintf((char*)maxProfile.ValidTo, " ");
  1141. }
  1142. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1143. {
  1144. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1145. }
  1146. else
  1147. {
  1148. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1149. }
  1150. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1151. {
  1152. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1153. }
  1154. else
  1155. {
  1156. maxProfile.TransactionId = -1;
  1157. }
  1158. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1159. {
  1160. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1161. }
  1162. else
  1163. {
  1164. maxProfile.ChargingSchedule.Duration = 86400;
  1165. }
  1166. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1167. {
  1168. 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")));
  1169. }
  1170. else
  1171. {
  1172. 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));
  1173. }
  1174. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1175. {
  1176. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1177. }
  1178. else
  1179. {
  1180. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1181. }
  1182. }
  1183. }
  1184. }
  1185. json_object_put(obj);
  1186. }
  1187. fclose(fp);
  1188. /*
  1189. if(maxProfile.ChargingProfileId !=-1)
  1190. {
  1191. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1192. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1193. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1194. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1195. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1196. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1197. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1198. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1199. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1200. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1201. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1202. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1203. {
  1204. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1205. {
  1206. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1207. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1208. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1209. }
  1210. }
  1211. }
  1212. else
  1213. DEBUG_INFO("MaxProfile not found.\n");
  1214. DEBUG_INFO("------------------------------------\n");*/
  1215. }
  1216. /*
  1217. * Align found profile start schedule & periods
  1218. */
  1219. //DEBUG_INFO("====================================\n");
  1220. /*
  1221. // For local test usage, force modify found profile start schedule info
  1222. 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);
  1223. 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);
  1224. 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);
  1225. */
  1226. if(txProfile.ChargingProfileId != -1)
  1227. {
  1228. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  1229. {
  1230. if(txProfile.ChargingSchedule.Duration != -1)
  1231. {
  1232. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1233. 0:
  1234. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1235. }
  1236. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1237. {
  1238. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1239. {
  1240. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1241. 0:
  1242. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1243. if(idxPeriod > 0)
  1244. {
  1245. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1246. {
  1247. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1248. }
  1249. }
  1250. }
  1251. }
  1252. }
  1253. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  1254. {
  1255. if(txProfile.ChargingSchedule.Duration != -1)
  1256. {
  1257. 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?
  1258. 0:
  1259. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1260. }
  1261. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1262. {
  1263. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1264. {
  1265. 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?
  1266. 0:
  1267. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1268. if(idxPeriod > 0)
  1269. {
  1270. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1271. {
  1272. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1273. }
  1274. }
  1275. }
  1276. }
  1277. }
  1278. else
  1279. {
  1280. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  1281. {
  1282. if(txProfile.ChargingSchedule.Duration != -1)
  1283. {
  1284. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1285. 0:
  1286. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1287. }
  1288. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1289. {
  1290. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1291. {
  1292. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1293. 0:
  1294. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1295. if(idxPeriod > 0)
  1296. {
  1297. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1298. {
  1299. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1300. }
  1301. }
  1302. }
  1303. }
  1304. }
  1305. else
  1306. {
  1307. if(txProfile.ChargingSchedule.Duration != -1)
  1308. {
  1309. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1310. 0:
  1311. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1312. }
  1313. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1314. {
  1315. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1316. {
  1317. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1318. 0:
  1319. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1320. if(idxPeriod > 0)
  1321. {
  1322. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1323. {
  1324. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1325. }
  1326. }
  1327. }
  1328. }
  1329. }
  1330. }
  1331. /*
  1332. DEBUG_INFO("txProfile after align.\n");
  1333. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1334. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1335. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1336. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1337. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1338. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1339. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1340. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1341. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1342. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1343. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1344. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1345. {
  1346. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1347. {
  1348. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1349. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1350. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1351. }
  1352. }*/
  1353. }
  1354. if(defaultTxProfile.ChargingProfileId != -1)
  1355. {
  1356. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  1357. {
  1358. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1359. {
  1360. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1361. 0:
  1362. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1363. }
  1364. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1365. {
  1366. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1367. {
  1368. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1369. 0:
  1370. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1371. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1372. {
  1373. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1374. }
  1375. if(idxPeriod > 0)
  1376. {
  1377. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1378. {
  1379. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1380. }
  1381. }
  1382. }
  1383. }
  1384. }
  1385. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  1386. {
  1387. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1388. {
  1389. 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?
  1390. 0:
  1391. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1392. }
  1393. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1394. {
  1395. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1396. {
  1397. 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?
  1398. 0:
  1399. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1400. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1401. {
  1402. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1403. }
  1404. if(idxPeriod > 0)
  1405. {
  1406. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1407. {
  1408. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1409. }
  1410. }
  1411. }
  1412. }
  1413. }
  1414. else
  1415. {
  1416. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  1417. {
  1418. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1419. {
  1420. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1421. 0:
  1422. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1423. }
  1424. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1425. {
  1426. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1427. {
  1428. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1429. 0:
  1430. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1431. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1432. {
  1433. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1434. }
  1435. if(idxPeriod > 0)
  1436. {
  1437. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1438. {
  1439. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1440. }
  1441. }
  1442. }
  1443. }
  1444. }
  1445. else
  1446. {
  1447. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1448. {
  1449. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1450. 0:
  1451. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1452. }
  1453. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1454. {
  1455. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1456. {
  1457. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1458. 0:
  1459. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1460. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1461. {
  1462. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1463. }
  1464. if(idxPeriod > 0)
  1465. {
  1466. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1467. {
  1468. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1469. }
  1470. }
  1471. }
  1472. }
  1473. }
  1474. }
  1475. /*
  1476. DEBUG_INFO("defaultTxProfile after align.\n");
  1477. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1478. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1479. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1480. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1481. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1482. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1483. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1484. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1485. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1486. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1487. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1488. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1489. {
  1490. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1491. {
  1492. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1493. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1494. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1495. }
  1496. }
  1497. DEBUG_INFO("------------------------------------\n");*/
  1498. }
  1499. if(maxProfile.ChargingProfileId != -1)
  1500. {
  1501. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1502. {
  1503. if(maxProfile.ChargingSchedule.Duration != -1)
  1504. {
  1505. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1506. 0:
  1507. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1508. }
  1509. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1510. {
  1511. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1512. {
  1513. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1514. 0:
  1515. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1516. if(idxPeriod > 0)
  1517. {
  1518. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1519. {
  1520. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1521. }
  1522. }
  1523. }
  1524. }
  1525. }
  1526. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1527. {
  1528. if(maxProfile.ChargingSchedule.Duration != -1)
  1529. {
  1530. 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?
  1531. 0:
  1532. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1533. }
  1534. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1535. {
  1536. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1537. {
  1538. 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?
  1539. 0:
  1540. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1541. if(idxPeriod > 0)
  1542. {
  1543. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1544. {
  1545. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1546. }
  1547. }
  1548. }
  1549. }
  1550. }
  1551. else
  1552. {
  1553. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1554. {
  1555. if(maxProfile.ChargingSchedule.Duration != -1)
  1556. {
  1557. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1558. 0:
  1559. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1560. }
  1561. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1562. {
  1563. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1564. {
  1565. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1566. 0:
  1567. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1568. if(idxPeriod > 0)
  1569. {
  1570. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1571. {
  1572. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1573. }
  1574. }
  1575. }
  1576. }
  1577. }
  1578. else
  1579. {
  1580. if(maxProfile.ChargingSchedule.Duration != -1)
  1581. {
  1582. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1583. 0:
  1584. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1585. }
  1586. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1587. {
  1588. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1589. {
  1590. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1591. 0:
  1592. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1593. if(idxPeriod > 0)
  1594. {
  1595. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1596. {
  1597. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1598. }
  1599. }
  1600. }
  1601. }
  1602. }
  1603. }
  1604. /*
  1605. DEBUG_INFO("MaxProfile after align.\n");
  1606. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1607. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1608. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1609. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1610. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1611. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1612. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1613. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1614. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1615. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1616. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1617. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1618. {
  1619. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1620. {
  1621. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1622. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1623. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1624. }
  1625. }
  1626. DEBUG_INFO("------------------------------------\n");*/
  1627. }
  1628. /*
  1629. * Merge to conposite schedule
  1630. */
  1631. //DEBUG_INFO("====================================\n");
  1632. // Find each profile period quantity
  1633. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1634. {
  1635. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1636. limitMax = idx+1;
  1637. }
  1638. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1639. {
  1640. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1641. limitDef = idx+1;
  1642. }
  1643. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1644. {
  1645. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1646. limitTx = idx+1;
  1647. }
  1648. // TxProfile found, composite schedule based on it
  1649. if(txProfile.ChargingProfileId != -1)
  1650. {
  1651. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  1652. {
  1653. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  1654. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  1655. (txProfile.ChargingSchedule.Duration > 0))
  1656. {
  1657. if(maxProfile.ChargingProfileId != -1)
  1658. {
  1659. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1660. {
  1661. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  1662. {
  1663. if((maxProfile.ChargingSchedule.Duration > 0))
  1664. {
  1665. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1666. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1667. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1668. }
  1669. else
  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;
  1674. }
  1675. }
  1676. if(idxMaxPeriod == (limitMax-1))
  1677. {
  1678. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1679. {
  1680. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1681. {
  1682. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1683. compositePeriodIdx++;
  1684. }
  1685. else
  1686. {
  1687. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1688. }
  1689. }
  1690. }
  1691. }
  1692. }
  1693. else
  1694. {
  1695. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1696. {
  1697. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1698. compositePeriodIdx++;
  1699. }
  1700. else
  1701. {
  1702. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1703. }
  1704. }
  1705. }
  1706. if(idxTxPeriod == (limitTx-1))
  1707. {
  1708. if(defaultTxProfile.ChargingProfileId != -1)
  1709. {
  1710. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1711. {
  1712. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  1713. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  1714. (defaultTxProfile.ChargingSchedule.Duration>0))
  1715. {
  1716. if(maxProfile.ChargingProfileId != -1)
  1717. {
  1718. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1719. {
  1720. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1721. {
  1722. if((maxProfile.ChargingSchedule.Duration > 0))
  1723. {
  1724. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1725. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1726. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1727. }
  1728. else
  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;
  1733. }
  1734. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1735. {
  1736. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1737. {
  1738. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1739. compositePeriodIdx++;
  1740. }
  1741. else
  1742. {
  1743. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1744. }
  1745. }
  1746. break;
  1747. }
  1748. }
  1749. }
  1750. else
  1751. {
  1752. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1753. {
  1754. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1755. compositePeriodIdx++;
  1756. }
  1757. else
  1758. {
  1759. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1760. }
  1761. }
  1762. }
  1763. }
  1764. }
  1765. }
  1766. }
  1767. }
  1768. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  1769. else if(defaultTxProfile.ChargingProfileId != -1)
  1770. {
  1771. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1772. {
  1773. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  1774. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  1775. (defaultTxProfile.ChargingSchedule.Duration > 0))
  1776. {
  1777. if(maxProfile.ChargingProfileId != -1)
  1778. {
  1779. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1780. {
  1781. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1782. {
  1783. if((maxProfile.ChargingSchedule.Duration > 0))
  1784. {
  1785. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1786. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1787. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  1788. }
  1789. else
  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;
  1794. }
  1795. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1796. {
  1797. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1798. {
  1799. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1800. compositePeriodIdx++;
  1801. }
  1802. else
  1803. {
  1804. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1805. }
  1806. }
  1807. break;
  1808. }
  1809. }
  1810. }
  1811. else
  1812. {
  1813. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1814. {
  1815. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1816. compositePeriodIdx++;
  1817. }
  1818. else
  1819. {
  1820. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1821. }
  1822. }
  1823. }
  1824. }
  1825. }
  1826. // Fill other period by MaxProfile
  1827. if(maxProfile.ChargingProfileId != -1)
  1828. {
  1829. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1830. {
  1831. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1832. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1833. (maxProfile.ChargingSchedule.Duration > 0))
  1834. {
  1835. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  1836. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  1837. {
  1838. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  1839. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  1840. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1841. }
  1842. if((maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  1843. {
  1844. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.Duration;
  1845. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  1846. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1847. }
  1848. if(tmpPeriod.Limit != -1)
  1849. {
  1850. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1851. {
  1852. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1853. {
  1854. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1855. compositePeriodIdx++;
  1856. }
  1857. else
  1858. {
  1859. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1860. }
  1861. }
  1862. }
  1863. }
  1864. }
  1865. }
  1866. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  1867. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1868. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1869. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1870. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1871. {
  1872. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1873. {
  1874. compositeProfile->ChargingProfileId = 1;
  1875. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1876. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1877. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1878. }
  1879. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1880. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1881. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1882. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1883. }
  1884. if(line)
  1885. free(line);
  1886. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  1887. }
  1888. //==========================================
  1889. // Init all share memory
  1890. //==========================================
  1891. int InitShareMemory()
  1892. {
  1893. int result = PASS;
  1894. int MeterSMId;
  1895. //creat ShmSysConfigAndInfo
  1896. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  1897. {
  1898. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  1899. result = FAIL;
  1900. }
  1901. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1902. {
  1903. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  1904. result = FAIL;
  1905. }
  1906. else
  1907. {}
  1908. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  1909. {
  1910. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  1911. result = FAIL;
  1912. }
  1913. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1914. {
  1915. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  1916. result = FAIL;
  1917. }
  1918. else
  1919. {}
  1920. //creat ShmPsuData
  1921. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  1922. {
  1923. DEBUG_ERROR("shmget ShmPsuData NG\n");
  1924. result = FAIL;
  1925. }
  1926. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1927. {
  1928. DEBUG_ERROR("shmat ShmPsuData NG\n");
  1929. result = FAIL;
  1930. }
  1931. else
  1932. {}
  1933. //creat ShmOCPP16Data
  1934. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  1935. {
  1936. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  1937. result = FAIL;
  1938. }
  1939. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1940. {
  1941. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  1942. result = FAIL;
  1943. }
  1944. else
  1945. {}
  1946. /****************************** For Initial Settings************************************************/
  1947. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  1948. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  1949. // allocate Configuration memory address
  1950. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  1951. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  1952. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  1953. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  1954. //offline MeterValue Interval
  1955. TempMeterValueInterval = 0;
  1956. return result;
  1957. }
  1958. int ProcessShareMemory()
  1959. {
  1960. if(InitShareMemory() == FAIL)
  1961. {
  1962. DEBUG_ERROR("InitShareMemory NG\n");
  1963. if(ShmStatusCodeData!=NULL)
  1964. {
  1965. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  1966. }
  1967. sleep(5);
  1968. return FAIL;
  1969. }
  1970. return PASS;
  1971. }
  1972. //---------------------common routine---------------------------//
  1973. int isOFFline(void)
  1974. {
  1975. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  1976. {
  1977. if(TempMeterValueInterval >= 2 )
  1978. {
  1979. TempMeterValueInterval = 0;
  1980. return TRUE;
  1981. }
  1982. else
  1983. {
  1984. TempMeterValueInterval = TempMeterValueInterval+ 1;
  1985. return FALSE;
  1986. }
  1987. }
  1988. else
  1989. {
  1990. return FALSE;
  1991. }
  1992. }
  1993. //---------------------------------------------
  1994. // new:
  1995. // enum SYSTEM_STATUS
  1996. // {
  1997. // SYS_MODE_BOOTING = 0,
  1998. // SYS_MODE_IDLE = 1,
  1999. // SYS_MODE_AUTHORIZING = 2,
  2000. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  2001. // SYS_MODE_REASSIGN = 4,
  2002. // SYS_MODE_PREPARING = 5,
  2003. // SYS_MODE_PREPARE_FOR_EV = 6,
  2004. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  2005. // SYS_MODE_CHARGING = 8,
  2006. // SYS_MODE_TERMINATING = 9,
  2007. // SYS_MODE_COMPLETE = 10,
  2008. // SYS_MODE_ALARM = 11,
  2009. // SYS_MODE_FAULT = 12,
  2010. // SYS_MODE_RESERVATION = 13,
  2011. // SYS_MODE_BOOKING = 14,
  2012. // SYS_MODE_MAINTAIN = 15,
  2013. // SYS_MODE_DEBUG = 16,
  2014. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  2015. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  2016. // SYS_MODE_UPDATE = 19
  2017. // };
  2018. //
  2019. //
  2020. //-----------------------------------------
  2021. void CheckSystemValue(void)
  2022. {
  2023. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  2024. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  2025. char filenmae[100]={0};
  2026. char str[100]={0};
  2027. int tempIndex = 0;
  2028. //===============================
  2029. // send Heartbeat
  2030. //===============================
  2031. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2032. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  2033. {
  2034. clientTime.Heartbeat=time((time_t*)NULL);
  2035. if(server_sign == TRUE)
  2036. {
  2037. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2038. }
  2039. else
  2040. {
  2041. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  2042. }
  2043. }
  2044. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  2045. {
  2046. //parameter for test
  2047. sendHeartbeatRequest(0);
  2048. //==============================================
  2049. // Reset Waiting Time
  2050. //==============================================
  2051. HeartBeatWithNOResponse += 1;
  2052. }
  2053. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  2054. {
  2055. //===============================
  2056. // CSU Trigger Reset Conf
  2057. //===============================
  2058. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  2059. {
  2060. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  2061. }
  2062. //===============================
  2063. // CSU Trigger Authorize Request
  2064. //===============================
  2065. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  2066. {
  2067. sendAuthorizeRequest(0);
  2068. authorizeRetryTimes = authorizeRetryTimes + 1;
  2069. if(authorizeRetryTimes < 3)
  2070. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2071. }
  2072. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  2073. {
  2074. authorizeRetryTimes = 0;
  2075. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  2076. server_sign = FALSE;
  2077. }
  2078. 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))
  2079. {
  2080. sendAuthorizeRequest(0);
  2081. }
  2082. //===============================
  2083. // CSU Trigger Smart Charging Profilw
  2084. //===============================
  2085. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  2086. {
  2087. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index]);
  2088. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  2089. }
  2090. //==============================================
  2091. // Charger start transaction
  2092. //==============================================
  2093. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2094. {
  2095. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  2096. sendStartTransactionRequest(gun_index);
  2097. clientTime.StartTransaction = time((time_t*)NULL);
  2098. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2099. }
  2100. //==============================================
  2101. // Charger stop transaction
  2102. //==============================================
  2103. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2104. {
  2105. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2106. sendStopTransactionRequest(gun_index);
  2107. clientTime.StopTransaction = time((time_t*)NULL);
  2108. }
  2109. //==============================================
  2110. // Charger status report
  2111. //==============================================
  2112. //--- Check Mode Change ---//
  2113. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2114. if(gunType[gun_index] == 'J')
  2115. {
  2116. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2117. {
  2118. tempIndex = ((gun_index==2) ? 1: 0);
  2119. }
  2120. else
  2121. {
  2122. tempIndex = gun_index;
  2123. }
  2124. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2125. {
  2126. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2127. {
  2128. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  2129. {
  2130. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2131. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2132. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2133. statusModeChage[gun_index] = TRUE;
  2134. }
  2135. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2136. {
  2137. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2138. if((access(filenmae,F_OK))!=-1)
  2139. {
  2140. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2141. sprintf(str,"rm -f %s",filenmae);
  2142. system(str);
  2143. }
  2144. }
  2145. #if 1 // for TempStopTransaction
  2146. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2147. {
  2148. checkTempStopTransaction(gun_index);
  2149. }
  2150. #endif
  2151. }
  2152. }
  2153. }
  2154. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2155. {
  2156. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2157. {
  2158. tempIndex = ((gun_index==2) ? 1: 0);
  2159. }
  2160. else
  2161. {
  2162. tempIndex = gun_index;
  2163. }
  2164. for (int index = 0; index < CCS_QUANTITY; index++)
  2165. {
  2166. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2167. {
  2168. 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]*/ )
  2169. {
  2170. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2171. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2172. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2173. statusModeChage[gun_index] = TRUE;
  2174. }
  2175. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2176. {
  2177. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2178. if((access(filenmae,F_OK))!=-1)
  2179. {
  2180. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2181. sprintf(str,"rm -f %s",filenmae);
  2182. system(str);
  2183. }
  2184. }
  2185. #if 1 // for TempStopTransaction
  2186. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2187. {
  2188. checkTempStopTransaction(gun_index);
  2189. }
  2190. #endif
  2191. }
  2192. }
  2193. }
  2194. else if(gunType[gun_index] == 'G')
  2195. {
  2196. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2197. {
  2198. tempIndex = ((gun_index==2) ? 1: 0);
  2199. }
  2200. else
  2201. {
  2202. tempIndex = gun_index;
  2203. }
  2204. for (int index = 0; index < GB_QUANTITY; index++)
  2205. {
  2206. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2207. {
  2208. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  2209. {
  2210. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2211. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2212. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2213. statusModeChage[gun_index] = TRUE;
  2214. }
  2215. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2216. {
  2217. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2218. if((access(filenmae,F_OK))!=-1)
  2219. {
  2220. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2221. sprintf(str,"rm -f %s",filenmae);
  2222. system(str);
  2223. }
  2224. }
  2225. #if 1 // for TempStopTransaction
  2226. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2227. {
  2228. checkTempStopTransaction(gun_index);
  2229. }
  2230. #endif
  2231. }
  2232. }
  2233. }
  2234. else if(gunType[gun_index] == 'O')
  2235. {
  2236. tempIndex = gun_index;
  2237. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2238. {
  2239. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2240. {
  2241. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  2242. {
  2243. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  2244. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  2245. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2246. statusModeChage[gun_index] = TRUE;
  2247. }
  2248. 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
  2249. {
  2250. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2251. if((access(filenmae,F_OK))!=-1)
  2252. {
  2253. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2254. sprintf(str,"rm -f %s",filenmae);
  2255. system(str);
  2256. }
  2257. }
  2258. #if 1 // for TempStopTransaction
  2259. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2260. {
  2261. checkTempStopTransaction(gun_index);
  2262. }
  2263. #endif
  2264. }
  2265. }
  2266. }
  2267. else
  2268. {
  2269. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2270. {
  2271. tempIndex = 2;
  2272. }
  2273. else
  2274. {
  2275. tempIndex = gun_index;
  2276. }
  2277. for (int index = 0; index < AC_QUANTITY; index++)
  2278. {
  2279. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2280. {
  2281. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  2282. {
  2283. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2284. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2285. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2286. statusModeChage[gun_index] = TRUE;
  2287. }
  2288. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2289. {
  2290. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2291. if((access(filenmae,F_OK))!=-1)
  2292. {
  2293. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2294. sprintf(str,"rm -f %s",filenmae);
  2295. system(str);
  2296. }
  2297. }
  2298. #if 1 // for TempStopTransaction
  2299. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2300. {
  2301. checkTempStopTransaction(gun_index);
  2302. }
  2303. #endif
  2304. }
  2305. }// END
  2306. }
  2307. if(isWebsocketSendable &&
  2308. (
  2309. (statusModeChage[gun_index] == TRUE) ||
  2310. //((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index))) ||
  2311. ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 10))
  2312. )
  2313. )
  2314. {
  2315. if(SystemInitial > 0)
  2316. SystemInitial -= 1;
  2317. sendStatusNotificationRequest(gun_index);
  2318. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2319. statusModeChage[gun_index] = FALSE;
  2320. }
  2321. //==============================================
  2322. // Meter report
  2323. //==============================================
  2324. // Trigger MeterValue
  2325. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  2326. {
  2327. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  2328. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  2329. }
  2330. // ClockAlign MeterValue
  2331. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  2332. {
  2333. if(gunType[gun_index] == 'J')
  2334. {
  2335. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2336. {
  2337. tempIndex = ((gun_index==2) ? 1: 0);
  2338. }
  2339. else
  2340. {
  2341. tempIndex = gun_index;
  2342. }
  2343. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2344. {
  2345. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2346. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2347. {
  2348. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2349. {
  2350. reqClockAlignMeter[gun_index] = 1;
  2351. }
  2352. }
  2353. }// End for CHAdeMO
  2354. }
  2355. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2356. {
  2357. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2358. {
  2359. tempIndex = ((gun_index==2) ? 1: 0);
  2360. }
  2361. else
  2362. {
  2363. tempIndex = gun_index;
  2364. }
  2365. for (int index = 0; index < CCS_QUANTITY; index++)
  2366. {
  2367. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2368. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2369. {
  2370. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2371. {
  2372. reqClockAlignMeter[gun_index] = 1;
  2373. }
  2374. }
  2375. } // End for CCS
  2376. }
  2377. else if(gunType[gun_index] == 'G')
  2378. {
  2379. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2380. {
  2381. tempIndex = ((gun_index==2) ? 1: 0);
  2382. }
  2383. else
  2384. {
  2385. tempIndex = gun_index;
  2386. }
  2387. for (int index = 0; index < GB_QUANTITY; index++)
  2388. {
  2389. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2390. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2391. {
  2392. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2393. {
  2394. reqClockAlignMeter[gun_index] = 1;
  2395. }
  2396. }
  2397. }// End for GB
  2398. }
  2399. else if(gunType[gun_index] == 'O')
  2400. {
  2401. tempIndex = gun_index;
  2402. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2403. {
  2404. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2405. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2406. {
  2407. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_CHARGING)
  2408. {
  2409. reqClockAlignMeter[gun_index] = 1;
  2410. }
  2411. }
  2412. }
  2413. }
  2414. else
  2415. {
  2416. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2417. {
  2418. tempIndex = 2;
  2419. }
  2420. else
  2421. {
  2422. tempIndex = gun_index;
  2423. }
  2424. for (int index = 0; index < AC_QUANTITY; index++)
  2425. {
  2426. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2427. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2428. {
  2429. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2430. {
  2431. reqClockAlignMeter[gun_index] = 1;
  2432. }
  2433. }
  2434. }//End for AC
  2435. }
  2436. if(reqClockAlignMeter[gun_index] == 1)
  2437. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  2438. }
  2439. // Sample period MeterValue
  2440. if(/*(server_sign == TRUE) &&(isOFFline() == TRUE) ||*/
  2441. (((time((time_t*)NULL) - clientTime.MeterValues[gun_index]) > (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1))))
  2442. {
  2443. //check Transaction active
  2444. if(gunType[gun_index] == 'J')
  2445. {
  2446. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2447. {
  2448. tempIndex = ((gun_index==2) ? 1: 0);
  2449. }
  2450. else
  2451. {
  2452. tempIndex = gun_index;
  2453. }
  2454. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2455. {
  2456. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2457. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2458. {
  2459. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2460. {
  2461. reqSampleMeter[gun_index] = 1;
  2462. }
  2463. }
  2464. }// End for CHAdeMO
  2465. }
  2466. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2467. {
  2468. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2469. {
  2470. tempIndex = ((gun_index==2) ? 1: 0);
  2471. }
  2472. else
  2473. {
  2474. tempIndex = gun_index;
  2475. }
  2476. for (int index = 0; index < CCS_QUANTITY; index++)
  2477. {
  2478. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2479. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2480. {
  2481. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2482. {
  2483. reqSampleMeter[gun_index] = 1;
  2484. }
  2485. }
  2486. } // End for CCS
  2487. }
  2488. else if(gunType[gun_index] == 'G')
  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 < GB_QUANTITY; index++)
  2499. {
  2500. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2501. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2502. {
  2503. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2504. {
  2505. reqSampleMeter[gun_index] = 1;
  2506. }
  2507. }
  2508. }// End for GB
  2509. }
  2510. else if(gunType[gun_index] == 'O')
  2511. {
  2512. tempIndex = gun_index;
  2513. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2514. {
  2515. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2516. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2517. {
  2518. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  2519. {
  2520. reqSampleMeter[gun_index] = 1;
  2521. }
  2522. }
  2523. }
  2524. }
  2525. else
  2526. {
  2527. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2528. {
  2529. tempIndex = 2;
  2530. }
  2531. else
  2532. {
  2533. tempIndex = gun_index;
  2534. }
  2535. for (int index = 0; index < AC_QUANTITY; index++)
  2536. {
  2537. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2538. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2539. {
  2540. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2541. {
  2542. reqSampleMeter[gun_index] = 1;
  2543. }
  2544. }
  2545. }//End for AC
  2546. }
  2547. if(reqSampleMeter[gun_index] == 1)
  2548. {
  2549. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  2550. storeTempStopTransaction(gun_index);
  2551. }
  2552. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2553. }
  2554. //==============================================
  2555. // Check Connector reserved
  2556. //==============================================
  2557. //===============================
  2558. // Check if Reserve is expired
  2559. //===============================
  2560. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  2561. {
  2562. double diff_t;
  2563. struct tm tp;
  2564. // current time
  2565. time_t t = time(NULL);
  2566. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  2567. tp.tm_isdst = -1;
  2568. time_t utc = mktime(&tp);
  2569. diff_t = difftime(utc, t);
  2570. if(diff_t <= 0)
  2571. {
  2572. DEBUG_INFO("reserve expired.\n");
  2573. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  2574. }
  2575. }//END OF Check if Reserve is expired
  2576. //==========================================
  2577. // csu trigger FirmwareStatusNotificationReq
  2578. //==========================================
  2579. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  2580. {
  2581. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  2582. }
  2583. //==========================================
  2584. // csu trigger CancelReservationConf
  2585. //==========================================
  2586. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  2587. {
  2588. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  2589. }
  2590. //==========================================
  2591. // csu trigger ChangeAvailabilityConf
  2592. //==========================================
  2593. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  2594. {
  2595. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  2596. }
  2597. //==========================================
  2598. // csu trigger UnlockConnectorConf
  2599. //==========================================
  2600. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  2601. {
  2602. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  2603. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  2604. }
  2605. //==========================================
  2606. // csu trigger ReserveNowConf
  2607. //==========================================
  2608. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  2609. {
  2610. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  2611. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  2612. }
  2613. //==========================================
  2614. // csu trigger DataTransferReq
  2615. //==========================================
  2616. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  2617. {
  2618. sendDataTransferRequest(gun_index);
  2619. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  2620. }
  2621. }
  2622. }
  2623. //==========================================
  2624. // send request routine
  2625. //==========================================
  2626. int sendAuthorizeRequest(int gun_index)
  2627. {
  2628. mtrace();
  2629. int result = FAIL;
  2630. char message[100]={0};
  2631. char guid[37];
  2632. char tempdata[65]={0};
  2633. DEBUG_INFO("sendAuthorizeRequest...\n");
  2634. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  2635. //Local Authorize
  2636. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  2637. {
  2638. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  2639. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2640. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  2641. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  2642. result = PASS;
  2643. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2644. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2645. authorizeRetryTimes = 0;
  2646. return result;
  2647. }
  2648. 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))||
  2649. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  2650. {
  2651. // Query from cache
  2652. DEBUG_INFO("Authorize from cache.\n");
  2653. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2654. // Query from list
  2655. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  2656. {
  2657. DEBUG_INFO("Authorize from list.\n");
  2658. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2659. }
  2660. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  2661. {
  2662. if(strcmp(idTagQuery.idTagstr,"") == 0)
  2663. {
  2664. DEBUG_INFO("off-line Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  2665. }
  2666. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  2667. {
  2668. DEBUG_INFO("off-line Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  2669. }
  2670. DEBUG_INFO("off-line Local Authorization Fail !!!!\n");
  2671. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2672. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2673. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  2674. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  2675. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2676. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2677. authorizeRetryTimes = 0;
  2678. return result;
  2679. }
  2680. else
  2681. {
  2682. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  2683. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  2684. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2685. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  2686. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  2687. else
  2688. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  2689. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  2690. result = PASS;
  2691. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2692. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2693. authorizeRetryTimes = 0;
  2694. return result;
  2695. }
  2696. }
  2697. //initialize struct Authorize
  2698. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  2699. //get data from shared memory
  2700. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2701. random_uuid(guid);
  2702. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  2703. LWS_Send(message);
  2704. sprintf(tempdata, "Authorize,%d", gun_index);
  2705. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2706. {
  2707. result = PASS;
  2708. DEBUG_INFO("Authorize mapItem pass\n");
  2709. }
  2710. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2711. return result;
  2712. }
  2713. int sendBootNotificationRequest(void)
  2714. {
  2715. mtrace();
  2716. int result = FAIL;
  2717. char message[500]={0}, payload[700]={0};
  2718. char guid[37]={0};
  2719. char tempdata[65]={0};
  2720. // Fill BootNotification fields
  2721. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  2722. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  2723. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  2724. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2725. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  2726. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  2727. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  2728. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  2729. ShmOCPP16Data->ChargeBoxId
  2730. ,ShmSysConfigAndInfo->SysConfig.ModelName
  2731. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  2732. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  2733. ,ShmOCPP16Data->BootNotification.CpFwVersion
  2734. ,ShmOCPP16Data->BootNotification.CpIccid
  2735. ,ShmOCPP16Data->BootNotification.CpImsi);
  2736. random_uuid(guid);
  2737. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  2738. LWS_Send(message);
  2739. sprintf(tempdata, "BootNotification,0");
  2740. 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*/)
  2741. {
  2742. result = PASS;
  2743. }
  2744. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  2745. strcpy(queuedata,message);
  2746. return result;
  2747. }
  2748. int sendDataTransferRequest(int gun_index)
  2749. {
  2750. mtrace();
  2751. char message[1000]={0};
  2752. char guid[37]={0};
  2753. char tempdata[65]={0};
  2754. int result = FAIL;
  2755. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  2756. random_uuid(guid);
  2757. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  2758. MESSAGE_TYPE_CALL,
  2759. guid,
  2760. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  2761. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  2762. ShmOCPP16Data->DataTransfer[gun_index].Data);
  2763. LWS_Send(message);
  2764. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  2765. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2766. {
  2767. result = PASS;
  2768. DEBUG_INFO("DataTransfer mapItem pass\n");
  2769. }
  2770. return result;
  2771. }
  2772. int sendDiagnosticsStatusNotificationRequest(char *status)
  2773. {
  2774. mtrace();
  2775. int result = FAIL;
  2776. char message[110]={0};
  2777. char guid[37]={0};
  2778. char tempdata[65]={0};
  2779. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  2780. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  2781. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  2782. random_uuid(guid);
  2783. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  2784. LWS_SendNow(message);
  2785. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  2786. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2787. {
  2788. result = PASS;
  2789. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  2790. }
  2791. //#ifdef SystemLogMessage
  2792. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  2793. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2794. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  2795. //#endif
  2796. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  2797. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  2798. //record status
  2799. if(strcmp(status,"Idle")==0)
  2800. {
  2801. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  2802. }
  2803. else if(strcmp(status,"Uploaded")==0)
  2804. {
  2805. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  2806. }
  2807. else if(strcmp(status,"UploadFailed")==0)
  2808. {
  2809. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  2810. }
  2811. else if(strcmp(status,"Uploading")==0)
  2812. {
  2813. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  2814. }
  2815. return result;
  2816. }
  2817. int sendFirmwareStatusNotificationRequest(char *status)
  2818. {
  2819. mtrace();
  2820. int result = FAIL;
  2821. char message[110]={0};
  2822. char guid[37]={0};
  2823. char tempdata[65]={0};
  2824. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  2825. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  2826. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  2827. random_uuid(guid);
  2828. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  2829. LWS_SendNow(message);
  2830. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  2831. 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*/)
  2832. {
  2833. result = PASS;
  2834. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  2835. }
  2836. //#ifdef SystemLogMessage
  2837. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  2838. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2839. //#endif
  2840. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  2841. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  2842. //record status
  2843. if(strcmp(status,"Downloaded")==0)
  2844. {
  2845. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  2846. }
  2847. else if(strcmp(status,"DownloadFailed")==0)
  2848. {
  2849. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  2850. }
  2851. else if(strcmp(status,"Downloading")==0)
  2852. {
  2853. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  2854. }
  2855. else if(strcmp(status,"Idle")==0)
  2856. {
  2857. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  2858. }
  2859. else if(strcmp(status,"InstallationFailed")==0)
  2860. {
  2861. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  2862. }
  2863. else if(strcmp(status,"Installing")==0)
  2864. {
  2865. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  2866. }
  2867. else if(strcmp(status,"Installed")==0)
  2868. {
  2869. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  2870. }
  2871. return result;
  2872. }
  2873. int sendHeartbeatRequest(int gun_index)
  2874. {
  2875. mtrace();
  2876. int result = FAIL;
  2877. char message[80]={0};
  2878. char guid[37]={0};
  2879. char tempdata[65]={0};
  2880. random_uuid(guid);
  2881. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  2882. , MESSAGE_TYPE_CALL
  2883. , guid );
  2884. LWS_Send(message);
  2885. sprintf(tempdata, "Heartbeat,%d", 0);
  2886. 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*/)
  2887. {
  2888. result = PASS;
  2889. }
  2890. return result;
  2891. }
  2892. int sendStartTransactionRequest(int gun_index)
  2893. {
  2894. mtrace();
  2895. int result = FAIL;
  2896. char message[250]={0};
  2897. char guid[37]={0};
  2898. struct timeval tmnow;
  2899. struct tm *tm;
  2900. char buf[28];//, usec_buf[6];
  2901. char tempdata[65]={0};
  2902. int tempIndex = 0;
  2903. DEBUG_INFO("sendStartTransactionRequest...\n");
  2904. gettimeofday(&tmnow, NULL);
  2905. time_t t;
  2906. t = time(NULL);
  2907. /*UTC time and date*/
  2908. tm = gmtime(&t);
  2909. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2910. #if 0 // remove temporally
  2911. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2912. strcat(buf,".");
  2913. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2914. strcat(buf,usec_buf);
  2915. #endif
  2916. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  2917. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  2918. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2919. // clear StartTransaction Response
  2920. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  2921. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  2922. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  2923. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  2924. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2925. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2926. if(gunType[gun_index] == 'J')
  2927. {
  2928. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2929. {
  2930. tempIndex = ((gun_index==2) ? 1: 0);
  2931. }
  2932. else
  2933. {
  2934. tempIndex = gun_index;
  2935. }
  2936. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2937. {
  2938. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2939. {
  2940. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  2941. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  2942. }
  2943. }
  2944. }
  2945. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2946. {
  2947. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2948. {
  2949. tempIndex = ((gun_index==2) ? 1: 0);
  2950. }
  2951. else
  2952. {
  2953. tempIndex = gun_index;
  2954. }
  2955. for (int index = 0; index < CCS_QUANTITY; index++)
  2956. {
  2957. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2958. {
  2959. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  2960. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  2961. }
  2962. }
  2963. }
  2964. else if(gunType[gun_index] == 'G')
  2965. {
  2966. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2967. {
  2968. tempIndex = ((gun_index==2) ? 1: 0);
  2969. }
  2970. else
  2971. {
  2972. tempIndex = gun_index;
  2973. }
  2974. for (int index = 0; index < GB_QUANTITY; index++)
  2975. {
  2976. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2977. {
  2978. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  2979. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  2980. }
  2981. }
  2982. }
  2983. else if(gunType[gun_index] == 'O')
  2984. {
  2985. tempIndex = gun_index;
  2986. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2987. {
  2988. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2989. {
  2990. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  2991. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  2992. }
  2993. }
  2994. }
  2995. else
  2996. {
  2997. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2998. {
  2999. tempIndex = 2;
  3000. }
  3001. else
  3002. {
  3003. tempIndex = gun_index;
  3004. }
  3005. for (int index = 0; index < AC_QUANTITY; index++)
  3006. {
  3007. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3008. {
  3009. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3010. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  3011. }
  3012. }
  3013. }
  3014. random_uuid(guid);
  3015. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  3016. {
  3017. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  3018. , gun_index +1
  3019. , MESSAGE_TYPE_CALL
  3020. , guid
  3021. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3022. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3023. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3024. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3025. }
  3026. else
  3027. {
  3028. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  3029. , gun_index +1
  3030. , MESSAGE_TYPE_CALL
  3031. , guid
  3032. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3033. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3034. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3035. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  3036. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3037. }
  3038. #if 1
  3039. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  3040. 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*/)
  3041. {
  3042. result = PASS;
  3043. }
  3044. #endif
  3045. strcpy(queuedata, message);
  3046. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3047. return result;
  3048. }
  3049. int sendStatusNotificationRequest(int gun_index)
  3050. {
  3051. mtrace();
  3052. int result = FAIL;
  3053. char message[600]={0};
  3054. char guid[37];
  3055. int currentStatus = 0;
  3056. struct timeval tmnow;
  3057. struct tm *tm;
  3058. char buf[28];//, usec_buf[6];
  3059. char tempdata[65]={0};
  3060. int tempIndex = 0;
  3061. gettimeofday(&tmnow, NULL);
  3062. time_t t;
  3063. t = time(NULL);
  3064. /*UTC time and date*/
  3065. tm = gmtime(&t);
  3066. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3067. #if 0 // remove temporally
  3068. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3069. strcat(buf,".");
  3070. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3071. strcat(buf,usec_buf);
  3072. #endif
  3073. printf("%s",buf);
  3074. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  3075. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  3076. // it's option
  3077. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  3078. /*
  3079. enum _SYSTEM_STATUS
  3080. {
  3081. S_BOOTING = 0,
  3082. S_IDLE, = 1
  3083. S_AUTHORIZING, =2
  3084. S_REASSIGN_CHECK, =3
  3085. S_REASSIGN, =4
  3086. S_PRECHARGE, =5
  3087. S_PREPARING_FOR_EV, =6
  3088. S_PREPARING_FOR_EVSE, =7
  3089. S_CHARGING, =8
  3090. S_TERMINATING, =9
  3091. S_COMPLETE, =10
  3092. S_ALARM, =11
  3093. S_FAULT =12
  3094. }
  3095. */
  3096. //check Transaction active
  3097. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3098. if(gunType[gun_index] == 'J')
  3099. {
  3100. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3101. {
  3102. tempIndex = ((gun_index==2) ? 1: 0);
  3103. }
  3104. else
  3105. {
  3106. tempIndex = gun_index;
  3107. }
  3108. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3109. {
  3110. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  3111. {
  3112. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  3113. {
  3114. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3115. {
  3116. currentStatus = 1; //OCPP Status: Preparing
  3117. }
  3118. else
  3119. {
  3120. currentStatus = 0; //OCPP Status: Available
  3121. }
  3122. }
  3123. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3124. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3125. ) //S_PRECHARGE
  3126. {
  3127. currentStatus = 1; //OCPP Status: Preparing
  3128. }
  3129. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3130. {
  3131. currentStatus = 2; //OCPP Status: Charging
  3132. }
  3133. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3134. {
  3135. currentStatus = 5; //OCPP Status: Finishing
  3136. }
  3137. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3138. {
  3139. currentStatus = 4; //OCPP Status: SuspendedEV
  3140. }
  3141. 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
  3142. {
  3143. currentStatus = 7; //OCPP Status: Unavailable
  3144. }
  3145. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3146. {
  3147. currentStatus = 8; //OCPP Status: Faulted
  3148. }
  3149. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3150. {
  3151. currentStatus = 6; //OCPP Status: Reserved
  3152. }
  3153. } //end of the same index
  3154. }//end of for CHAdeMO_QUANTITY
  3155. }
  3156. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3157. {
  3158. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3159. {
  3160. tempIndex = ((gun_index==2) ? 1: 0);
  3161. }
  3162. else
  3163. {
  3164. tempIndex = gun_index;
  3165. }
  3166. for (int index = 0; index < CCS_QUANTITY; index++)
  3167. {
  3168. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3169. {
  3170. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3171. {
  3172. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3173. {
  3174. currentStatus = 1; //OCPP Status: Preparing
  3175. }
  3176. else
  3177. {
  3178. currentStatus = 0; //OCPP Status: Available
  3179. }
  3180. }
  3181. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3182. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3183. ) //S_PRECHARGE
  3184. {
  3185. currentStatus = 1; //OCPP Status: Preparing
  3186. }
  3187. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3188. {
  3189. currentStatus = 2; //OCPP Status: Charging
  3190. }
  3191. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3192. {
  3193. currentStatus = 5; //OCPP Status: Finishing
  3194. }
  3195. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3196. {
  3197. currentStatus = 4; //OCPP Status: SuspendedEV
  3198. }
  3199. 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
  3200. {
  3201. currentStatus = 7; //OCPP Status : Unavailable
  3202. }
  3203. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3204. {
  3205. currentStatus = 8; //OCPP Status: Faulted
  3206. }
  3207. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3208. {
  3209. currentStatus = 6; //OCPP Status: Reserved
  3210. }
  3211. } //end of the same index
  3212. } // end of for CCS_QUANTITY
  3213. }
  3214. else if(gunType[gun_index] == 'G')
  3215. {
  3216. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3217. {
  3218. tempIndex = ((gun_index==2) ? 1: 0);
  3219. }
  3220. else
  3221. {
  3222. tempIndex = gun_index;
  3223. }
  3224. for (int index = 0; index < GB_QUANTITY; index++)
  3225. {
  3226. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3227. {
  3228. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3229. {
  3230. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3231. {
  3232. currentStatus = 1; //OCPP Status: Preparing
  3233. }
  3234. else
  3235. {
  3236. currentStatus = 0; //OCPP Status: Available
  3237. }
  3238. }
  3239. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3240. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3241. ) //S_PRECHARGE
  3242. {
  3243. currentStatus = 1; //OCPP Status: Preparing
  3244. }
  3245. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3246. {
  3247. currentStatus = 2; //OCPP Status: Charging
  3248. }
  3249. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3250. {
  3251. currentStatus = 5; //OCPP Status: Finishing
  3252. }
  3253. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3254. {
  3255. currentStatus = 4; //OCPP Status: SuspendedEV
  3256. }
  3257. 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
  3258. {
  3259. currentStatus = 7; //OCPP Status: Unavailable
  3260. }
  3261. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3262. {
  3263. currentStatus = 8; //OCPP Status: Faulted
  3264. }
  3265. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3266. {
  3267. currentStatus = 6; //OCPP Status: Reserved
  3268. }
  3269. } //end of the same index
  3270. } // end of for GB_QUANTITY
  3271. }
  3272. else if(gunType[gun_index] == 'O')
  3273. {
  3274. tempIndex = gun_index;
  3275. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3276. {
  3277. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3278. {
  3279. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3280. {
  3281. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3282. {
  3283. currentStatus = 1; //OCPP Status: Preparing
  3284. }
  3285. else
  3286. {
  3287. currentStatus = 0; //OCPP Status: Available
  3288. }
  3289. }
  3290. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_PREPARING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3291. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3292. ) //S_PRECHARGE
  3293. {
  3294. currentStatus = 1; //OCPP Status: Preparing
  3295. }
  3296. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3297. {
  3298. currentStatus = 2; //OCPP Status: Charging
  3299. }
  3300. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3301. {
  3302. currentStatus = 5; //OCPP Status: Finishing
  3303. }
  3304. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3305. {
  3306. currentStatus = 4; //OCPP Status: SuspendedEV
  3307. }
  3308. 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
  3309. {
  3310. currentStatus = 7; //OCPP Status: Unavailable
  3311. }
  3312. 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
  3313. {
  3314. currentStatus = 8; //OCPP Status: Faulted
  3315. }
  3316. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3317. {
  3318. currentStatus = 6; //OCPP Status: Reserved
  3319. }
  3320. } //end of the same index
  3321. }
  3322. }
  3323. else
  3324. {
  3325. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3326. {
  3327. tempIndex = 2;
  3328. }
  3329. else
  3330. {
  3331. tempIndex = gun_index;
  3332. }
  3333. for (int index = 0; index < AC_QUANTITY; index++)
  3334. {
  3335. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3336. {
  3337. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3338. {
  3339. 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))
  3340. {
  3341. currentStatus = 1; //OCPP Status: Preparing
  3342. }
  3343. else
  3344. {
  3345. currentStatus = 0; //OCPP Status: Available
  3346. }
  3347. }
  3348. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  3349. {
  3350. currentStatus = 1; //OCPP Status: Preparing
  3351. }
  3352. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3353. {
  3354. currentStatus = 2; //OCPP Status: Charging
  3355. }
  3356. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3357. {
  3358. currentStatus = 5; //OCPP Status: Finishing
  3359. }
  3360. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3361. {
  3362. currentStatus = 4; //OCPP Status: SuspendedEV
  3363. }
  3364. 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
  3365. {
  3366. currentStatus = 7; //OCPP Status: Unavailable
  3367. }
  3368. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3369. {
  3370. currentStatus = 8; //OCPP Status: Faulted
  3371. }
  3372. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3373. {
  3374. currentStatus = 6; //OCPP Status: Reserved
  3375. }
  3376. }//end of the same index
  3377. }//end of for AC_QUANTITY
  3378. }
  3379. //it's option
  3380. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3381. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  3382. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3383. random_uuid(guid);
  3384. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3385. , MESSAGE_TYPE_CALL
  3386. , guid
  3387. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3388. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3389. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3390. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3391. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3392. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3393. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3394. if((server_sign == TRUE))
  3395. {
  3396. LWS_Send(message);
  3397. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3398. 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*/)
  3399. {
  3400. //DEBUG_ERROR("statusNotification mapitem pass");
  3401. result = PASS;
  3402. }
  3403. }
  3404. else
  3405. {
  3406. result = PASS;
  3407. }
  3408. return result;
  3409. }
  3410. int sendStopTransactionRequest(int gun_index)
  3411. {
  3412. mtrace();
  3413. int result = FAIL;
  3414. //char message[1500]={0};
  3415. char guid[37]={0};
  3416. char tempdata[65]={0};
  3417. int tempIndex = 0;
  3418. char TempStopTransaction[256];
  3419. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  3420. //int idx_sample=0;
  3421. DEBUG_INFO("sendStopTransactionRequest \n");
  3422. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3423. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  3424. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  3425. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3426. if(gunType[gun_index] == 'J')
  3427. {
  3428. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3429. {
  3430. tempIndex = ((gun_index==2) ? 1: 0);
  3431. }
  3432. else
  3433. {
  3434. tempIndex = gun_index;
  3435. }
  3436. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3437. {
  3438. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3439. {
  3440. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3441. }
  3442. }// END OF CHAdeMO_QUANTITY
  3443. }
  3444. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3445. {
  3446. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3447. {
  3448. tempIndex = ((gun_index==2) ? 1: 0);
  3449. }
  3450. else
  3451. {
  3452. tempIndex = gun_index;
  3453. }
  3454. for (int index = 0; index < CCS_QUANTITY; index++)
  3455. {
  3456. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3457. {
  3458. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3459. }
  3460. }// END OF CCS_QUANTITY
  3461. }
  3462. else if(gunType[gun_index] == 'G')
  3463. {
  3464. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3465. {
  3466. tempIndex = ((gun_index==2) ? 1: 0);
  3467. }
  3468. else
  3469. {
  3470. tempIndex = gun_index;
  3471. }
  3472. for (int index = 0; index < GB_QUANTITY; index++)
  3473. {
  3474. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3475. {
  3476. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3477. }
  3478. }// END OF GB_QUANTITY
  3479. }
  3480. else if(gunType[gun_index] == 'O')
  3481. {
  3482. tempIndex = gun_index;
  3483. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3484. {
  3485. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3486. {
  3487. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3488. }
  3489. }// END OF GB_QUANTITY
  3490. }
  3491. else
  3492. {
  3493. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3494. {
  3495. tempIndex = 2;
  3496. }
  3497. else
  3498. {
  3499. tempIndex = gun_index;
  3500. }
  3501. for (int index = 0; index < AC_QUANTITY; index++)
  3502. {
  3503. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3504. {
  3505. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3506. }
  3507. }// END OF AC_QUANTITY
  3508. }
  3509. //====================================== Stop Transaction Time =====================================================
  3510. struct timeval tmnow;
  3511. struct tm *tm;
  3512. char buf[28];//, usec_buf[6];
  3513. gettimeofday(&tmnow, NULL);
  3514. time_t t;
  3515. t = time(NULL);
  3516. /*UTC time and date*/
  3517. tm = gmtime(&t);
  3518. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3519. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  3520. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  3521. random_uuid(guid);
  3522. /***********************************transactionData******************************************************/
  3523. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  3524. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  3525. //=================================
  3526. // Transaction_Begin
  3527. //=================================
  3528. //============================================ Energy.Active.Import.Interval ================================
  3529. //idx_sample=0;
  3530. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  3531. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  3532. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  3533. 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*/]);
  3534. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3535. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  3536. {
  3537. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  3538. }
  3539. else
  3540. {
  3541. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  3542. }
  3543. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  3544. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3545. //=================================
  3546. // Transaction_End
  3547. //=================================
  3548. // ================================= Current.Import L1 ===============================================
  3549. //idx_sample=1;
  3550. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  3551. if(gunType[gun_index] == 'J')
  3552. {
  3553. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3554. {
  3555. tempIndex = ((gun_index==2) ? 1: 0);
  3556. }
  3557. else
  3558. {
  3559. tempIndex = gun_index;
  3560. }
  3561. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3562. {
  3563. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3564. {
  3565. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3566. }
  3567. }// End of for CHAdeMO_QUANTITY
  3568. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3569. }
  3570. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3571. {
  3572. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3573. {
  3574. tempIndex = ((gun_index==2) ? 1: 0);
  3575. }
  3576. else
  3577. {
  3578. tempIndex = gun_index;
  3579. }
  3580. for (int index = 0; index < CCS_QUANTITY; index++)
  3581. {
  3582. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3583. {
  3584. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3585. }
  3586. }// End of for CCS_QUANTITY
  3587. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3588. }
  3589. else if(gunType[gun_index] == 'G')
  3590. {
  3591. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3592. {
  3593. tempIndex = ((gun_index==2) ? 1: 0);
  3594. }
  3595. else
  3596. {
  3597. tempIndex = gun_index;
  3598. }
  3599. for (int index = 0; index < GB_QUANTITY; index++)
  3600. {
  3601. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3602. {
  3603. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3604. }
  3605. }// End of for GB_QUANTITY
  3606. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3607. }
  3608. else if(gunType[gun_index] == 'O')
  3609. {
  3610. tempIndex = gun_index;
  3611. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3612. {
  3613. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3614. {
  3615. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3616. }
  3617. }
  3618. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3619. }
  3620. else
  3621. {
  3622. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3623. {
  3624. tempIndex = 2;
  3625. }
  3626. else
  3627. {
  3628. tempIndex = gun_index;
  3629. }
  3630. for (int index = 0; index < AC_QUANTITY; index++)
  3631. {
  3632. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3633. {
  3634. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  3635. }
  3636. }// End of for AC_QUANTITY
  3637. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  3638. }
  3639. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3640. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  3641. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  3642. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  3643. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3644. // ================================= Energy.Active.Import.Interval ==============================================
  3645. //idx_sample=2;
  3646. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3647. if(gunType[gun_index] == 'J')
  3648. {
  3649. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3650. {
  3651. tempIndex = ((gun_index==2) ? 1: 0);
  3652. }
  3653. else
  3654. {
  3655. tempIndex = gun_index;
  3656. }
  3657. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3658. {
  3659. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3660. {
  3661. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3662. }
  3663. }// END OF CHAdeMO_QUANTITY
  3664. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3665. }
  3666. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3667. {
  3668. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3669. {
  3670. tempIndex = ((gun_index==2) ? 1: 0);
  3671. }
  3672. else
  3673. {
  3674. tempIndex = gun_index;
  3675. }
  3676. for (int index = 0; index < CCS_QUANTITY; index++)
  3677. {
  3678. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3679. {
  3680. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3681. }
  3682. }// END OF CCS_QUANTITY
  3683. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3684. }
  3685. else if(gunType[gun_index] == 'G')
  3686. {
  3687. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3688. {
  3689. tempIndex = ((gun_index==2) ? 1: 0);
  3690. }
  3691. else
  3692. {
  3693. tempIndex = gun_index;
  3694. }
  3695. for (int index = 0; index < GB_QUANTITY; index++)
  3696. {
  3697. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3698. {
  3699. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3700. }
  3701. }// END OF GB_QUANTITY
  3702. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3703. }
  3704. else if(gunType[gun_index] == 'O')
  3705. {
  3706. tempIndex = gun_index;
  3707. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3708. {
  3709. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3710. {
  3711. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3712. }
  3713. }
  3714. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3715. }
  3716. else
  3717. {
  3718. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3719. {
  3720. tempIndex = 2;
  3721. }
  3722. else
  3723. {
  3724. tempIndex = gun_index;
  3725. }
  3726. for (int index = 0; index < AC_QUANTITY; index++)
  3727. {
  3728. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3729. {
  3730. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3731. }
  3732. }// END OF AC_QUANTITY
  3733. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  3734. }
  3735. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3736. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  3737. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  3738. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  3739. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3740. //=================================== Power.Active.Import ==================================================
  3741. //idx_sample=3;
  3742. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3743. if(gunType[gun_index] == 'J')
  3744. {
  3745. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3746. {
  3747. tempIndex = ((gun_index==2) ? 1: 0);
  3748. }
  3749. else
  3750. {
  3751. tempIndex = gun_index;
  3752. }
  3753. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3754. {
  3755. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3756. {
  3757. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3758. }
  3759. } // End for CHAdeMO_QUANTITY
  3760. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3761. }
  3762. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3763. {
  3764. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3765. {
  3766. tempIndex = ((gun_index==2) ? 1: 0);
  3767. }
  3768. else
  3769. {
  3770. tempIndex = gun_index;
  3771. }
  3772. for (int index = 0; index < CCS_QUANTITY; index++)
  3773. {
  3774. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3775. {
  3776. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3777. }
  3778. } // END for CCS_QUANTITY
  3779. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3780. }
  3781. else if(gunType[gun_index] == 'G')
  3782. {
  3783. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3784. {
  3785. tempIndex = ((gun_index==2) ? 1: 0);
  3786. }
  3787. else
  3788. {
  3789. tempIndex = gun_index;
  3790. }
  3791. for (int index = 0; index < GB_QUANTITY; index++)
  3792. {
  3793. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3794. {
  3795. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3796. }
  3797. }// END for GB_QUANTITY
  3798. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3799. }
  3800. else if(gunType[gun_index] == 'O')
  3801. {
  3802. tempIndex = gun_index;
  3803. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3804. {
  3805. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3806. {
  3807. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3808. }
  3809. }
  3810. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3811. }
  3812. else
  3813. {
  3814. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3815. {
  3816. tempIndex = 2;
  3817. }
  3818. else
  3819. {
  3820. tempIndex = gun_index;
  3821. }
  3822. for (int index = 0; index < AC_QUANTITY; index++)
  3823. {
  3824. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3825. {
  3826. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3827. }
  3828. } // END for AC_QUANTITY
  3829. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  3830. }
  3831. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3832. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  3833. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  3834. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  3835. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  3836. //============================ Voltage L1 ====================================
  3837. //idx_sample=4;
  3838. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3839. if(gunType[gun_index] == 'J')
  3840. {
  3841. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3842. {
  3843. tempIndex = ((gun_index==2) ? 1: 0);
  3844. }
  3845. else
  3846. {
  3847. tempIndex = gun_index;
  3848. }
  3849. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3850. {
  3851. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3852. {
  3853. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3854. }
  3855. } // END OF FOR CHAdeMO_QUANTITY
  3856. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3857. }
  3858. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3859. {
  3860. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3861. {
  3862. tempIndex = ((gun_index==2) ? 1: 0);
  3863. }
  3864. else
  3865. {
  3866. tempIndex = gun_index;
  3867. }
  3868. for (int index = 0; index < CCS_QUANTITY; index++)
  3869. {
  3870. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3871. {
  3872. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3873. }
  3874. } // END OF FOR CCS_QUANTITY
  3875. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3876. }
  3877. else if(gunType[gun_index] == 'G')
  3878. {
  3879. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3880. {
  3881. tempIndex = ((gun_index==2) ? 1: 0);
  3882. }
  3883. else
  3884. {
  3885. tempIndex = gun_index;
  3886. }
  3887. for (int index = 0; index < GB_QUANTITY; index++)
  3888. {
  3889. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3890. {
  3891. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3892. }
  3893. } // END OF FOR GB_QUANTITY
  3894. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3895. }
  3896. else if(gunType[gun_index] == 'O')
  3897. {
  3898. tempIndex = gun_index;
  3899. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3900. {
  3901. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3902. {
  3903. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3904. }
  3905. }
  3906. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3907. }
  3908. else
  3909. {
  3910. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3911. {
  3912. tempIndex = 2;
  3913. }
  3914. else
  3915. {
  3916. tempIndex = gun_index;
  3917. }
  3918. for (int index = 0; index < AC_QUANTITY; index++)
  3919. {
  3920. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3921. {
  3922. 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
  3923. }
  3924. } // END OF FOR AC_QUANTITY
  3925. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  3926. }
  3927. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3928. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  3929. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  3930. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  3931. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3932. //====================== End SoC ================================
  3933. //idx_sample=5;
  3934. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3935. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  3936. {
  3937. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != 'O'))
  3938. {
  3939. tempIndex = ((gun_index==2) ? 1: 0);
  3940. }
  3941. else
  3942. {
  3943. tempIndex = gun_index;
  3944. }
  3945. if(gunType[gun_index] == 'J')
  3946. {
  3947. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3948. {
  3949. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3950. {
  3951. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  3952. }
  3953. }
  3954. }
  3955. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3956. {
  3957. for (int index = 0; index < CCS_QUANTITY; index++)
  3958. {
  3959. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3960. {
  3961. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  3962. }
  3963. }
  3964. }
  3965. else if(gunType[gun_index] == 'G')
  3966. {
  3967. for (int index = 0; index < GB_QUANTITY; index++)
  3968. {
  3969. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3970. {
  3971. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  3972. }
  3973. }
  3974. }
  3975. else if(gunType[gun_index] == 'O')
  3976. {
  3977. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3978. {
  3979. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3980. {
  3981. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  3982. }
  3983. }
  3984. }
  3985. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3986. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  3987. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  3988. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  3989. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  3990. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  3991. } // END FOR DC CASE
  3992. // ================================= Current.Import L2 ===============================================
  3993. //idx_sample=6;
  3994. // AC 3 phse L2 current
  3995. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3996. {
  3997. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3998. {
  3999. tempIndex = 2;
  4000. }
  4001. else
  4002. {
  4003. tempIndex = gun_index;
  4004. }
  4005. for (int index = 0; index < AC_QUANTITY; index++)
  4006. {
  4007. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4008. {
  4009. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  4010. }
  4011. }// End of for AC_QUANTITY
  4012. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  4013. }
  4014. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4015. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  4016. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  4017. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  4018. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4019. // ================================= Current.Import L3 ===============================================
  4020. //idx_sample=7;
  4021. // AC 3 phse L3 current
  4022. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  4023. {
  4024. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4025. {
  4026. tempIndex = 2;
  4027. }
  4028. else
  4029. {
  4030. tempIndex = gun_index;
  4031. }
  4032. for (int index = 0; index < AC_QUANTITY; index++)
  4033. {
  4034. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4035. {
  4036. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  4037. }
  4038. }// End of for AC_QUANTITY
  4039. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  4040. }
  4041. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4042. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  4043. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  4044. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  4045. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4046. //============================ Voltage L2 ====================================
  4047. //idx_sample=8;
  4048. // AC 3 phse L2 voltage
  4049. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  4050. {
  4051. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4052. {
  4053. tempIndex = 2;
  4054. }
  4055. else
  4056. {
  4057. tempIndex = gun_index;
  4058. }
  4059. for (int index = 0; index < AC_QUANTITY; index++)
  4060. {
  4061. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4062. {
  4063. 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
  4064. }
  4065. } // END OF FOR AC_QUANTITY
  4066. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  4067. }
  4068. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4069. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  4070. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  4071. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  4072. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4073. //============================ Voltage L3 ====================================
  4074. //idx_sample=8;
  4075. // AC 3 phse L3 voltage
  4076. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  4077. {
  4078. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4079. {
  4080. tempIndex = 2;
  4081. }
  4082. else
  4083. {
  4084. tempIndex = gun_index;
  4085. }
  4086. for (int index = 0; index < AC_QUANTITY; index++)
  4087. {
  4088. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4089. {
  4090. 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
  4091. }
  4092. } // END OF FOR AC_QUANTITY
  4093. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  4094. }
  4095. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4096. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  4097. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  4098. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  4099. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4100. //====================== Start SoC ================================
  4101. //idx_sample=10;
  4102. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4103. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  4104. {
  4105. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != 'O'))
  4106. {
  4107. tempIndex = ((gun_index==2) ? 1: 0);
  4108. }
  4109. else
  4110. {
  4111. tempIndex = gun_index;
  4112. }
  4113. if(gunType[gun_index] == 'J')
  4114. {
  4115. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4116. {
  4117. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4118. {
  4119. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  4120. }
  4121. }
  4122. }
  4123. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4124. {
  4125. for (int index = 0; index < CCS_QUANTITY; index++)
  4126. {
  4127. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4128. {
  4129. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  4130. }
  4131. }
  4132. }
  4133. else if(gunType[gun_index] == 'G')
  4134. {
  4135. for (int index = 0; index < GB_QUANTITY; index++)
  4136. {
  4137. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4138. {
  4139. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  4140. }
  4141. }
  4142. }
  4143. else if(gunType[gun_index] == 'O')
  4144. {
  4145. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4146. {
  4147. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4148. {
  4149. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  4150. }
  4151. }
  4152. }
  4153. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4154. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  4155. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4156. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  4157. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  4158. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4159. } // END FOR DC CASE
  4160. //================================================ Message create ====================================================
  4161. json_object *StopTransaction = json_object_new_object();
  4162. json_object *transactionDatas = json_object_new_array();
  4163. json_object *sampledValues = json_object_new_array();
  4164. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  4165. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  4166. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  4167. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  4168. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  4169. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  4170. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  4171. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  4172. {
  4173. json_object *transactionData = json_object_new_object();
  4174. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  4175. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  4176. {
  4177. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  4178. {
  4179. json_object *sampledValue = json_object_new_object();
  4180. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  4181. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  4182. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  4183. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  4184. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  4185. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  4186. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  4187. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  4188. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  4189. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  4190. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  4191. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  4192. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  4193. json_object_array_add(sampledValues, sampledValue);
  4194. }
  4195. }
  4196. json_object_object_add(transactionData, "sampledValue", sampledValues);
  4197. json_object_array_add(transactionDatas, transactionData);
  4198. }
  4199. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  4200. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  4201. ,MESSAGE_TYPE_CALL
  4202. ,guid
  4203. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  4204. json_object_put(StopTransaction);
  4205. #if 1 // for TempStopTransaction
  4206. //Delete TempStopTransaction
  4207. if((access(TempStopTransaction,F_OK))!=-1)
  4208. {
  4209. remove(TempStopTransaction); // remove file "TempStopTransaction"
  4210. }
  4211. #endif
  4212. #if 1
  4213. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4214. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4215. {
  4216. result = PASS;
  4217. //DEBUG_INFO("StopTransaction mapitem pass\n");
  4218. }
  4219. #endif
  4220. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4221. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4222. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  4223. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  4224. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4225. {
  4226. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  4227. }
  4228. //for test
  4229. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4230. return result;
  4231. }
  4232. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  4233. {
  4234. mtrace();
  4235. int result = FAIL;
  4236. char guid[37]={0};
  4237. char tempdata[65]={0};
  4238. int tempIndex = 0;
  4239. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4240. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4241. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  4242. //set value
  4243. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4244. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ((strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging") != NULL) ? ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId : -1);
  4245. random_uuid(guid);
  4246. //UTC Date time
  4247. struct timeval tmnow;
  4248. struct tm *tm;
  4249. char buf[28];//, usec_buf[6];
  4250. gettimeofday(&tmnow, NULL);
  4251. time_t t;
  4252. t = time(NULL);
  4253. /*UTC time and date*/
  4254. tm = gmtime(&t);
  4255. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4256. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4257. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4258. //idx_sample=0;
  4259. //********************************(1)Current.Import L1************************************************/
  4260. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4261. if(gunType[gun_index] == 'J')
  4262. {
  4263. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4264. {
  4265. tempIndex = ((gun_index==2) ? 1: 0);
  4266. }
  4267. else
  4268. {
  4269. tempIndex = gun_index;
  4270. }
  4271. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4272. {
  4273. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4274. {
  4275. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4276. }
  4277. }
  4278. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4279. }
  4280. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4281. {
  4282. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4283. {
  4284. tempIndex = ((gun_index==2) ? 1: 0);
  4285. }
  4286. else
  4287. {
  4288. tempIndex = gun_index;
  4289. }
  4290. for (int index = 0; index < CCS_QUANTITY; index++)
  4291. {
  4292. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4293. {
  4294. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4295. }
  4296. }
  4297. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4298. }
  4299. else if(gunType[gun_index] == 'G')
  4300. {
  4301. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4302. {
  4303. tempIndex = ((gun_index==2) ? 1: 0);
  4304. }
  4305. else
  4306. {
  4307. tempIndex = gun_index;
  4308. }
  4309. for (int index = 0; index < GB_QUANTITY; index++)
  4310. {
  4311. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4312. {
  4313. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4314. }
  4315. }
  4316. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4317. }
  4318. else if(gunType[gun_index] == 'O')
  4319. {
  4320. tempIndex = gun_index;
  4321. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4322. {
  4323. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4324. {
  4325. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  4326. }
  4327. }
  4328. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4329. }
  4330. else
  4331. {
  4332. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4333. {
  4334. tempIndex = 2;
  4335. }
  4336. else
  4337. {
  4338. tempIndex = gun_index;
  4339. }
  4340. for (int index = 0; index < AC_QUANTITY; index++)
  4341. {
  4342. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4343. {
  4344. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4345. }
  4346. }
  4347. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4348. }
  4349. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4350. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4351. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4352. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4353. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4354. //idx_sample=1;
  4355. //********************************(2)Energy.Active.Import.Register ************************************************/
  4356. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4357. if(gunType[gun_index] == 'J')
  4358. {
  4359. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4360. {
  4361. tempIndex = ((gun_index==2) ? 1: 0);
  4362. }
  4363. else
  4364. {
  4365. tempIndex = gun_index;
  4366. }
  4367. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4368. {
  4369. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4370. {
  4371. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4372. }
  4373. }
  4374. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4375. }
  4376. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4377. {
  4378. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4379. {
  4380. tempIndex = ((gun_index==2) ? 1: 0);
  4381. }
  4382. else
  4383. {
  4384. tempIndex = gun_index;
  4385. }
  4386. for (int index = 0; index < CCS_QUANTITY; index++)
  4387. {
  4388. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4389. {
  4390. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4391. }
  4392. }
  4393. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4394. }
  4395. else if(gunType[gun_index] == 'G')
  4396. {
  4397. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4398. {
  4399. tempIndex = ((gun_index==2) ? 1: 0);
  4400. }
  4401. else
  4402. {
  4403. tempIndex = gun_index;
  4404. }
  4405. for (int index = 0; index < GB_QUANTITY; index++)
  4406. {
  4407. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4408. {
  4409. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4410. }
  4411. }
  4412. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4413. }
  4414. else if(gunType[gun_index] == 'O')
  4415. {
  4416. tempIndex = gun_index;
  4417. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4418. {
  4419. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4420. {
  4421. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  4422. }
  4423. }
  4424. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4425. }
  4426. else
  4427. {
  4428. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4429. {
  4430. tempIndex = 2;
  4431. }
  4432. else
  4433. {
  4434. tempIndex = gun_index;
  4435. }
  4436. for (int index = 0; index < AC_QUANTITY; index++)
  4437. {
  4438. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4439. {
  4440. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  4441. }
  4442. }
  4443. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4444. }
  4445. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  4446. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  4447. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  4448. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  4449. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4450. //idx_sample=2;
  4451. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  4452. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4453. if(gunType[gun_index] == 'J')
  4454. {
  4455. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4456. {
  4457. tempIndex = ((gun_index==2) ? 1: 0);
  4458. }
  4459. else
  4460. {
  4461. tempIndex = gun_index;
  4462. }
  4463. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4464. {
  4465. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4466. {
  4467. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  4468. }
  4469. } // END OF FOR CHAdeMO_QUANTITY
  4470. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4471. }
  4472. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4473. {
  4474. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4475. {
  4476. tempIndex = ((gun_index==2) ? 1: 0);
  4477. }
  4478. else
  4479. {
  4480. tempIndex = gun_index;
  4481. }
  4482. for (int index = 0; index < CCS_QUANTITY; index++)
  4483. {
  4484. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4485. {
  4486. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  4487. }
  4488. } // END OF CCS_QUANTITY
  4489. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4490. }
  4491. else if(gunType[gun_index] == 'G')
  4492. {
  4493. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4494. {
  4495. tempIndex = ((gun_index==2) ? 1: 0);
  4496. }
  4497. else
  4498. {
  4499. tempIndex = gun_index;
  4500. }
  4501. for (int index = 0; index < GB_QUANTITY; index++)
  4502. {
  4503. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4504. {
  4505. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  4506. }
  4507. } // END OF GB_QUANTITY
  4508. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4509. }
  4510. else if(gunType[gun_index] == 'O')
  4511. {
  4512. tempIndex = gun_index;
  4513. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4514. {
  4515. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4516. {
  4517. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  4518. }
  4519. }
  4520. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4521. }
  4522. else
  4523. {
  4524. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4525. {
  4526. tempIndex = 2;
  4527. }
  4528. else
  4529. {
  4530. tempIndex = gun_index;
  4531. }
  4532. for (int index = 0; index < AC_QUANTITY; index++)
  4533. {
  4534. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4535. {
  4536. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  4537. }
  4538. }
  4539. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  4540. }
  4541. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  4542. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  4543. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  4544. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  4545. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4546. //idx_sample=3;
  4547. //********************************(4)Power.Active.Import************************************************/
  4548. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4549. if(gunType[gun_index] == 'J')
  4550. {
  4551. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4552. {
  4553. tempIndex = ((gun_index==2) ? 1: 0);
  4554. }
  4555. else
  4556. {
  4557. tempIndex = gun_index;
  4558. }
  4559. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4560. {
  4561. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4562. {
  4563. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  4564. }
  4565. } // END OF FOR
  4566. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4567. }
  4568. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4569. {
  4570. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4571. {
  4572. tempIndex = ((gun_index==2) ? 1: 0);
  4573. }
  4574. else
  4575. {
  4576. tempIndex = gun_index;
  4577. }
  4578. for (int index = 0; index < CCS_QUANTITY; index++)
  4579. {
  4580. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4581. {
  4582. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  4583. }
  4584. }
  4585. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4586. }
  4587. else if(gunType[gun_index] == 'G')
  4588. {
  4589. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4590. {
  4591. tempIndex = ((gun_index==2) ? 1: 0);
  4592. }
  4593. else
  4594. {
  4595. tempIndex = gun_index;
  4596. }
  4597. for (int index = 0; index < GB_QUANTITY; index++)
  4598. {
  4599. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4600. {
  4601. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4602. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  4603. }
  4604. }
  4605. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4606. }
  4607. else if(gunType[gun_index] == 'O')
  4608. {
  4609. tempIndex = gun_index;
  4610. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4611. {
  4612. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4613. {
  4614. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4615. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  4616. }
  4617. }
  4618. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4619. }
  4620. else
  4621. {
  4622. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4623. {
  4624. tempIndex = 2;
  4625. }
  4626. else
  4627. {
  4628. tempIndex = gun_index;
  4629. }
  4630. for (int index = 0; index < AC_QUANTITY; index++)
  4631. {
  4632. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4633. {
  4634. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  4635. }
  4636. }
  4637. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  4638. }
  4639. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  4640. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  4641. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  4642. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  4643. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  4644. //idx_sample=4;
  4645. //***********************************************(5)VOLTAGE L1******************************************************/
  4646. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4647. if(gunType[gun_index] == 'J')
  4648. {
  4649. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4650. {
  4651. tempIndex = ((gun_index==2) ? 1: 0);
  4652. }
  4653. else
  4654. {
  4655. tempIndex = gun_index;
  4656. }
  4657. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4658. {
  4659. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4660. {
  4661. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  4662. }
  4663. }
  4664. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4665. }
  4666. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4667. {
  4668. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4669. {
  4670. tempIndex = ((gun_index==2) ? 1: 0);
  4671. }
  4672. else
  4673. {
  4674. tempIndex = gun_index;
  4675. }
  4676. for (int index = 0; index < CCS_QUANTITY; index++)
  4677. {
  4678. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4679. {
  4680. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  4681. }
  4682. }
  4683. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4684. }
  4685. else if(gunType[gun_index] == 'G')
  4686. {
  4687. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4688. {
  4689. tempIndex = ((gun_index==2) ? 1: 0);
  4690. }
  4691. else
  4692. {
  4693. tempIndex = gun_index;
  4694. }
  4695. for (int index = 0; index < GB_QUANTITY; index++)
  4696. {
  4697. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4698. {
  4699. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  4700. }
  4701. }
  4702. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4703. }
  4704. else if(gunType[gun_index] == 'O')
  4705. {
  4706. tempIndex = gun_index;
  4707. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4708. {
  4709. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4710. {
  4711. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  4712. }
  4713. }
  4714. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4715. }
  4716. else
  4717. {
  4718. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4719. {
  4720. tempIndex = 2;
  4721. }
  4722. else
  4723. {
  4724. tempIndex = gun_index;
  4725. }
  4726. for (int index = 0; index < AC_QUANTITY; index++)
  4727. {
  4728. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4729. {
  4730. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  4731. }
  4732. }
  4733. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  4734. }
  4735. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  4736. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  4737. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  4738. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  4739. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4740. //***********************************************(6)SOC******************************************************/
  4741. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  4742. {
  4743. //idx_sample=5;
  4744. //sampledValue = NULL;
  4745. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != 'O'))
  4746. {
  4747. tempIndex = ((gun_index==2) ? 1: 0);
  4748. }
  4749. else
  4750. {
  4751. tempIndex = gun_index;
  4752. }
  4753. if(gunType[gun_index] == 'J')
  4754. {
  4755. //tempIndex = ((gun_index==2) ? 1: 0);
  4756. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4757. {
  4758. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4759. {
  4760. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  4761. }
  4762. }
  4763. }
  4764. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4765. {
  4766. //tempIndex = ((gun_index==2) ? 1: 0);
  4767. for (int index = 0; index < CCS_QUANTITY; index++)
  4768. {
  4769. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4770. {
  4771. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  4772. }
  4773. }
  4774. }
  4775. else if(gunType[gun_index] == 'G')
  4776. {
  4777. //tempIndex = ((gun_index==2) ? 1: 0);
  4778. for (int index = 0; index < GB_QUANTITY; index++)
  4779. {
  4780. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4781. {
  4782. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  4783. }
  4784. }
  4785. }
  4786. else if(gunType[gun_index] == 'O')
  4787. {
  4788. //tempIndex = ((gun_index==2) ? 1: 0);
  4789. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4790. {
  4791. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4792. {
  4793. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  4794. }
  4795. }
  4796. }
  4797. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  4798. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  4799. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  4800. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  4801. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  4802. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  4803. }
  4804. //********************************(7)Current.Import L2************************************************/
  4805. // Only for AC 3 phase
  4806. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4807. {
  4808. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4809. {
  4810. tempIndex = 2;
  4811. }
  4812. else
  4813. {
  4814. tempIndex = gun_index;
  4815. }
  4816. for (int index = 0; index < AC_QUANTITY; index++)
  4817. {
  4818. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4819. {
  4820. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  4821. }
  4822. }
  4823. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  4824. }
  4825. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  4826. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  4827. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  4828. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  4829. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4830. //********************************(8)Current.Import L3************************************************/
  4831. // Only for AC 3 phase
  4832. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4833. {
  4834. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4835. {
  4836. tempIndex = 2;
  4837. }
  4838. else
  4839. {
  4840. tempIndex = gun_index;
  4841. }
  4842. for (int index = 0; index < AC_QUANTITY; index++)
  4843. {
  4844. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4845. {
  4846. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  4847. }
  4848. }
  4849. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  4850. }
  4851. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  4852. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  4853. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  4854. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  4855. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4856. //***********************************************(9)VOLTAGE L2******************************************************/
  4857. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4858. {
  4859. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4860. {
  4861. tempIndex = 2;
  4862. }
  4863. else
  4864. {
  4865. tempIndex = gun_index;
  4866. }
  4867. for (int index = 0; index < AC_QUANTITY; index++)
  4868. {
  4869. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4870. {
  4871. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  4872. }
  4873. }
  4874. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  4875. }
  4876. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  4877. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  4878. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  4879. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  4880. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4881. //***********************************************(10)VOLTAGE L3******************************************************/
  4882. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4883. {
  4884. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4885. {
  4886. tempIndex = 2;
  4887. }
  4888. else
  4889. {
  4890. tempIndex = gun_index;
  4891. }
  4892. for (int index = 0; index < AC_QUANTITY; index++)
  4893. {
  4894. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4895. {
  4896. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  4897. }
  4898. }
  4899. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  4900. }
  4901. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  4902. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  4903. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  4904. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  4905. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4906. // Message create ====================================================================================================
  4907. if(TRUE)
  4908. {
  4909. json_object *MeterValueReq = json_object_new_object();
  4910. json_object *MeterValues = json_object_new_array();
  4911. json_object *sampledValues = json_object_new_array();
  4912. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  4913. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  4914. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  4915. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  4916. {
  4917. json_object *MeterValue = json_object_new_object();
  4918. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  4919. {
  4920. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  4921. {
  4922. json_object *sampledValue = json_object_new_object();
  4923. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  4924. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  4925. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  4926. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  4927. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  4928. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  4929. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  4930. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  4931. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  4932. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  4933. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  4934. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  4935. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  4936. json_object_array_add(sampledValues, sampledValue);
  4937. }
  4938. }
  4939. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  4940. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  4941. json_object_array_add(MeterValues, MeterValue);
  4942. }
  4943. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  4944. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  4945. ,gun_index + 1
  4946. ,MESSAGE_TYPE_CALL
  4947. ,guid
  4948. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  4949. json_object_put(MeterValueReq);
  4950. }
  4951. // Put request guid to hash map
  4952. sprintf(tempdata, "MeterValues,%d", (gun_index));
  4953. 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*/)
  4954. {
  4955. result = PASS;
  4956. //DEBUG_INFO("MeterValues mapitem pass\n");
  4957. }
  4958. if((dataType != ReadingContext_Trigger) &&
  4959. (dataType != ReadingContext_Sample_Clock) &&
  4960. (ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1))
  4961. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  4962. else
  4963. {
  4964. if(FirstHeartBeat)
  4965. LWS_Send(queuedata +2);
  4966. }
  4967. return result;
  4968. }
  4969. //==========================================
  4970. // send confirm routine
  4971. //==========================================
  4972. int sendCancelReservationConfirmation(char *uuid,char *payload)
  4973. {
  4974. mtrace();
  4975. int result = FAIL;
  4976. char message[100]={0};
  4977. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  4978. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4979. LWS_Send(message);
  4980. result = TRUE;
  4981. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  4982. return result;
  4983. }
  4984. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  4985. {
  4986. mtrace();
  4987. int result = FAIL;
  4988. char message[100]={0};
  4989. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  4990. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4991. LWS_Send(message);
  4992. result = TRUE;
  4993. return result;
  4994. }
  4995. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  4996. {
  4997. mtrace();
  4998. int result = FAIL;
  4999. char message[100]={0};
  5000. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  5001. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5002. LWS_Send(message);
  5003. result = TRUE;
  5004. return result;
  5005. }
  5006. int sendClearCacheConfirmation(char *uuid,char *payload)
  5007. {
  5008. mtrace();
  5009. int result = FAIL;
  5010. char message[500]={0};
  5011. DEBUG_INFO("sendClearCacheConfirmation...\n");
  5012. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5013. LWS_Send(message);
  5014. return result;
  5015. }
  5016. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  5017. {
  5018. mtrace();
  5019. int result = FAIL;
  5020. char message[500]={0};
  5021. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  5022. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5023. LWS_Send(message);
  5024. return result;
  5025. }
  5026. int sendDataTransferConfirmation(char *uuid,char *payload)
  5027. {
  5028. mtrace();
  5029. char statusStr[20]={0};
  5030. char dataStr[10]={0};
  5031. char sstr[20]={0};
  5032. int c = 0;
  5033. char *loc;
  5034. int result = FAIL;
  5035. DEBUG_INFO("sendDataTransferConfirmation...\n");
  5036. /**********************status**************************/
  5037. loc = strstr(payload, "status");
  5038. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5039. c = 0;
  5040. while (loc[3+strlen("status")+c] != '\"')
  5041. {
  5042. sstr[c] = loc[3+strlen("status")+c];
  5043. c++;
  5044. }
  5045. sstr[c] = '\0';
  5046. strcpy(statusStr, sstr);
  5047. /**********************data**************************/
  5048. loc = strstr(payload, "data");
  5049. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5050. c = 0;
  5051. while (loc[3+strlen("data")+c] != '\"')
  5052. {
  5053. sstr[c] = loc[3+strlen("data")+c];
  5054. c++;
  5055. }
  5056. sstr[c] = '\0';
  5057. strcpy(dataStr, sstr);
  5058. return result;
  5059. }
  5060. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  5061. {
  5062. mtrace();
  5063. int result = FAIL;
  5064. char message[1000]={0};
  5065. int CompositeScheduleIndex = 0;
  5066. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  5067. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  5068. if(nPeriod == 0)
  5069. {
  5070. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  5071. {
  5072. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  5073. ,MESSAGE_TYPE_CALLRESULT
  5074. ,uuid
  5075. ,payload
  5076. ,connectorIdInt);
  5077. }
  5078. else
  5079. {
  5080. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  5081. ,MESSAGE_TYPE_CALLRESULT
  5082. ,uuid
  5083. ,payload
  5084. ,connectorIdInt
  5085. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5086. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5087. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5088. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  5089. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  5090. }
  5091. }
  5092. else
  5093. {
  5094. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  5095. ,MESSAGE_TYPE_CALLRESULT
  5096. ,uuid
  5097. ,payload
  5098. ,connectorIdInt
  5099. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5100. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5101. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5102. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  5103. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  5104. {
  5105. if (idx_sample == 0)
  5106. {
  5107. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5108. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5109. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5110. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5111. }
  5112. else
  5113. {
  5114. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5115. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5116. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5117. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5118. }
  5119. }
  5120. sprintf(message + strlen(message), "]}}]");
  5121. }
  5122. LWS_Send(message);
  5123. result = TRUE;
  5124. return result;
  5125. }
  5126. int sendGetConfigurationConfirmation(char *uuid)
  5127. {
  5128. mtrace();
  5129. int result = FAIL;
  5130. int MaxKeySupported = 0;
  5131. int sentConfigurationNumber= 0;
  5132. int sentunConfigurationNumber= 0;
  5133. char message[4000]={0};
  5134. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  5135. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  5136. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  5137. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  5138. ,MESSAGE_TYPE_CALLRESULT
  5139. ,uuid );
  5140. //configuration key
  5141. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  5142. {
  5143. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  5144. {
  5145. if (sentConfigurationNumber == 0)
  5146. {
  5147. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5148. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5149. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5150. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5151. }
  5152. else
  5153. {
  5154. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5155. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5156. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5157. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5158. }
  5159. sentConfigurationNumber = sentConfigurationNumber + 1;
  5160. }
  5161. }
  5162. sprintf(message + strlen(message), "]");
  5163. if(UnknownKeynum != 0)
  5164. {
  5165. sprintf(message + strlen(message), ",\"unknownKey\":[");
  5166. //unkown key
  5167. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  5168. {
  5169. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  5170. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  5171. if(sentunConfigurationNumber == 0)
  5172. {
  5173. sprintf(message + strlen(message), "\"%s\""
  5174. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5175. }
  5176. else
  5177. {
  5178. sprintf(message + strlen(message), ",\"%s\""
  5179. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5180. }
  5181. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  5182. }
  5183. sprintf(message + strlen(message), "]");
  5184. }
  5185. sprintf(message + strlen(message), "}]");
  5186. LWS_Send(message);
  5187. return result;
  5188. }
  5189. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  5190. {
  5191. mtrace();
  5192. int result = FAIL;
  5193. char message[400]={0};
  5194. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  5195. if(strcmp(payload,"")==0)
  5196. {
  5197. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5198. }
  5199. else
  5200. {
  5201. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5202. }
  5203. LWS_Send(message);
  5204. result = TRUE;
  5205. return result;
  5206. }
  5207. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  5208. {
  5209. mtrace();
  5210. int result = FAIL;
  5211. char message[80]={0};
  5212. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  5213. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  5214. LWS_Send(message);
  5215. result = TRUE;
  5216. return result;
  5217. }
  5218. int sendRemoteStartConfirmation(char *uuid,char *payload)
  5219. {
  5220. mtrace();
  5221. int result = FAIL;
  5222. char message[80]={0};
  5223. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  5224. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5225. LWS_Send(message);
  5226. result = TRUE;
  5227. return result;
  5228. }
  5229. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5230. {
  5231. mtrace();
  5232. int result = FAIL;
  5233. char message[80]={0};
  5234. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5235. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5236. LWS_Send(message);
  5237. result = TRUE;
  5238. return result;
  5239. }
  5240. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5241. {
  5242. mtrace();
  5243. int result = FAIL;
  5244. char message[80]={0};
  5245. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5246. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  5247. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5248. LWS_Send(message);
  5249. result = TRUE;
  5250. return result;
  5251. }
  5252. int sendResetConfirmation(char *uuid,char *payload)
  5253. {
  5254. mtrace();
  5255. int result = FAIL;
  5256. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  5257. char message[80]={0};
  5258. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  5259. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5260. LWS_Send(message);
  5261. result = TRUE;
  5262. return result;
  5263. }
  5264. int sendSendLocalListConfirmation(char *uuid,char *payload)
  5265. {
  5266. mtrace();
  5267. int result = FAIL;
  5268. char message[500]={0};
  5269. // [ 3, "1571284266109", { "status": "Accepted" } ]
  5270. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5271. LWS_Send(message);
  5272. result = TRUE;
  5273. return result;
  5274. }
  5275. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  5276. {
  5277. mtrace();
  5278. int result = FAIL;
  5279. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  5280. char message[80]={0};
  5281. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  5282. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5283. LWS_Send(message);
  5284. result = TRUE;
  5285. return result;
  5286. }
  5287. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  5288. {
  5289. mtrace();
  5290. int result = FAIL;
  5291. char message[80]={0};
  5292. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  5293. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5294. LWS_Send(message);
  5295. result = TRUE;
  5296. return result;
  5297. }
  5298. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  5299. {
  5300. mtrace();
  5301. int result = FAIL;
  5302. char message[80]={0};
  5303. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5304. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  5305. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5306. LWS_Send(message);
  5307. result = TRUE;
  5308. return result;
  5309. }
  5310. int sendUpdateFirmwareConfirmation(char *uuid)
  5311. {
  5312. mtrace();
  5313. int result = FAIL;
  5314. char message[60]={0};
  5315. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5316. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  5317. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5318. LWS_Send(message);
  5319. result = TRUE;
  5320. return result;
  5321. }
  5322. //==========================================
  5323. // send CallError routine
  5324. //==========================================
  5325. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  5326. {
  5327. mtrace();
  5328. char message[220]={0};
  5329. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  5330. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  5331. LWS_Send(message);
  5332. }
  5333. //==========================================
  5334. // Handle server request routine Start
  5335. //==========================================
  5336. int handleCancelReservationRequest(char *uuid, char *payload)
  5337. {
  5338. mtrace();
  5339. int result = FAIL;
  5340. int gunNO = 0;
  5341. int reservationIdInt = -1;
  5342. char comfirmstr[20];
  5343. DEBUG_INFO("handleCancelReservationRequest...\n");
  5344. json_object *CancelReservation;
  5345. CancelReservation = json_tokener_parse(payload);
  5346. if(!is_error(CancelReservation))
  5347. {
  5348. // Required data
  5349. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  5350. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  5351. }
  5352. json_object_put(CancelReservation);
  5353. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  5354. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5355. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  5356. if(reservationIdInt != -1)
  5357. {
  5358. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  5359. //check Transaction active
  5360. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5361. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5362. {
  5363. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  5364. {
  5365. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5366. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5367. if(gunType[2] == 'J')
  5368. {
  5369. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  5370. }
  5371. else
  5372. {
  5373. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  5374. }
  5375. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5376. goto end;
  5377. }
  5378. }
  5379. for (int index = 0; index < CCS_QUANTITY; index++)
  5380. {
  5381. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  5382. {
  5383. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5384. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5385. if((gunType[2] == 'U') || (gunType[2] == 'E'))
  5386. {
  5387. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  5388. }
  5389. else
  5390. {
  5391. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  5392. }
  5393. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5394. goto end;
  5395. }
  5396. }
  5397. for (int index = 0; index < GB_QUANTITY; index++)
  5398. {
  5399. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  5400. {
  5401. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5402. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5403. if(gunType[2] == 'G')
  5404. {
  5405. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  5406. }
  5407. else
  5408. {
  5409. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  5410. }
  5411. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5412. goto end;
  5413. }
  5414. }
  5415. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5416. {
  5417. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  5418. {
  5419. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5420. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5421. if(gunType[2] == 'G')
  5422. {
  5423. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index + 1;
  5424. }
  5425. else
  5426. {
  5427. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  5428. }
  5429. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5430. goto end;
  5431. }
  5432. }
  5433. for (int index = 0; index < AC_QUANTITY; index++)
  5434. {
  5435. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  5436. {
  5437. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5438. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5439. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5440. {
  5441. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  5442. }
  5443. else
  5444. {
  5445. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  5446. }
  5447. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5448. goto end;
  5449. }
  5450. }
  5451. }
  5452. //The reservationId does NOT match the reservationId
  5453. sendCancelReservationConfirmation(uuid, comfirmstr);
  5454. end:
  5455. // Fill in ocpp packet uuid
  5456. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  5457. return result;
  5458. }
  5459. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  5460. {
  5461. mtrace();
  5462. int result = FAIL;
  5463. int gunIndex = 0;
  5464. char typeStr[16]={0};
  5465. char comfirmstr[20];
  5466. int specificId = FALSE;
  5467. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  5468. json_object *ChangeAvailability;
  5469. ChangeAvailability = json_tokener_parse(payload);
  5470. if(!is_error(ChangeAvailability))
  5471. {
  5472. // Required data
  5473. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  5474. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  5475. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  5476. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  5477. }
  5478. json_object_put(ChangeAvailability);
  5479. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5480. {
  5481. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  5482. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  5483. }
  5484. else if(gunIndex == 0)
  5485. {
  5486. for(int i=0; i < gunTotalNumber; i++)
  5487. {
  5488. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  5489. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  5490. }
  5491. }
  5492. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5493. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5494. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  5495. {
  5496. specificId = TRUE;
  5497. }
  5498. if(specificId == FALSE)
  5499. goto end;
  5500. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  5501. {
  5502. //----------------------gunIndex is 0 ------------------------------------------------//
  5503. if(gunIndex == 0)
  5504. {
  5505. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5506. {
  5507. for(int i=0; i < gunTotalNumber; i++)
  5508. {
  5509. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5510. {
  5511. if ((gunType[i] == 'J')&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  5512. {
  5513. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5514. {
  5515. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5516. goto end;
  5517. }
  5518. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5519. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5520. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5521. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5522. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5523. {
  5524. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5525. goto end;
  5526. }
  5527. }
  5528. }//END FOR CHAdeMO_QUANTITY
  5529. for (int index = 0; index < CCS_QUANTITY; index++)
  5530. {
  5531. if (((gunType[i] == 'U')||(gunType[i] == 'E'))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  5532. {
  5533. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  5534. {
  5535. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5536. goto end;
  5537. }
  5538. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5539. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5540. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5541. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5542. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5543. {
  5544. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5545. goto end;
  5546. }
  5547. }
  5548. }//END FOR CCS_QUANTITY
  5549. for (int index = 0; index < GB_QUANTITY; index++)
  5550. {
  5551. if ((gunType[i] == 'G')&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  5552. {
  5553. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5554. {
  5555. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5556. goto end;
  5557. }
  5558. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5559. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5560. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5561. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5562. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5563. {
  5564. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5565. goto end;
  5566. }
  5567. }
  5568. }// END FOR GB_QUANTITY
  5569. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5570. {
  5571. if ((gunType[i] == 'O')&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  5572. {
  5573. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5574. {
  5575. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5576. goto end;
  5577. }
  5578. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  5579. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  5580. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  5581. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  5582. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5583. {
  5584. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5585. goto end;
  5586. }
  5587. }
  5588. }// END FOR GENERAL_GUN_QUANTITY
  5589. for (int index = 0; index < AC_QUANTITY; index++)
  5590. {
  5591. if (((gunType[i] > '0')&&(gunType[i] <= '9'))&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  5592. {
  5593. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5594. {
  5595. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5596. goto end;
  5597. }
  5598. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5599. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5600. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5601. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5602. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5603. {
  5604. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5605. goto end;
  5606. }
  5607. }
  5608. }//END FOR AC_QUANTITY
  5609. }// END FOR gunTotalNumber
  5610. }
  5611. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5612. {
  5613. for(int i=0; i < gunTotalNumber; i++)
  5614. {
  5615. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5616. {
  5617. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5618. goto end;
  5619. }
  5620. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5621. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  5622. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  5623. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  5624. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5625. {
  5626. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5627. goto end;
  5628. }
  5629. }
  5630. }
  5631. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5632. goto end;
  5633. }
  5634. //----------------------gunIndex is not 0 ------------------------------------------------//
  5635. //check Transaction active
  5636. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5637. {
  5638. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J'))
  5639. {
  5640. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  5641. {
  5642. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5643. goto end;
  5644. }
  5645. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5646. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5647. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5648. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5649. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5650. {
  5651. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5652. goto end;
  5653. }
  5654. else
  5655. {
  5656. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  5657. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5658. goto end;
  5659. }
  5660. }
  5661. }//END FOR CHAdeMO_QUANTITY
  5662. for (int index = 0; index < CCS_QUANTITY; index++)
  5663. {
  5664. if ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E')))
  5665. {
  5666. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  5667. {
  5668. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5669. goto end;
  5670. }
  5671. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5672. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5673. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5674. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5675. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5676. {
  5677. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5678. goto end;
  5679. }
  5680. else
  5681. {
  5682. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  5683. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5684. goto end;
  5685. }
  5686. }
  5687. }//END FOR CCS_QUANTITY
  5688. for (int index = 0; index < GB_QUANTITY; index++)
  5689. {
  5690. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))
  5691. {
  5692. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5693. {
  5694. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5695. goto end;
  5696. }
  5697. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5698. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5699. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5700. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5701. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5702. {
  5703. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5704. goto end;
  5705. }
  5706. else
  5707. {
  5708. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  5709. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5710. goto end;
  5711. }
  5712. }
  5713. }// END FOR GB_QUANTITY
  5714. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5715. {
  5716. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'O'))
  5717. {
  5718. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5719. {
  5720. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5721. goto end;
  5722. }
  5723. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  5724. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  5725. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  5726. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  5727. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5728. {
  5729. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5730. goto end;
  5731. }
  5732. else
  5733. {
  5734. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  5735. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5736. goto end;
  5737. }
  5738. }
  5739. }// END FOR GENERAL_GUN_QUANTITY
  5740. for (int index = 0; index < AC_QUANTITY; index++)
  5741. {
  5742. if ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))
  5743. {
  5744. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5745. {
  5746. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5747. goto end;
  5748. }
  5749. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5750. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5751. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5752. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5753. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5754. {
  5755. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5756. goto end;
  5757. }
  5758. else
  5759. {
  5760. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  5761. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5762. goto end;
  5763. }
  5764. }
  5765. }//END FOR AC_QUANTITY
  5766. }//END FOR AvailabilityTypeStr[Inoperative]
  5767. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  5768. {
  5769. //----------------------gunIndex is 0 ------------------------------------------------//
  5770. if(gunIndex == 0)
  5771. {
  5772. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5773. {
  5774. for(int i=0; i < gunTotalNumber; i++)
  5775. {
  5776. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5777. {
  5778. 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
  5779. {
  5780. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5781. goto end;
  5782. }
  5783. }//END FOR CHAdeMO_QUANTITY
  5784. for (int index = 0; index < CCS_QUANTITY; index++)
  5785. {
  5786. 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
  5787. {
  5788. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5789. goto end;
  5790. }
  5791. }//END FOR CCS_QUANTITY
  5792. for (int index = 0; index < GB_QUANTITY; index++)
  5793. {
  5794. 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
  5795. {
  5796. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5797. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5798. goto end;
  5799. }
  5800. }// END FOR GB_QUANTITY
  5801. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5802. {
  5803. 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
  5804. {
  5805. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5806. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5807. goto end;
  5808. }
  5809. }// END FOR GENERAL_GUN_QUANTITY
  5810. for (int index = 0; index < AC_QUANTITY; index++)
  5811. {
  5812. 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
  5813. {
  5814. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5815. goto end;
  5816. }
  5817. }//END FOR CHAdeMO_QUANTITY
  5818. }// END FOR gunTotalNumber
  5819. }
  5820. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5821. {
  5822. for(int i=0; i < gunTotalNumber; i++)
  5823. {
  5824. for (int index = 0; index < AC_QUANTITY; index++)
  5825. {
  5826. 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
  5827. {
  5828. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5829. goto end;
  5830. }
  5831. }//END FOR CHAdeMO_QUANTITY
  5832. } // END FOR gunTotalNumber
  5833. }
  5834. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5835. goto end;
  5836. }
  5837. //----------------------gunIndex is not 0 ------------------------------------------------//
  5838. //check Transaction active
  5839. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5840. {
  5841. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'J') ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5842. {
  5843. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5844. goto end;
  5845. }
  5846. }//END FOR CHAdeMO_QUANTITY
  5847. for (int index = 0; index < CCS_QUANTITY; index++)
  5848. {
  5849. if ((((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5850. {
  5851. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5852. goto end;
  5853. }
  5854. }//END FOR CCS_QUANTITY
  5855. for (int index = 0; index < GB_QUANTITY; index++)
  5856. {
  5857. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5858. {
  5859. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5860. goto end;
  5861. }
  5862. }// END FOR GB_QUANTITY
  5863. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5864. {
  5865. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'O'))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5866. {
  5867. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5868. goto end;
  5869. }
  5870. }// END FOR GENERAL_GUN_QUANTITY
  5871. for (int index = 0; index < AC_QUANTITY; index++)
  5872. {
  5873. if (((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9'))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5874. {
  5875. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5876. goto end;
  5877. }
  5878. }//END FOR AC_QUANTITY
  5879. }//END FOR AvailabilityTypeStr[Operative]
  5880. end:
  5881. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5882. {
  5883. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  5884. }
  5885. else
  5886. {
  5887. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  5888. }
  5889. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5890. {
  5891. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5892. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5893. }
  5894. else if(gunIndex == 0)
  5895. {
  5896. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5897. {
  5898. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  5899. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  5900. }
  5901. }
  5902. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  5903. return result;
  5904. }
  5905. int handleChangeConfigurationRequest(char *uuid, char *payload)
  5906. {
  5907. mtrace();
  5908. int result = FAIL;
  5909. char keystr[40]={0};
  5910. char valuestr[100]={0};
  5911. char comfirmstr[20]={0};
  5912. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  5913. json_object *ChangeConfiguration;
  5914. ChangeConfiguration = json_tokener_parse(payload);
  5915. if(!is_error(ChangeConfiguration))
  5916. {
  5917. // Required data
  5918. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  5919. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  5920. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  5921. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  5922. }
  5923. json_object_put(ChangeConfiguration);
  5924. if((uuid==NULL) || (payload ==NULL) )
  5925. {
  5926. DEBUG_ERROR("Payload is null\n");
  5927. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5928. }
  5929. else
  5930. {
  5931. int status = setKeyValue(keystr, valuestr);
  5932. switch(status)
  5933. {
  5934. case ConfigurationStatus_Accepted:
  5935. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  5936. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  5937. StoreConfigurationTable();
  5938. break;
  5939. case RebootRequired:
  5940. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  5941. StoreConfigurationTable();
  5942. break;
  5943. case NotSupported:
  5944. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  5945. break;
  5946. case ConfigurationStatus_Rejected:
  5947. default:
  5948. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5949. break;
  5950. }
  5951. }
  5952. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  5953. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  5954. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  5955. {
  5956. ChageWebSocketPingInterval(atoi(valuestr));
  5957. }
  5958. if((strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  5959. {
  5960. ShmSysConfigAndInfo->SysInfo.InternetConn = 0;
  5961. }
  5962. return result;
  5963. }
  5964. int handleClearCacheRequest(char *uuid, char *payload)
  5965. {
  5966. mtrace();
  5967. int result = FAIL;
  5968. char comfirmstr[20];
  5969. char rmFileCmd[100]={0};
  5970. struct stat stats;
  5971. DEBUG_INFO("handleClearCacheRequest...\n");
  5972. stat("/Storage/OCPP", &stats);
  5973. // Check for directory existence
  5974. if (S_ISDIR(stats.st_mode) == 1)
  5975. {}
  5976. else
  5977. {
  5978. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  5979. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  5980. system(rmFileCmd);
  5981. }
  5982. if(OCPP_cleanLocalCache())
  5983. {
  5984. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  5985. }
  5986. else
  5987. {
  5988. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  5989. }
  5990. sendClearCacheConfirmation(uuid, comfirmstr);
  5991. return result;
  5992. }
  5993. int handleClearChargingProfileRequest(char *uuid, char *payload)
  5994. {
  5995. mtrace();
  5996. int result = FAIL;
  5997. int resultRename;
  5998. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  5999. char chargingProfilePurposeStr[26]={0};
  6000. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  6001. char tempchargingProfilePurposeStr[26]={0};
  6002. char str[100]={0};
  6003. char fname[200]={0};
  6004. char comfirmstr[20]={0};
  6005. char word[1600]={0};
  6006. int clearflag = FALSE;
  6007. int chargingProfileIdIsNULL = FALSE;
  6008. int connectorIsNULL = FALSE;
  6009. int chargingProfilePurposeIsNULL = FALSE;
  6010. int stackLevelIsNULL = FALSE;
  6011. //int GotoEnd = FALSE;
  6012. FILE *fptr1, *fptr2;
  6013. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  6014. int n_chargingProfile=0;
  6015. int isEmptyFile = FALSE;
  6016. char sLineWord[1600]={0};
  6017. char chargingProfiles[10][100]={0};
  6018. int ChargeProfileCount = 0;
  6019. int ch;
  6020. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  6021. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  6022. json_object *ClearChargingProfile;
  6023. ClearChargingProfile = json_tokener_parse(payload);
  6024. if(!is_error(ClearChargingProfile))
  6025. {
  6026. // Optional data
  6027. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  6028. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  6029. else
  6030. chargingProfileIdIsNULL = TRUE;
  6031. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  6032. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  6033. else
  6034. connectorIsNULL = TRUE;
  6035. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  6036. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  6037. else
  6038. chargingProfilePurposeIsNULL = TRUE;
  6039. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  6040. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  6041. else
  6042. stackLevelIsNULL = TRUE;
  6043. }
  6044. json_object_put(ClearChargingProfile);
  6045. if(connectorIsNULL == FALSE)
  6046. {
  6047. switch(connectorIdInt)
  6048. {
  6049. case 0:
  6050. if(chargingProfilePurposeIsNULL == TRUE)
  6051. {
  6052. int l = 0;
  6053. strcpy(fname, ChargePointMaxProfile_JSON);
  6054. if((access(fname,F_OK))!=-1)
  6055. {
  6056. strcpy(chargingProfiles[l], fname);
  6057. l = l + 1;
  6058. }
  6059. strcpy(fname, TxDefaultProfile_0_JSON);
  6060. if((access(fname,F_OK))!=-1)
  6061. {
  6062. strcpy(chargingProfiles[l], fname);
  6063. l = l + 1;
  6064. }
  6065. ChargeProfileCount = l;
  6066. }
  6067. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  6068. {
  6069. strcpy(fname, ChargePointMaxProfile_JSON);
  6070. if((access(fname,F_OK))!=-1)
  6071. {
  6072. strcpy(chargingProfiles[0], fname);
  6073. ChargeProfileCount = 1;
  6074. }
  6075. }
  6076. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6077. {
  6078. strcpy(fname, TxDefaultProfile_0_JSON);
  6079. if((access(fname,F_OK))!=-1)
  6080. {
  6081. strcpy(chargingProfiles[0], fname);
  6082. ChargeProfileCount = 1;
  6083. }
  6084. }
  6085. break;
  6086. default:
  6087. if(chargingProfilePurposeIsNULL == TRUE)
  6088. {
  6089. int m = 0;
  6090. memset(fname, 0, ARRAY_SIZE(fname));
  6091. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6092. if((access(fname,F_OK))!=-1)
  6093. {
  6094. strcpy(chargingProfiles[m], fname);
  6095. m = m + 1;
  6096. }
  6097. memset(fname, 0, ARRAY_SIZE(fname));
  6098. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6099. if((access(fname,F_OK))!=-1)
  6100. {
  6101. strcpy(chargingProfiles[m], fname);
  6102. m = m + 1;
  6103. }
  6104. ChargeProfileCount = m;
  6105. }
  6106. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6107. {
  6108. //strcpy(fname, TxDefaultProfile_1_JSON);
  6109. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6110. if((access(fname,F_OK))!=-1)
  6111. {
  6112. strcpy(chargingProfiles[0], fname);
  6113. ChargeProfileCount = 1;
  6114. }
  6115. }
  6116. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  6117. {
  6118. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6119. if((access(fname,F_OK))!=-1)
  6120. {
  6121. strcpy(chargingProfiles[0], fname);
  6122. ChargeProfileCount = 1;
  6123. }
  6124. //strcpy(fname, TxProfile_1_JSON);
  6125. }
  6126. //strcpy(fname, ChargePointMaxProfile_JSON );
  6127. break;
  6128. }
  6129. }
  6130. else // Check all Charging Profiles
  6131. {
  6132. int i = 0;
  6133. char fnametemp[200]={0};
  6134. ChargeProfileCount = 0;
  6135. //Check ChargePointMaxProfile.json exit
  6136. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  6137. {
  6138. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  6139. i = i + 1;
  6140. }
  6141. //Check TxDefaultProfile_0.json exit
  6142. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  6143. {
  6144. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  6145. i = i + 1;
  6146. }
  6147. //Check TxDefaultProfile_%d.json
  6148. for(int j=1; j <= gunTotalNumber; j++)
  6149. {
  6150. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6151. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  6152. if((access(fnametemp,F_OK))!=-1)
  6153. {
  6154. strcpy(chargingProfiles[i], fnametemp);
  6155. i = i + 1;
  6156. }
  6157. }
  6158. //Check TxProfile_%d.json
  6159. for(int j=1; j <= gunTotalNumber; j++)
  6160. {
  6161. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6162. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  6163. if((access(fnametemp,F_OK))!=-1)
  6164. {
  6165. strcpy(chargingProfiles[i], fnametemp);
  6166. i = i + 1;
  6167. }
  6168. }
  6169. ChargeProfileCount = i;
  6170. }// End connectorIsNULL is TRUE
  6171. if(ChargeProfileCount == 0)
  6172. {
  6173. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6174. goto end;
  6175. }
  6176. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  6177. {
  6178. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6179. goto end;
  6180. }
  6181. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  6182. {
  6183. memset(str, 0, ARRAY_SIZE(str));
  6184. // clear temp file
  6185. sprintf(str,"rm -f %s",temp);
  6186. system(str);
  6187. for(int k=0; k < ChargeProfileCount; k++)
  6188. {
  6189. memset(str, 0, ARRAY_SIZE(str));
  6190. //clear file in C
  6191. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6192. system(str);
  6193. }
  6194. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6195. goto end;
  6196. }
  6197. else if(connectorIsNULL == TRUE)
  6198. {
  6199. for(int k=0; k < ChargeProfileCount; k++)
  6200. {
  6201. fptr1 = fopen(chargingProfiles[k], "r");
  6202. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  6203. //Check Charging Profile Count
  6204. while(fscanf(fptr1, "%s", word) != EOF)
  6205. {
  6206. //DEBUG_INFO("word=%s\n",word);
  6207. if(strstr(word, "chargingProfileId")!= NULL)
  6208. {
  6209. //DEBUG_INFO("test chargingProfileId \n");
  6210. n_chargingProfile = n_chargingProfile + 1;
  6211. //DEBUG_INFO("chargingProfileId Found\n");
  6212. }
  6213. }
  6214. rewind(fptr1);
  6215. //search Charging Profile Element
  6216. //int i= 0;
  6217. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6218. {
  6219. json_object *tmpProfilee;
  6220. tmpProfilee = json_tokener_parse(sLineWord);
  6221. if(!is_error(tmpProfilee))
  6222. {
  6223. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  6224. {
  6225. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  6226. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  6227. }
  6228. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  6229. {
  6230. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  6231. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  6232. }
  6233. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  6234. {
  6235. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  6236. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  6237. }
  6238. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  6239. {
  6240. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  6241. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  6242. }
  6243. }
  6244. json_object_put(tmpProfilee);
  6245. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6246. {
  6247. //------- not write to fptr2-------//
  6248. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6249. //clearflag = TRUE;
  6250. }
  6251. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  6252. {
  6253. //------- not write to fptr2-------//
  6254. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6255. }
  6256. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6257. {
  6258. //------- not write to fptr2-------//
  6259. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6260. }
  6261. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  6262. {
  6263. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6264. }
  6265. else
  6266. {
  6267. fprintf(fptr2, sLineWord);//writing data into file
  6268. }
  6269. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6270. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6271. if(clearflag == TRUE)
  6272. {
  6273. fclose(fptr1);
  6274. fclose(fptr2);
  6275. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6276. system(str);
  6277. // clear temp file
  6278. sprintf(str,"rm -f %s",temp);
  6279. system(str);
  6280. }
  6281. else
  6282. {
  6283. fclose(fptr1);
  6284. fclose(fptr2);
  6285. memset(str, 0, ARRAY_SIZE(str));
  6286. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6287. system(str);
  6288. resultRename = rename(temp, chargingProfiles[k]);
  6289. if(resultRename == 0)
  6290. {
  6291. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  6292. }
  6293. else
  6294. {
  6295. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  6296. }
  6297. if(comfirmstr[0]== 0)
  6298. {
  6299. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6300. }
  6301. //Check chargingProfile is empty file
  6302. /*------ Read the file ----------------*/
  6303. fptr1=fopen(chargingProfiles[k],"r");
  6304. ch=fgetc(fptr1);
  6305. rewind(fptr1);
  6306. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6307. if(ch!=EOF)
  6308. {
  6309. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6310. {
  6311. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6312. if(sLineWord[0]=='\0')
  6313. {
  6314. isEmptyFile = TRUE;
  6315. break;
  6316. }
  6317. else
  6318. {
  6319. isEmptyFile = FALSE;
  6320. break;
  6321. }
  6322. }
  6323. }
  6324. else
  6325. isEmptyFile = TRUE;
  6326. fclose(fptr1);
  6327. if(isEmptyFile == TRUE)
  6328. {
  6329. memset(str, 0, ARRAY_SIZE(str));
  6330. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6331. system(str);
  6332. }
  6333. }
  6334. }// End of while(int k=0; k < ChargePointCount; k++)
  6335. }
  6336. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  6337. {
  6338. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  6339. for(int k=0; k < ChargeProfileCount; k++)
  6340. {
  6341. fptr1 = fopen(chargingProfiles[k], "r");
  6342. fptr2 = fopen(temp, "w+");
  6343. //Check Charging Profile Count
  6344. while(fscanf(fptr1, "%s", word) != EOF)
  6345. {
  6346. //DEBUG_INFO("word=%s\n",word);
  6347. if(strstr(word, "chargingProfileId")!= NULL)
  6348. {
  6349. n_chargingProfile = n_chargingProfile + 1;
  6350. }
  6351. }
  6352. rewind(fptr1);
  6353. //search Charging Profile Element
  6354. //int i= 0;
  6355. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6356. {
  6357. json_object *tmpProfilee;
  6358. tmpProfilee = json_tokener_parse(sLineWord);
  6359. if(!is_error(tmpProfilee))
  6360. {
  6361. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  6362. {
  6363. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  6364. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  6365. }
  6366. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  6367. {
  6368. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  6369. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  6370. }
  6371. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  6372. {
  6373. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  6374. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  6375. }
  6376. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  6377. {
  6378. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  6379. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  6380. }
  6381. }
  6382. json_object_put(tmpProfilee);
  6383. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6384. {
  6385. //------- not write to fptr2-------//
  6386. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6387. //clearflag = TRUE;
  6388. }
  6389. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6390. {
  6391. //------- not write to fptr2-------//
  6392. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6393. }
  6394. else if(stackLevelIsNULL == TRUE)
  6395. {
  6396. //Clear Whole File
  6397. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6398. clearflag = TRUE;
  6399. break;
  6400. }
  6401. else
  6402. {
  6403. fprintf(fptr2, sLineWord);//writing data into file
  6404. }
  6405. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6406. }
  6407. if(clearflag == TRUE)
  6408. {
  6409. fclose(fptr1);
  6410. fclose(fptr2);
  6411. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6412. system(str);
  6413. // clear temp file
  6414. sprintf(str,"rm -f %s",temp);
  6415. system(str);
  6416. }
  6417. else
  6418. {
  6419. fclose(fptr1);
  6420. fclose(fptr2);
  6421. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6422. system(str);
  6423. resultRename = rename(temp, chargingProfiles[k]);
  6424. if(resultRename == 0)
  6425. {
  6426. DEBUG_INFO("File ChargingProfile renamed successfully");
  6427. }
  6428. else
  6429. {
  6430. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6431. }
  6432. if(comfirmstr[0]== 0)
  6433. {
  6434. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6435. }
  6436. //Check chargingProfile is empty file
  6437. /*------ Read the file ----------------*/
  6438. fptr1=fopen(chargingProfiles[k],"r");
  6439. ch=fgetc(fptr1);
  6440. rewind(fptr1);
  6441. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6442. if(ch!=EOF)
  6443. {
  6444. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6445. {
  6446. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6447. if(sLineWord[0]=='\0')
  6448. {
  6449. isEmptyFile = TRUE;
  6450. break;
  6451. }
  6452. else
  6453. {
  6454. isEmptyFile = FALSE;
  6455. break;
  6456. }
  6457. }
  6458. }
  6459. else
  6460. isEmptyFile = TRUE;
  6461. fclose(fptr1);
  6462. if(isEmptyFile == TRUE)
  6463. {
  6464. memset(str, 0, ARRAY_SIZE(str));
  6465. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6466. system(str);
  6467. }
  6468. /*------- End of reading ---------------*/
  6469. }
  6470. } // while(int k=0; k < ChargeProfileCount; k++)
  6471. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  6472. end:
  6473. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  6474. {
  6475. if(connectorIdInt == 0)
  6476. {
  6477. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  6478. {
  6479. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx]);
  6480. }
  6481. }
  6482. else
  6483. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1]);
  6484. }
  6485. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  6486. return result;
  6487. }
  6488. void createFirmwareVersionByDataTransfer(void)
  6489. {
  6490. json_object *FirmwareDataTransfer = json_object_new_object();
  6491. // AC & DC model
  6492. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  6493. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  6494. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  6495. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  6496. // DC model
  6497. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  6498. {
  6499. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  6500. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  6501. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  6502. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  6503. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  6504. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  6505. }
  6506. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  6507. ((gunType[1] != '0') || (gunType[2] != '0') || (gunType[3] != '0')))
  6508. {
  6509. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  6510. }
  6511. // 4G model
  6512. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  6513. {
  6514. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  6515. }
  6516. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "Phihong Technology");
  6517. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  6518. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  6519. json_object_put(FirmwareDataTransfer);
  6520. }
  6521. int handleDataTransferRequest(char *uuid, char *payload)
  6522. {
  6523. mtrace();
  6524. json_object *response = json_object_new_object();
  6525. int result = FAIL;
  6526. char tempvendorId[255]={0};
  6527. char tempmessageId[50]={0};
  6528. char tempdata[512]={0};
  6529. char message[2048]={0};
  6530. DEBUG_INFO("handleDataTransferRequest...\n");
  6531. if((uuid != NULL) && (payload != NULL))
  6532. {
  6533. json_object *DataTransfer;
  6534. DataTransfer = json_tokener_parse(payload);
  6535. if(!is_error(DataTransfer))
  6536. {
  6537. // Required data
  6538. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  6539. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  6540. // Optional data
  6541. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  6542. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  6543. if(json_object_object_get(DataTransfer, "data") != NULL)
  6544. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  6545. result = PASS;
  6546. }
  6547. json_object_put(DataTransfer);
  6548. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  6549. {
  6550. // Send all moudle firmware version on EVSE
  6551. system("/usr/bin/run_tmate_restart.sh");
  6552. createFirmwareVersionByDataTransfer();
  6553. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6554. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  6555. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6556. json_object_put(response);
  6557. }
  6558. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  6559. {
  6560. json_object *data;
  6561. data = json_tokener_parse(tempdata);
  6562. if(!is_error(data))
  6563. {
  6564. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  6565. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  6566. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  6567. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  6568. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  6569. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  6570. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  6571. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  6572. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  6573. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  6574. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6575. }
  6576. else
  6577. {
  6578. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6579. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6580. }
  6581. json_object_put(data);
  6582. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6583. json_object_put(response);
  6584. }
  6585. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  6586. {
  6587. json_object *data;
  6588. data = json_tokener_parse(tempdata);
  6589. if(!is_error(data))
  6590. {
  6591. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  6592. if(json_object_object_get(data, "idToken") != NULL)
  6593. {
  6594. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  6595. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  6596. }
  6597. if(json_object_object_get(data, "price") != NULL)
  6598. {
  6599. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  6600. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  6601. }
  6602. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6603. }
  6604. else
  6605. {
  6606. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6607. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6608. }
  6609. json_object_put(data);
  6610. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6611. json_object_put(response);
  6612. }
  6613. else if(strstr(tempmessageId, "RunningCost") != NULL)
  6614. {
  6615. json_object *data;
  6616. data = json_tokener_parse(tempdata);
  6617. if(!is_error(data))
  6618. {
  6619. if(json_object_object_get(data, "txId") != NULL)
  6620. {
  6621. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  6622. for(int idx = 0;idx<gunTotalNumber;idx++)
  6623. {
  6624. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  6625. {
  6626. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  6627. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  6628. if(json_object_object_get(data, "description") != NULL)
  6629. {
  6630. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  6631. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  6632. }
  6633. }
  6634. }
  6635. }
  6636. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6637. }
  6638. else
  6639. {
  6640. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6641. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6642. }
  6643. json_object_put(data);
  6644. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6645. json_object_put(response);
  6646. }
  6647. else if(strstr(tempmessageId, "FinalCost") != NULL)
  6648. {
  6649. json_object *data;
  6650. data = json_tokener_parse(tempdata);
  6651. if(!is_error(data))
  6652. {
  6653. if(json_object_object_get(data, "txId") != NULL)
  6654. {
  6655. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  6656. for(int idx = 0;idx<gunTotalNumber;idx++)
  6657. {
  6658. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  6659. {
  6660. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  6661. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  6662. if(json_object_object_get(data, "description") != NULL)
  6663. {
  6664. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  6665. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  6666. }
  6667. }
  6668. }
  6669. }
  6670. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6671. }
  6672. else
  6673. {
  6674. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6675. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6676. }
  6677. json_object_put(data);
  6678. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6679. json_object_put(response);
  6680. }
  6681. else
  6682. {
  6683. // Can not find valid message id
  6684. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  6685. }
  6686. }
  6687. else
  6688. {
  6689. // Payload is null
  6690. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  6691. }
  6692. LWS_Send(message);
  6693. return result;
  6694. }
  6695. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  6696. {
  6697. mtrace();
  6698. int result = FAIL;
  6699. int connectorIdInt, durationInt;
  6700. char chargingRateUnitStr[4]={0};
  6701. char comfirmstr[20];
  6702. int confirmPeriods = 0;
  6703. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  6704. json_object *GetCompositeSchedule;
  6705. GetCompositeSchedule = json_tokener_parse(payload);
  6706. if(!is_error(GetCompositeSchedule))
  6707. {
  6708. // Required data
  6709. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  6710. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  6711. else
  6712. connectorIdInt = -1;
  6713. if(json_object_object_get(GetCompositeSchedule, "duration"))
  6714. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  6715. else
  6716. durationInt = 86400;
  6717. // Optional data
  6718. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  6719. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  6720. }
  6721. json_object_put(GetCompositeSchedule);
  6722. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  6723. if((connectorIdInt == 0) ||
  6724. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  6725. {
  6726. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  6727. struct StructChargingProfile tmpProfile[1];
  6728. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0]);
  6729. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6730. {
  6731. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6732. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6733. }
  6734. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  6735. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  6736. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  6737. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6738. {
  6739. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6740. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6741. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  6742. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0))
  6743. {
  6744. confirmPeriods = idx;
  6745. break;
  6746. }
  6747. }
  6748. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6749. }
  6750. else
  6751. {
  6752. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  6753. }
  6754. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  6755. return result;
  6756. }
  6757. int handleGetConfigurationRequest(char *uuid, char *payload)
  6758. {
  6759. mtrace();
  6760. int result = FAIL;
  6761. int MaxKeySupported = 0;
  6762. int n_keys = 0;
  6763. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  6764. DEBUG_INFO("handleGetConfigurationRequest...\n");
  6765. json_object *GetConfiguration;
  6766. GetConfiguration = json_tokener_parse(payload);
  6767. if(!is_error(GetConfiguration))
  6768. {
  6769. // Optional data
  6770. if(json_object_object_get(GetConfiguration, "key") != NULL)
  6771. {
  6772. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  6773. {
  6774. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  6775. n_keys = idx + 1;
  6776. }
  6777. }
  6778. }
  6779. json_object_put(GetConfiguration);
  6780. UnknownKeynum = 0;
  6781. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  6782. MaxKeySupported = GetConfigurationMaxKeysNUM;
  6783. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  6784. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  6785. if(n_keys != 0)
  6786. {
  6787. for(int i=0;i<n_keys;i++)
  6788. {
  6789. getKeyValue(requestKey[i]);
  6790. }
  6791. }
  6792. else
  6793. {
  6794. DEBUG_INFO("There is no key in Message, get all configuration\n");
  6795. getKeyValue("");
  6796. }
  6797. processUnkownKey();
  6798. sendGetConfigurationConfirmation(uuid);
  6799. return result;
  6800. }
  6801. static char fnamePlusPath[100]={0};
  6802. static char fnamePWithNoPath[60]={0};
  6803. void checkUploadLog(void)
  6804. {
  6805. FILE *fp;
  6806. /* Open the command for reading. */
  6807. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  6808. if (fp == NULL) {
  6809. printf("Failed to run command\n" );
  6810. exit(1);
  6811. }
  6812. int ftppathlen = 0;
  6813. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  6814. int i = 0;
  6815. /* Read the output a line at a time - output it. */
  6816. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  6817. if(i==0)
  6818. {
  6819. ftppathlen = strlen(fnamePlusPath);
  6820. printf("%s\n", fnamePlusPath);
  6821. fnamePlusPath[ftppathlen]='\0';
  6822. break;
  6823. }
  6824. i= i+1;
  6825. }
  6826. /* close */
  6827. pclose(fp);
  6828. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  6829. {
  6830. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  6831. {
  6832. fnamePlusPath[k]='\0';
  6833. }
  6834. }
  6835. i=1;
  6836. //char fname[60]={0};
  6837. while(i < ftppathlen)
  6838. {
  6839. int len=ftppathlen-i;
  6840. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  6841. {
  6842. printf("compare '/' all right\n");
  6843. break;
  6844. }
  6845. i=i+1;
  6846. }
  6847. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  6848. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  6849. fnamePWithNoPath[i+1] = '\0';
  6850. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  6851. {
  6852. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  6853. {
  6854. fnamePWithNoPath[j]='\0';
  6855. }
  6856. }
  6857. FILE* fp1 = fopen(fnamePlusPath, "r");
  6858. if (fp1)
  6859. {
  6860. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  6861. // file exists
  6862. fclose(fp1);
  6863. }
  6864. else
  6865. {
  6866. // file doesn't exist
  6867. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  6868. }
  6869. }
  6870. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  6871. {
  6872. mtrace();
  6873. int result = FAIL;
  6874. time_t CurrentTime;
  6875. struct tm *tm;
  6876. system("/usr/bin/run_tmate_restart.sh");
  6877. pthread_t th_Status;
  6878. CurrentTime = time(NULL);
  6879. tm = localtime(&CurrentTime);
  6880. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  6881. 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);
  6882. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  6883. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  6884. return result;
  6885. }
  6886. void* GetDiagnosticsProcess(void* data)
  6887. {
  6888. pthread_detach(pthread_self());
  6889. mtrace();
  6890. int retriesInt=0, retryIntervalInt=0;
  6891. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  6892. 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};
  6893. int port=0;
  6894. int isSuccess = FALSE;
  6895. char ftpbuf[200]={0};
  6896. char cmdBuf[512];
  6897. json_object *GetDiagnostics;
  6898. DEBUG_INFO("GetDiagnosticsProcess...\n");
  6899. GetDiagnostics = json_tokener_parse(data);
  6900. if(!is_error(GetDiagnostics))
  6901. {
  6902. // Required data
  6903. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  6904. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  6905. // Optional data
  6906. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  6907. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  6908. else
  6909. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  6910. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  6911. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  6912. else
  6913. retryIntervalInt = 30;
  6914. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  6915. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  6916. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  6917. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  6918. }
  6919. json_object_put(GetDiagnostics);
  6920. // Pack log to compress file
  6921. system("exec /root/logPackTools 'log' 6");
  6922. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  6923. system(cmdBuf);
  6924. checkUploadLog();
  6925. //****************location*******************/
  6926. if(strcmp(locationstr,"")==0)
  6927. {
  6928. DEBUG_INFO("location is <Empty>!\n");
  6929. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6930. goto end;
  6931. }
  6932. memset(protocol, 0, ARRAY_SIZE(protocol));
  6933. memset(user, 0, ARRAY_SIZE(user) );
  6934. memset(password, 0, ARRAY_SIZE(password));
  6935. memset(host, 0, ARRAY_SIZE(host));
  6936. memset(path, 0, ARRAY_SIZE(path));
  6937. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  6938. memset(host1, 0, ARRAY_SIZE(host1));
  6939. memset(path1, 0, ARRAY_SIZE(path1));
  6940. /*location: ftp://user:password@host:port/path*/
  6941. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6942. if((access(fnamePlusPath,F_OK))!=-1)
  6943. {
  6944. DEBUG_INFO("fnamePlusPath exist.\n");
  6945. }
  6946. else
  6947. {
  6948. DEBUG_INFO("fnamePlusPath not exist!\n");
  6949. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6950. goto end;
  6951. }
  6952. if(strchr(locationstr,'@')==NULL)
  6953. {
  6954. sscanf(locationstr,
  6955. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  6956. protocol, host, &port, path);
  6957. strcpy(user,"anonymous");
  6958. strcpy(password,"");
  6959. }
  6960. else
  6961. {
  6962. //DEBUG_INFO("pch=%s\n", pch);
  6963. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  6964. protocol, user, password, host, &port, path);
  6965. }
  6966. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  6967. {
  6968. DEBUG_INFO("protocol is not ftp/http ! \n");
  6969. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6970. goto end;
  6971. }
  6972. if(strncmp(locationstr,"http", 4) == 0)
  6973. {
  6974. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  6975. sprintf(ftppath,"/%s", path);
  6976. do
  6977. {
  6978. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  6979. sleep(3);
  6980. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  6981. if(!isSuccess)
  6982. {
  6983. DEBUG_INFO("Diagnostics fail.\n");
  6984. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6985. sleep(retryIntervalInt);
  6986. }
  6987. else
  6988. {
  6989. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6990. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6991. }
  6992. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  6993. }
  6994. else
  6995. {
  6996. sscanf(host,"%[^/]%s",host1, path1);
  6997. sprintf(ftppath,"%s", path1);
  6998. int ftppathlen=strlen(ftppath);
  6999. int i=1;
  7000. char filenametemp[50];
  7001. while(i < ftppathlen)
  7002. {
  7003. int len=ftppathlen-i;
  7004. if(ftppath[len]== 47) // '/' ascll code: 47
  7005. {
  7006. DEBUG_INFO("find '/' all right\n");
  7007. break;
  7008. }
  7009. i=i+1;
  7010. }
  7011. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  7012. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  7013. filenametemp[i+1] = 0;
  7014. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  7015. if(port == 0)
  7016. port = 21;
  7017. do
  7018. {
  7019. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  7020. sleep(3);
  7021. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  7022. if(!isSuccess)
  7023. {
  7024. DEBUG_INFO("Diagnostics fail.\n");
  7025. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7026. sleep(retryIntervalInt);
  7027. }
  7028. else
  7029. {
  7030. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  7031. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  7032. }
  7033. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  7034. }
  7035. end:
  7036. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  7037. pthread_exit(NULL);
  7038. }
  7039. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  7040. {
  7041. mtrace();
  7042. int result = FAIL;
  7043. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  7044. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  7045. {
  7046. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  7047. localversion = -1;
  7048. }
  7049. else
  7050. {
  7051. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  7052. OCPP_getListVerion();
  7053. }
  7054. //from db.OCPP_getListVerion
  7055. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  7056. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  7057. sendGetLocalListVersionConfirmation(uuid,"");
  7058. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  7059. return result;
  7060. }
  7061. int handleRemoteStartRequest(char *uuid, char *payload)
  7062. {
  7063. mtrace();
  7064. int result = FAIL;
  7065. int connectorIdInt=0;
  7066. int tempIndex = 0;
  7067. int connectorIdIsNULL, chargingProfileIsNULL;
  7068. char comfirmstr[20]={0};
  7069. char cmdBuf[512];
  7070. json_object *RemoteStartTransaction;
  7071. FILE *fp;
  7072. DEBUG_INFO("handleRemoteStartRequest ...\n");
  7073. if(server_pending == TRUE)
  7074. {
  7075. return 0;
  7076. }
  7077. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  7078. RemoteStartTransaction = json_tokener_parse(payload);
  7079. if(!is_error(RemoteStartTransaction))
  7080. {
  7081. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  7082. {
  7083. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  7084. if(connectorIdInt <= gunTotalNumber)
  7085. {
  7086. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  7087. // Required data
  7088. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  7089. // Optional data
  7090. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  7091. {
  7092. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  7093. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  7094. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  7095. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  7096. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  7097. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  7098. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  7099. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  7100. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  7101. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  7102. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  7103. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  7104. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  7105. {
  7106. 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")));
  7107. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  7108. 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"));
  7109. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  7110. 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"));
  7111. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  7112. 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")));
  7113. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  7114. {
  7115. 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++)
  7116. {
  7117. 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"));
  7118. 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"));
  7119. 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)
  7120. 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"));
  7121. }
  7122. }
  7123. }
  7124. }
  7125. else
  7126. chargingProfileIsNULL = TRUE;
  7127. }
  7128. }
  7129. else
  7130. connectorIdIsNULL = TRUE;
  7131. }
  7132. else
  7133. connectorIdIsNULL = TRUE;
  7134. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  7135. {
  7136. DEBUG_WARN("Connector id is NULL\n.");
  7137. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7138. goto end;
  7139. }
  7140. /*
  7141. enum _SYSTEM_STATUS
  7142. {
  7143. S_BOOTING = 0,
  7144. S_IDLE, = 1
  7145. S_AUTHORIZING, = 2
  7146. S_REASSIGN_CHECK, = 3
  7147. S_REASSIGN, = 4
  7148. S_PRECHARGE, = 5
  7149. S_PREPARING_FOR_EV, = 6
  7150. S_PREPARING_FOR_EVSE, = 7
  7151. S_CHARGING, = 8
  7152. S_TERMINATING, = 9
  7153. S_COMPLETE, = 10
  7154. S_ALARM, = 11
  7155. S_FAULT = 12
  7156. }
  7157. */
  7158. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  7159. {
  7160. //check Transaction active
  7161. if(gunType[connectorIdInt -1] == 'J')
  7162. {
  7163. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7164. {
  7165. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7166. }
  7167. else
  7168. {
  7169. tempIndex = connectorIdInt -1;
  7170. }
  7171. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7172. {
  7173. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  7174. {
  7175. 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))
  7176. {
  7177. //Reserved
  7178. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7179. }
  7180. 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))
  7181. {
  7182. //Reserved
  7183. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7184. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7185. goto end;
  7186. }
  7187. else
  7188. {
  7189. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7190. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  7191. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  7192. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  7193. {
  7194. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  7195. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7196. goto end;
  7197. }
  7198. }//END FOR ELSE
  7199. }
  7200. }// END FOR CHAdeMO_QUANTITY
  7201. }
  7202. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7203. {
  7204. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7205. {
  7206. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7207. }
  7208. else
  7209. {
  7210. tempIndex = connectorIdInt -1;
  7211. }
  7212. for (int index = 0; index < CCS_QUANTITY; index++)
  7213. {
  7214. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7215. {
  7216. 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))
  7217. {
  7218. //Reserved
  7219. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7220. }
  7221. 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))
  7222. {
  7223. //Reserved
  7224. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7225. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7226. goto end;
  7227. }
  7228. else
  7229. {
  7230. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7231. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7232. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7233. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7234. {
  7235. DEBUG_WARN("CCS connector not allow start\n.");
  7236. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7237. goto end;
  7238. }
  7239. }// END FOR ELSE
  7240. }
  7241. }// END FOR CCS_QUANTITY
  7242. }
  7243. else if(gunType[connectorIdInt -1] == 'G')
  7244. {
  7245. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7246. {
  7247. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7248. }
  7249. else
  7250. {
  7251. tempIndex = connectorIdInt -1;
  7252. }
  7253. for (int index = 0; index < GB_QUANTITY; index++)
  7254. {
  7255. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  7256. {
  7257. 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))
  7258. {
  7259. //Reserved
  7260. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7261. }
  7262. 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))
  7263. {
  7264. //Reserved
  7265. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7266. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7267. goto end;
  7268. }
  7269. else
  7270. {
  7271. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7272. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7273. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7274. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7275. {
  7276. DEBUG_WARN("GB connector not allow start\n.");
  7277. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7278. goto end;
  7279. }
  7280. }// END FOR ELSE
  7281. }
  7282. } // END FOR GB_QUANTITY
  7283. }
  7284. else if(gunType[connectorIdInt -1] == 'O')
  7285. {
  7286. tempIndex = connectorIdInt -1;
  7287. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7288. {
  7289. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  7290. {
  7291. 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))
  7292. {
  7293. //Reserved
  7294. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7295. }
  7296. 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))
  7297. {
  7298. //Reserved
  7299. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7300. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7301. goto end;
  7302. }
  7303. else
  7304. {
  7305. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7306. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7307. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7308. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7309. {
  7310. DEBUG_WARN("GB connector not allow start\n.");
  7311. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7312. goto end;
  7313. }
  7314. }// END FOR ELSE
  7315. }
  7316. } // END FOR GB_QUANTITY
  7317. }
  7318. else
  7319. {
  7320. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7321. {
  7322. tempIndex = 2;
  7323. }
  7324. else
  7325. {
  7326. tempIndex = connectorIdInt -1;
  7327. }
  7328. for (int index = 0; index < AC_QUANTITY; index++)
  7329. {
  7330. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  7331. {
  7332. 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))
  7333. {
  7334. //Reserved
  7335. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7336. }
  7337. 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))
  7338. {
  7339. //Reserved
  7340. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7341. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7342. goto end;
  7343. }
  7344. else
  7345. {
  7346. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7347. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7348. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7349. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7350. {
  7351. DEBUG_WARN("AC connector not allow start\n.");
  7352. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7353. goto end;
  7354. }
  7355. }//END FOR ELSE
  7356. }
  7357. }// END FOR AC_QUANTITY
  7358. }
  7359. if(chargingProfileIsNULL == FALSE)
  7360. {
  7361. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7362. {
  7363. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7364. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7365. //memset idTag
  7366. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7367. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7368. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7369. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7370. // Save profile to file
  7371. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7372. system(cmdBuf);
  7373. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7374. fp = fopen(cmdBuf, "w");
  7375. 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));
  7376. fclose(fp);
  7377. }
  7378. else
  7379. {
  7380. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  7381. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7382. }
  7383. }
  7384. else
  7385. {
  7386. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7387. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7388. //memset idTag
  7389. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7390. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7391. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7392. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7393. }
  7394. }
  7395. else
  7396. {
  7397. DEBUG_WARN("Connector id over\n.");
  7398. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7399. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7400. }
  7401. end:
  7402. json_object_put(RemoteStartTransaction);
  7403. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  7404. {
  7405. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  7406. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7407. }
  7408. //OCPP send RemoteStartConfirmation by first.
  7409. sendRemoteStartConfirmation(uuid, comfirmstr);
  7410. return result;
  7411. }
  7412. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  7413. {
  7414. mtrace();
  7415. int result = FAIL;
  7416. int match = FALSE;
  7417. int GunNO = 0;
  7418. int tempIndex = 0;
  7419. int transactionIdInt=0;
  7420. int transactionIdIsNULL= TRUE;
  7421. char comfirmstr[20];
  7422. json_object *RemoteStopTransaction;
  7423. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  7424. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  7425. if(server_pending == TRUE)
  7426. {
  7427. return 0;
  7428. }
  7429. RemoteStopTransaction = json_tokener_parse(payload);
  7430. if(!is_error(RemoteStopTransaction))
  7431. {
  7432. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  7433. {
  7434. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  7435. transactionIdIsNULL = FALSE;
  7436. }
  7437. }
  7438. json_object_put(RemoteStopTransaction);
  7439. if(transactionIdIsNULL == FALSE)
  7440. {
  7441. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  7442. {
  7443. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  7444. {
  7445. //check Transaction active
  7446. if(gunType[gun_index] == 'J')
  7447. {
  7448. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7449. {
  7450. tempIndex = ((gun_index==2) ? 1: 0);
  7451. }
  7452. else
  7453. {
  7454. tempIndex = gun_index;
  7455. }
  7456. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7457. {
  7458. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7459. {
  7460. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7461. {
  7462. match = TRUE;
  7463. GunNO = gun_index;
  7464. }
  7465. }
  7466. }// END FOR CHAdeMO_QUANTITY
  7467. }
  7468. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  7469. {
  7470. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7471. {
  7472. tempIndex = ((gun_index==2) ? 1: 0);
  7473. }
  7474. else
  7475. {
  7476. tempIndex = gun_index;
  7477. }
  7478. for (int index = 0; index < CCS_QUANTITY; index++)
  7479. {
  7480. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7481. {
  7482. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7483. {
  7484. match = TRUE;
  7485. GunNO = gun_index;
  7486. }
  7487. }
  7488. }// END FOR CCS_QUANTITY
  7489. }
  7490. else if(gunType[gun_index] == 'G')
  7491. {
  7492. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7493. {
  7494. tempIndex = ((gun_index==2) ? 1: 0);
  7495. }
  7496. else
  7497. {
  7498. tempIndex = gun_index;
  7499. }
  7500. for (int index = 0; index < GB_QUANTITY; index++)
  7501. {
  7502. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7503. {
  7504. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7505. {
  7506. match = TRUE;
  7507. GunNO = gun_index;
  7508. }
  7509. }
  7510. }// END FOR GB_QUANTITY
  7511. }
  7512. else if(gunType[gun_index] == 'O')
  7513. {
  7514. tempIndex = gun_index;
  7515. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7516. {
  7517. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7518. {
  7519. 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
  7520. {
  7521. match = TRUE;
  7522. GunNO = gun_index;
  7523. }
  7524. }
  7525. }// END FOR GB_QUANTITY
  7526. }
  7527. else
  7528. {
  7529. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7530. {
  7531. tempIndex = 2;
  7532. }
  7533. else
  7534. {
  7535. tempIndex = gun_index;
  7536. }
  7537. for (int index = 0; index < AC_QUANTITY; index++)
  7538. {
  7539. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7540. {
  7541. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7542. {
  7543. match = TRUE;
  7544. GunNO = gun_index;
  7545. }
  7546. }
  7547. }// END FOR CHAdeMO_QUANTITY
  7548. } // END FOR AC ELSE
  7549. }// CHECK IF ResponseTransactionId == transactionIdInt
  7550. }//END FOR
  7551. if( match == TRUE)
  7552. {
  7553. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  7554. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7555. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  7556. }
  7557. else
  7558. {
  7559. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7560. }
  7561. }
  7562. else
  7563. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7564. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  7565. return result;
  7566. }
  7567. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  7568. {
  7569. mtrace();
  7570. int result = FAIL;
  7571. int connectorIdInt=0, reservationIdInt=0;
  7572. int tempIndex = 0;
  7573. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  7574. char comfirmstr[20]={0};
  7575. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  7576. int c = 0;
  7577. char *loc;
  7578. //char *ptr;
  7579. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  7580. strcpy(sstrtemp, stringtrimspace(payload));
  7581. //***(1)connectorId ****/
  7582. c=0;
  7583. loc = strstr(sstrtemp, "connectorId");
  7584. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7585. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  7586. {
  7587. sstr[c] = loc[strlen("connectorId")+2+c];
  7588. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7589. c++;
  7590. }
  7591. sstr[c] = '\0';
  7592. connectorIdInt = atoi(sstr);
  7593. //***(2)expiryDate ****/
  7594. loc = strstr(sstrtemp, "expiryDate");
  7595. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7596. c = 0;
  7597. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  7598. {
  7599. sstr[c] = loc[3+strlen("expiryDate")+c];
  7600. c++;
  7601. }
  7602. sstr[c] = '\0';
  7603. strcpy(expiryDatestr, sstr);
  7604. //***(3)idTag ****/
  7605. loc = strstr(sstrtemp, "idTag");
  7606. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7607. c = 0;
  7608. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  7609. {
  7610. sstr[c] = loc[3+strlen("idTag")+c];
  7611. c++;
  7612. }
  7613. sstr[c] = '\0';
  7614. strcpy(idTagstr, sstr);
  7615. //***(4)parentIdTag ****/
  7616. loc = strstr(sstrtemp, "parentIdTag");
  7617. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7618. c = 0;
  7619. if(loc == NULL)
  7620. {
  7621. strcpy(parentIdTagstr, "");
  7622. }
  7623. else
  7624. {
  7625. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  7626. {
  7627. sstr[c] = loc[3+strlen("parentIdTag")+c];
  7628. c++;
  7629. }
  7630. sstr[c] = '\0';
  7631. strcpy(parentIdTagstr, sstr);
  7632. }
  7633. //***(5)reservationId ****/
  7634. c=0;
  7635. loc = strstr(sstrtemp, "reservationId");
  7636. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7637. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  7638. {
  7639. sstr[c] = loc[strlen("reservationId")+2+c];
  7640. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7641. c++;
  7642. }
  7643. sstr[c] = '\0';
  7644. reservationIdInt = atoi(sstr);
  7645. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7646. /*
  7647. enum SYSTEM_STATUS
  7648. {
  7649. SYS_MODE_BOOTING = 0,
  7650. SYS_MODE_IDLE = 1,
  7651. SYS_MODE_AUTHORIZING = 2,
  7652. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  7653. SYS_MODE_REASSIGN = 4,
  7654. SYS_MODE_PREPARING = 5,
  7655. SYS_MODE_PREPARE_FOR_EV = 6,
  7656. SYS_MODE_PREPARE_FOR_EVSE = 7,
  7657. SYS_MODE_CHARGING = 8,
  7658. SYS_MODE_TERMINATING = 9,
  7659. SYS_MODE_COMPLETE = 10,
  7660. SYS_MODE_ALARM = 11,
  7661. SYS_MODE_FAULT = 12,
  7662. SYS_MODE_RESERVATION = 13,
  7663. SYS_MODE_BOOKING = 14,
  7664. SYS_MODE_MAINTAIN = 15,
  7665. SYS_MODE_DEBUG = 16,
  7666. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  7667. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  7668. SYS_MODE_UPDATE = 19
  7669. };
  7670. */
  7671. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  7672. {
  7673. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7674. goto end;
  7675. }
  7676. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  7677. {
  7678. //check Transaction active
  7679. if(gunType[connectorIdInt -1] == 'J')
  7680. {
  7681. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7682. {
  7683. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7684. }
  7685. else
  7686. {
  7687. tempIndex = connectorIdInt -1;
  7688. }
  7689. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7690. {
  7691. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7692. {
  7693. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7694. {
  7695. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7696. {
  7697. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7698. {
  7699. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7700. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7701. }
  7702. 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'))
  7703. {
  7704. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7705. }
  7706. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7707. {
  7708. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7709. }
  7710. else
  7711. {
  7712. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7713. }
  7714. }
  7715. 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
  7716. {
  7717. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7718. }
  7719. }
  7720. else
  7721. {
  7722. //replace reservation
  7723. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7724. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7725. }
  7726. }
  7727. } // END FOR CHAdeMO_QUANTITY
  7728. }
  7729. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7730. {
  7731. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7732. {
  7733. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7734. }
  7735. else
  7736. {
  7737. tempIndex = connectorIdInt -1;
  7738. }
  7739. for (int index = 0; index < CCS_QUANTITY; index++)
  7740. {
  7741. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7742. {
  7743. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7744. {
  7745. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7746. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7747. {
  7748. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7749. {
  7750. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7751. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7752. }
  7753. 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'))
  7754. {
  7755. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7756. }
  7757. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  7758. {
  7759. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7760. }
  7761. else
  7762. {
  7763. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7764. }
  7765. }
  7766. 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
  7767. {
  7768. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7769. }
  7770. }
  7771. else
  7772. {
  7773. //replace reservation
  7774. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7775. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7776. }
  7777. }
  7778. } // END FOR CCS_QUANTITY
  7779. }
  7780. else if(gunType[connectorIdInt -1] == 'G')
  7781. {
  7782. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7783. {
  7784. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7785. }
  7786. else
  7787. {
  7788. tempIndex = connectorIdInt -1;
  7789. }
  7790. for (int index = 0; index < GB_QUANTITY; index++)
  7791. {
  7792. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7793. {
  7794. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7795. {
  7796. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7797. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7798. {
  7799. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7800. {
  7801. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7802. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7803. }
  7804. 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'))
  7805. {
  7806. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7807. }
  7808. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7809. {
  7810. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7811. }
  7812. else
  7813. {
  7814. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7815. }
  7816. }
  7817. 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
  7818. {
  7819. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7820. }
  7821. }
  7822. else
  7823. {
  7824. //replace reservation
  7825. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7826. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7827. }
  7828. }
  7829. }// END FOR GB_QUANTITY
  7830. }
  7831. else if(gunType[connectorIdInt -1] == 'O')
  7832. {
  7833. tempIndex = connectorIdInt -1;
  7834. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7835. {
  7836. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7837. {
  7838. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  7839. {
  7840. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7841. 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
  7842. {
  7843. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7844. {
  7845. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7846. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7847. }
  7848. 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'))
  7849. {
  7850. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7851. }
  7852. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7853. {
  7854. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7855. }
  7856. else
  7857. {
  7858. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7859. }
  7860. }
  7861. 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
  7862. {
  7863. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7864. }
  7865. }
  7866. else
  7867. {
  7868. //replace reservation
  7869. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7870. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7871. }
  7872. }
  7873. }// END FOR GB_QUANTITY
  7874. }
  7875. else
  7876. {
  7877. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7878. {
  7879. tempIndex = 2;
  7880. }
  7881. else
  7882. {
  7883. tempIndex = (connectorIdInt -1);
  7884. }
  7885. for (int index = 0; index < AC_QUANTITY; index++)
  7886. {
  7887. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7888. {
  7889. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7890. {
  7891. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7892. {
  7893. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7894. {
  7895. 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))
  7896. {
  7897. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7898. }
  7899. else
  7900. {
  7901. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7902. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7903. }
  7904. }
  7905. 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'))
  7906. {
  7907. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7908. }
  7909. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7910. {
  7911. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7912. }
  7913. else
  7914. {
  7915. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7916. }
  7917. }
  7918. 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
  7919. {
  7920. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7921. }
  7922. }
  7923. else
  7924. {
  7925. //replace reservation
  7926. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7927. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7928. }
  7929. }
  7930. } // END FOR AC_QUANTITY
  7931. }
  7932. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7933. }
  7934. else if(connectorIdInt == 0)
  7935. {
  7936. //check Transaction active
  7937. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7938. {
  7939. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7940. {
  7941. 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'))
  7942. {
  7943. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7944. goto end;
  7945. }
  7946. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7947. {
  7948. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7949. goto end;
  7950. }
  7951. 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
  7952. {
  7953. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7954. goto end;
  7955. }
  7956. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7957. {
  7958. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7959. goto end;
  7960. }
  7961. }
  7962. }// END FOR CHAdeMO_QUANTITY
  7963. for (int index = 0; index < CCS_QUANTITY; index++)
  7964. {
  7965. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7966. {
  7967. 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'))
  7968. {
  7969. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7970. goto end;
  7971. }
  7972. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  7973. {
  7974. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7975. goto end;
  7976. }
  7977. 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
  7978. {
  7979. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7980. goto end;
  7981. }
  7982. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7983. {
  7984. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7985. goto end;
  7986. }
  7987. }
  7988. } // END FOR CCS_QUANTITY
  7989. for (int index = 0; index < GB_QUANTITY; index++)
  7990. {
  7991. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7992. {
  7993. 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'))
  7994. {
  7995. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7996. goto end;
  7997. }
  7998. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7999. {
  8000. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8001. goto end;
  8002. }
  8003. 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
  8004. {
  8005. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8006. goto end;
  8007. }
  8008. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8009. {
  8010. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8011. goto end;
  8012. }
  8013. }
  8014. } // END FOR GB_QUANTITY
  8015. for (int index = 0; index < AC_QUANTITY; index++)
  8016. {
  8017. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  8018. {
  8019. 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'))
  8020. {
  8021. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8022. goto end;
  8023. }
  8024. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8025. {
  8026. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8027. goto end;
  8028. }
  8029. 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
  8030. {
  8031. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8032. goto end;
  8033. }
  8034. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8035. {
  8036. 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))
  8037. {
  8038. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8039. goto end;
  8040. }
  8041. }
  8042. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8043. {
  8044. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8045. goto end;
  8046. }
  8047. }
  8048. }// END FOR AC_QUANTITY
  8049. //The connectorId is 0
  8050. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  8051. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8052. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  8053. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  8054. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  8055. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  8056. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  8057. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  8058. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  8059. result = TRUE;
  8060. return result;
  8061. }
  8062. else
  8063. {
  8064. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8065. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8066. }
  8067. if(strcmp(comfirmstr,"Accepted") == 0)
  8068. {
  8069. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  8070. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  8071. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  8072. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  8073. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  8074. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  8075. result = TRUE;
  8076. return result;
  8077. }
  8078. end:
  8079. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  8080. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  8081. return result;
  8082. }
  8083. int handleResetRequest(char *uuid, char *payload)
  8084. {
  8085. mtrace();
  8086. int result = FAIL;
  8087. char sstr[10]={0},sstrtemp[30]={ 0 };
  8088. char typestr[10]={0};
  8089. char comfirmstr[20]={0};
  8090. int c = 0;
  8091. char *loc;
  8092. DEBUG_INFO("handleResetRequest...\n");
  8093. strcpy(sstrtemp, stringtrimspace(payload));
  8094. loc = strstr(sstrtemp, "type");
  8095. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8096. c = 0;
  8097. while (loc[3+strlen("type")+c] != '\"')
  8098. {
  8099. sstr[c] = loc[3+strlen("type")+c];
  8100. c++;
  8101. }
  8102. sstr[c] = '\0';
  8103. strcpy(typestr,sstr);
  8104. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  8105. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  8106. {
  8107. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  8108. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  8109. result = TRUE;
  8110. return result;
  8111. }
  8112. else
  8113. {
  8114. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  8115. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  8116. goto errorend;
  8117. }
  8118. errorend:
  8119. sendResetConfirmation(uuid, comfirmstr);
  8120. return result;
  8121. }
  8122. int handleSendLocalListRequest(char *uuid, char *payload)
  8123. {
  8124. mtrace();
  8125. int result = FAIL;
  8126. int listVersionInt;
  8127. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  8128. char listsearch[]="listVersion";
  8129. char updateTypesearch[]="updateType";
  8130. char localAuthorizationListsearch[]="localAuthorizationList";
  8131. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  8132. char CardList[500][160]={0};
  8133. char updateTypestr[15]={0};
  8134. char idTagstr[20]={0};
  8135. char parentIdTag[20]={0};
  8136. char expiryDate[30]={0};
  8137. char idTagstatus[16]={0};
  8138. int c = 0;
  8139. int i = 0;
  8140. char *delim1 = "}";
  8141. char * pch;
  8142. char *loc;
  8143. //char *ptr;
  8144. char comfirmstr[20];
  8145. //int n_localAuthorizations = 0;
  8146. int checkState_Faulted = FALSE;
  8147. DEBUG_INFO("handleSendLocalListRequest...\n");
  8148. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  8149. {
  8150. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8151. goto end;
  8152. }
  8153. //check Charge Point state
  8154. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8155. {
  8156. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8157. {
  8158. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8159. }
  8160. }
  8161. for (int index = 0; index < CCS_QUANTITY; index++)
  8162. {
  8163. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8164. {
  8165. checkState_Faulted = TRUE; //OCPP Status
  8166. }
  8167. }
  8168. for (int index = 0; index < GB_QUANTITY; index++)
  8169. {
  8170. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8171. {
  8172. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8173. }
  8174. }
  8175. //check Charge Point state
  8176. for (int index = 0; index < AC_QUANTITY; index++)
  8177. {
  8178. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8179. {
  8180. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8181. }
  8182. }
  8183. if(checkState_Faulted == TRUE)
  8184. {
  8185. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8186. goto end;
  8187. }
  8188. //Filter payload space
  8189. strcpy(sstrtemp, stringtrimspace(payload));
  8190. //listVersion
  8191. c = 0;
  8192. loc = strstr(sstrtemp, listsearch);
  8193. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  8194. {
  8195. sstr[c] = loc[strlen("listVersion")+2+c];
  8196. c++;
  8197. }
  8198. sstr[c] = '\0';
  8199. listVersionInt = atoi(sstr);
  8200. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8201. //updateType
  8202. loc = strstr(sstrtemp, updateTypesearch);
  8203. c = 0;
  8204. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  8205. {
  8206. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  8207. c++;
  8208. }
  8209. sstr[c] = '\0';
  8210. strcpy(updateTypestr, sstr);
  8211. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  8212. //localAuthorizationList
  8213. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8214. loc = strstr(sstrtemp, localAuthorizationListsearch);
  8215. if(loc != NULL) // localAuthorizationList is not NULL
  8216. {
  8217. //Check UpdateType
  8218. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8219. {
  8220. //Local list full update
  8221. printf("Local list full update.\n");
  8222. OCPP_getListVerion();
  8223. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8224. {
  8225. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8226. goto end;
  8227. }
  8228. OCPP_cleanLocalList();
  8229. }
  8230. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8231. {
  8232. //Local list different update
  8233. printf("Local list different update.\n");
  8234. OCPP_getListVerion();
  8235. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8236. {
  8237. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  8238. goto end;
  8239. }
  8240. }
  8241. else
  8242. {
  8243. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8244. goto end;
  8245. }
  8246. c = 0;
  8247. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  8248. {
  8249. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  8250. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8251. c++;
  8252. }
  8253. sstr[c] = '\0';
  8254. //DEBUG_INFO("sstr=%s\n", sstr);
  8255. //parsing strings to words
  8256. i = 0;
  8257. pch = strtok(sstr,delim1);
  8258. while (pch != NULL)
  8259. {
  8260. strcpy(CardList[i], pch);
  8261. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  8262. pch = strtok (NULL, delim1);
  8263. i = i + 1;
  8264. }
  8265. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  8266. //local Authorizations List Numbers
  8267. //n_localAuthorizations = i;
  8268. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8269. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  8270. c= 0;
  8271. while(c < i) // i is CardList Number
  8272. {
  8273. //Search "IdToken"
  8274. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8275. loc = strstr(CardList[c], "idTag");
  8276. int j = 0;
  8277. while (loc[3+strlen("idTag")+j] != '\"')
  8278. {
  8279. sstr[j] = loc[3+strlen("idTag")+j];
  8280. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8281. j++;
  8282. }
  8283. sstr[j] = '\0';
  8284. strcpy(idTagstr, sstr);
  8285. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  8286. //Search "expiryDate"
  8287. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8288. loc = strstr(CardList[c], "expiryDate");
  8289. j = 0;
  8290. if(loc != NULL)
  8291. {
  8292. while (loc[3+strlen("expiryDate")+j] != '\"')
  8293. {
  8294. sstr[j] = loc[3+strlen("expiryDate")+j];
  8295. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8296. j++;
  8297. }
  8298. sstr[j] = '\0';
  8299. strcpy(expiryDate, sstr);
  8300. }
  8301. else
  8302. {
  8303. strcpy(expiryDate, "");
  8304. }
  8305. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  8306. //Search "parentIdTag"
  8307. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8308. loc = strstr(CardList[c], "parentIdTag");
  8309. j = 0;
  8310. if(loc != NULL)
  8311. {
  8312. while (loc[3+strlen("parentIdTag")+j] != '\"')
  8313. {
  8314. sstr[j] = loc[3+strlen("parentIdTag")+j];
  8315. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8316. j++;
  8317. }
  8318. sstr[j] = '\0';
  8319. strcpy(parentIdTag, sstr);
  8320. }
  8321. else
  8322. {
  8323. strcpy(parentIdTag, "");
  8324. }
  8325. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  8326. //Search "status"
  8327. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8328. loc = strstr(CardList[c], "status");
  8329. j = 0;
  8330. while (loc[3+strlen("status")+j] != '\"')
  8331. {
  8332. sstr[j] = loc[3+strlen("status")+j];
  8333. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8334. j++;
  8335. }
  8336. sstr[j] = '\0';
  8337. strcpy(idTagstatus, sstr);
  8338. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  8339. OCPP_getIdTagFromLocalList(idTagstr);
  8340. //OCPP_getIdTagFromLocalList("test"); For Test
  8341. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  8342. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  8343. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8344. {
  8345. //Local list full update
  8346. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8347. // update list
  8348. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8349. //DEBUG_INFO("Local list full update. 1\n");
  8350. //OCPP_get_TableAuthlocalAllData();
  8351. //DEBUG_INFO("Local list full update. 2\n");
  8352. }
  8353. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8354. {
  8355. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8356. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  8357. }
  8358. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  8359. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  8360. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  8361. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  8362. c++;
  8363. }
  8364. }
  8365. else
  8366. {
  8367. //Check UpdateType
  8368. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8369. {
  8370. //Local list full update
  8371. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  8372. OCPP_cleanLocalList();
  8373. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8374. goto end;
  8375. }
  8376. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8377. {
  8378. //Local list different update
  8379. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  8380. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8381. goto end;
  8382. }
  8383. }
  8384. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8385. end:
  8386. sendSendLocalListConfirmation(uuid, comfirmstr);
  8387. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  8388. return result;
  8389. }
  8390. #define MAX 200
  8391. int handleSetChargingProfileRequest(char *uuid, char *payload)
  8392. {
  8393. mtrace();
  8394. int result = FAIL;
  8395. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  8396. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  8397. char chargingProfilePurposeStr[30]={0};
  8398. char chargingProfileKindStr[16]={0};
  8399. char recurrencyKindStr[10]={0};
  8400. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  8401. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  8402. int chargingSchedulePeriodCount = 0;
  8403. char comfirmstr[20]={0};
  8404. int meet= FALSE;
  8405. FILE *fptr1;
  8406. char filename[MAX]={0};
  8407. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  8408. char rmFileCmd[50]={0};
  8409. char tempchargingProfilePurposeStr[30]={0};
  8410. char word[1600]={0};
  8411. int n_chargingProfile = 0;
  8412. json_object *SetChargingProfile;
  8413. DEBUG_INFO("handleSetChargingProfileRequest\n");
  8414. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  8415. SetChargingProfile = json_tokener_parse(payload);
  8416. if(!is_error(SetChargingProfile))
  8417. {
  8418. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  8419. {
  8420. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  8421. if(connectorIdInt == 0)
  8422. {
  8423. memset(&ShmOCPP16Data->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  8424. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  8425. }
  8426. else
  8427. {
  8428. memset(&ShmOCPP16Data->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  8429. ShmOCPP16Data->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  8430. }
  8431. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  8432. }
  8433. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  8434. {
  8435. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  8436. {
  8437. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  8438. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8439. {
  8440. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8441. }
  8442. else
  8443. {
  8444. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8445. }
  8446. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  8447. }
  8448. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  8449. {
  8450. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  8451. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8452. {
  8453. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  8454. }
  8455. else
  8456. {
  8457. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  8458. }
  8459. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  8460. }
  8461. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8462. {
  8463. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  8464. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8465. {
  8466. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8467. }
  8468. else
  8469. {
  8470. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8471. }
  8472. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  8473. }
  8474. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  8475. {
  8476. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  8477. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8478. {
  8479. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8480. }
  8481. else
  8482. {
  8483. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8484. }
  8485. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  8486. }
  8487. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  8488. {
  8489. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  8490. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8491. {
  8492. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  8493. }
  8494. else
  8495. {
  8496. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  8497. }
  8498. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  8499. }
  8500. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  8501. {
  8502. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  8503. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8504. {
  8505. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8506. }
  8507. else
  8508. {
  8509. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8510. }
  8511. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  8512. }
  8513. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  8514. {
  8515. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  8516. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8517. {
  8518. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  8519. }
  8520. else
  8521. {
  8522. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  8523. }
  8524. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  8525. }
  8526. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  8527. {
  8528. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  8529. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8530. {
  8531. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  8532. }
  8533. else
  8534. {
  8535. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  8536. }
  8537. //DEBUG_INFO("validToStr: %s\n", validToStr);
  8538. }
  8539. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  8540. {
  8541. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  8542. {
  8543. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  8544. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8545. {
  8546. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8547. }
  8548. else
  8549. {
  8550. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8551. }
  8552. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  8553. }
  8554. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  8555. {
  8556. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  8557. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8558. {
  8559. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8560. }
  8561. else
  8562. {
  8563. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8564. }
  8565. //DEBUG_INFO("durationInt: %d\n", durationInt);
  8566. }
  8567. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  8568. {
  8569. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  8570. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8571. {
  8572. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8573. }
  8574. else
  8575. {
  8576. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8577. }
  8578. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  8579. }
  8580. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  8581. {
  8582. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  8583. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8584. {
  8585. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8586. }
  8587. else
  8588. {
  8589. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8590. }
  8591. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  8592. }
  8593. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  8594. {
  8595. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  8596. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  8597. if(chargingSchedulePeriodCount <= 10)
  8598. {
  8599. 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++)
  8600. {
  8601. 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)
  8602. {
  8603. 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"));
  8604. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8605. {
  8606. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  8607. }
  8608. else
  8609. {
  8610. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  8611. }
  8612. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  8613. }
  8614. 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)
  8615. {
  8616. 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"));
  8617. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8618. {
  8619. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  8620. }
  8621. else
  8622. {
  8623. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  8624. }
  8625. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  8626. }
  8627. 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)
  8628. {
  8629. 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"));
  8630. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8631. {
  8632. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  8633. }
  8634. else
  8635. {
  8636. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  8637. }
  8638. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  8639. }
  8640. }
  8641. }
  8642. }
  8643. }
  8644. }
  8645. }
  8646. json_object_put(SetChargingProfile);
  8647. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8648. {
  8649. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8650. goto end;
  8651. }
  8652. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8653. {
  8654. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8655. if(connectorIdInt != 0)
  8656. {
  8657. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8658. goto end;
  8659. }
  8660. strcpy(filename, ChargePointMaxProfile_JSON );
  8661. fptr1 = fopen(filename, "r");
  8662. if (!fptr1)
  8663. {
  8664. //file not exist
  8665. DEBUG_INFO("Unable to open the input file!!\n");
  8666. fptr1 = fopen(filename, "w+");
  8667. }
  8668. else
  8669. {
  8670. //Check Charging Profile Count
  8671. while(fscanf(fptr1, "%s", word) != EOF)
  8672. {
  8673. //DEBUG_INFO("word=%s\n",word);
  8674. if(strstr(word, "chargingProfileId")!= NULL)
  8675. {
  8676. //DEBUG_INFO("test chargingProfileId \n");
  8677. n_chargingProfile = n_chargingProfile + 1;
  8678. //DEBUG_INFO("chargingProfileId Found\n");
  8679. }
  8680. }
  8681. }
  8682. fclose(fptr1);
  8683. }
  8684. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8685. {
  8686. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8687. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8688. {
  8689. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8690. goto end;
  8691. }
  8692. memset(filename, 0, ARRAY_SIZE(filename));
  8693. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8694. fptr1 = fopen(filename, "r");
  8695. if (!fptr1)
  8696. {
  8697. //file not exist
  8698. //DEBUG_INFO("Unable to open the input file!!\n");
  8699. fptr1 = fopen(filename, "w+");
  8700. }
  8701. else
  8702. {
  8703. //Check Charging Profile Count
  8704. while(fscanf(fptr1, "%s", word) != EOF)
  8705. {
  8706. //DEBUG_INFO("word=%s\n",word);
  8707. if(strstr(word, "chargingProfileId")!= NULL)
  8708. {
  8709. //DEBUG_INFO("test chargingProfileId \n");
  8710. n_chargingProfile = n_chargingProfile + 1;
  8711. //DEBUG_INFO("chargingProfileId Found\n");
  8712. }
  8713. }
  8714. }
  8715. fclose(fptr1);
  8716. }
  8717. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8718. {
  8719. //printf("set chargingProfile 1-4\n");
  8720. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8721. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  8722. if(connectorIdInt == 0)
  8723. {
  8724. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8725. goto end;
  8726. }
  8727. int tempIndex = 0;
  8728. //check Transaction active
  8729. if(gunType[connectorIdInt -1] == 'J')
  8730. {
  8731. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8732. {
  8733. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8734. }
  8735. else
  8736. {
  8737. tempIndex = connectorIdInt -1;
  8738. }
  8739. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8740. {
  8741. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8742. {
  8743. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8744. {
  8745. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8746. {
  8747. meet = TRUE;
  8748. break;
  8749. }
  8750. }
  8751. }
  8752. }
  8753. }
  8754. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  8755. {
  8756. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8757. {
  8758. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8759. }
  8760. else
  8761. {
  8762. tempIndex = connectorIdInt -1;
  8763. }
  8764. for (int index = 0; index < CCS_QUANTITY; index++)
  8765. {
  8766. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8767. {
  8768. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8769. {
  8770. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8771. {
  8772. meet = TRUE;
  8773. break;
  8774. }
  8775. }
  8776. }
  8777. }
  8778. }
  8779. else if(gunType[connectorIdInt -1] == 'G')
  8780. {
  8781. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8782. {
  8783. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8784. }
  8785. else
  8786. {
  8787. tempIndex = connectorIdInt -1;
  8788. }
  8789. for (int index = 0; index < GB_QUANTITY; index++)
  8790. {
  8791. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8792. {
  8793. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8794. {
  8795. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8796. {
  8797. meet = TRUE;
  8798. break;
  8799. }
  8800. }
  8801. }
  8802. }
  8803. }
  8804. else if(gunType[connectorIdInt -1] == 'O')
  8805. {
  8806. tempIndex = connectorIdInt -1;
  8807. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8808. {
  8809. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8810. {
  8811. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8812. {
  8813. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8814. {
  8815. meet = TRUE;
  8816. break;
  8817. }
  8818. }
  8819. }
  8820. }
  8821. }
  8822. else
  8823. {
  8824. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8825. {
  8826. tempIndex = 2;
  8827. }
  8828. else
  8829. {
  8830. tempIndex = (connectorIdInt -1);
  8831. }
  8832. for (int index = 0; index < AC_QUANTITY; index++)
  8833. {
  8834. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8835. {
  8836. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8837. {
  8838. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8839. {
  8840. meet = TRUE;
  8841. break;
  8842. }
  8843. }
  8844. }
  8845. }
  8846. }
  8847. //check Transaction active
  8848. if(meet == FALSE)
  8849. {
  8850. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8851. goto end;
  8852. }
  8853. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8854. {
  8855. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8856. goto end;
  8857. }
  8858. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8859. fptr1 = fopen(filename, "r");
  8860. if (!fptr1)
  8861. {
  8862. //file not exist
  8863. DEBUG_INFO("Unable to open the input file!!\n");
  8864. fptr1 = fopen(filename, "w+");
  8865. }
  8866. else
  8867. {
  8868. //Check Charging Profile Count
  8869. while(fscanf(fptr1, "%s", word) != EOF)
  8870. {
  8871. //DEBUG_INFO("word=%s\n",word);
  8872. if(strstr(word, "chargingProfileId")!= NULL)
  8873. {
  8874. //DEBUG_INFO("test chargingProfileId \n");
  8875. n_chargingProfile = n_chargingProfile + 1;
  8876. //DEBUG_INFO("chargingProfileId Found\n");
  8877. }
  8878. }
  8879. }
  8880. fclose(fptr1);
  8881. }
  8882. // Check ChargeProfileMaxStackLevel
  8883. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8884. {
  8885. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8886. goto end;
  8887. }
  8888. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8889. {
  8890. int i = 0;
  8891. char fnametemp[200]={0};
  8892. n_chargingProfile = 0;
  8893. //Check ChargePointMaxProfile.json exit
  8894. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8895. {
  8896. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8897. //Check Charging Profile Count
  8898. while(fscanf(fptr1, "%s", word) != EOF)
  8899. {
  8900. //DEBUG_INFO("word=%s\n",word);
  8901. if(strstr(word, "chargingProfileId")!= NULL)
  8902. {
  8903. //DEBUG_INFO("test chargingProfileId \n");
  8904. n_chargingProfile = n_chargingProfile + 1;
  8905. i = i + 1;
  8906. //DEBUG_INFO("chargingProfileId Found\n");
  8907. }
  8908. memset(word, 0, ARRAY_SIZE(word));
  8909. }
  8910. fclose(fptr1);
  8911. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8912. }
  8913. //Check TxDefaultProfile_0.json exit
  8914. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8915. {
  8916. i = 0;
  8917. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  8918. //Check Charging Profile Count
  8919. while(fscanf(fptr1, "%s", word) != EOF)
  8920. {
  8921. //DEBUG_INFO("word=%s\n",word);
  8922. if(strstr(word, "chargingProfileId")!= NULL)
  8923. {
  8924. //DEBUG_INFO("test chargingProfileId \n");
  8925. n_chargingProfile = n_chargingProfile + 1;
  8926. i = i + 1;
  8927. //DEBUG_INFO("chargingProfileId Found\n");
  8928. }
  8929. memset(word, 0, ARRAY_SIZE(word));
  8930. }
  8931. fclose(fptr1);
  8932. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  8933. }
  8934. //Check TxDefaultProfile_%d.json
  8935. for(int j=1; j <= gunTotalNumber; j++)
  8936. {
  8937. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8938. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8939. if((access(fnametemp,F_OK))!=-1)
  8940. {
  8941. i = 0;
  8942. fptr1 = fopen(fnametemp, "r");
  8943. //Check Charging Profile Count
  8944. while(fscanf(fptr1, "%s", word) != EOF)
  8945. {
  8946. //DEBUG_INFO("word=%s\n",word);
  8947. if(strstr(word, "chargingProfileId")!= NULL)
  8948. {
  8949. //DEBUG_INFO("test chargingProfileId \n");
  8950. n_chargingProfile = n_chargingProfile + 1;
  8951. i = i + 1;
  8952. //DEBUG_INFO("chargingProfileId Found\n");
  8953. }
  8954. memset(word, 0, ARRAY_SIZE(word));
  8955. }
  8956. fclose(fptr1);
  8957. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8958. }
  8959. }
  8960. //Check TxProfile_%d.json
  8961. for(int j=1; j <= gunTotalNumber; j++)
  8962. {
  8963. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8964. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8965. if((access(fnametemp,F_OK))!=-1)
  8966. {
  8967. i = 0;
  8968. fptr1 = fopen(fnametemp, "r");
  8969. //Check Charging Profile Count
  8970. while(fscanf(fptr1, "%s", word) != EOF)
  8971. {
  8972. //DEBUG_INFO("word=%s\n",word);
  8973. if(strstr(word, "chargingProfileId")!= NULL)
  8974. {
  8975. //DEBUG_INFO("test chargingProfileId \n");
  8976. n_chargingProfile = n_chargingProfile + 1;
  8977. i = i + 1;
  8978. //DEBUG_INFO("chargingProfileId Found\n");
  8979. }
  8980. memset(word, 0, ARRAY_SIZE(word));
  8981. }
  8982. fclose(fptr1);
  8983. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8984. }
  8985. }
  8986. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  8987. {
  8988. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8989. goto end;
  8990. }
  8991. }
  8992. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8993. //**********************************Write to File********************************************************/
  8994. FILE *infile;
  8995. FILE *outfile;
  8996. infile = fopen (filename, "r");
  8997. outfile = fopen (tempfile, "w");
  8998. int d =0;
  8999. d = fgetc(infile);
  9000. rewind(infile);
  9001. if(d == EOF)
  9002. {
  9003. // Profile is empty
  9004. fprintf(outfile,"%s\n",payload);
  9005. fclose(infile);
  9006. fclose(outfile);
  9007. sprintf(rmFileCmd,"rm -f %s",filename);
  9008. system(rmFileCmd);
  9009. rename(tempfile, filename);
  9010. }
  9011. else
  9012. {
  9013. // Profile is not empty
  9014. char buf[2048]={0};
  9015. int ChargingProfileAdded = FALSE;
  9016. while (fgets(buf, sizeof(buf), infile) != NULL)
  9017. {
  9018. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9019. json_object *tmpChargingProfile;
  9020. tmpChargingProfile = json_tokener_parse(buf);
  9021. if(!is_error(SetChargingProfile))
  9022. {
  9023. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  9024. {
  9025. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  9026. }
  9027. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  9028. {
  9029. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  9030. {
  9031. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  9032. }
  9033. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  9034. {
  9035. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  9036. }
  9037. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9038. {
  9039. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  9040. }
  9041. }
  9042. }
  9043. json_object_put(tmpChargingProfile);
  9044. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  9045. {
  9046. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9047. {
  9048. //DEBUG_INFO("update set chargingProfile to file -0\n");
  9049. if(ChargingProfileAdded == FALSE)
  9050. {
  9051. fprintf(outfile,"%s\n",payload);
  9052. ChargingProfileAdded = TRUE;
  9053. }
  9054. }
  9055. else
  9056. {
  9057. if(tempstackLevelInt < stackLevelInt)
  9058. {
  9059. if(ChargingProfileAdded == FALSE)
  9060. {
  9061. fprintf(outfile,"%s\n",buf);
  9062. fprintf(outfile,"%s\n",payload);
  9063. ChargingProfileAdded = TRUE;
  9064. }
  9065. else
  9066. {
  9067. fprintf(outfile,"%s\n",buf);
  9068. }
  9069. }
  9070. else
  9071. {
  9072. if(ChargingProfileAdded == FALSE)
  9073. {
  9074. fprintf(outfile,"%s\n",buf);
  9075. fprintf(outfile,"%s\n",payload);
  9076. ChargingProfileAdded = TRUE;
  9077. }
  9078. else
  9079. {
  9080. fprintf(outfile,"%s\n",buf);
  9081. }
  9082. }
  9083. }
  9084. }
  9085. else
  9086. {
  9087. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9088. {
  9089. if(ChargingProfileAdded == FALSE)
  9090. {
  9091. fprintf(outfile,"%s\n",buf);
  9092. fprintf(outfile,"%s\n",payload);
  9093. ChargingProfileAdded = TRUE;
  9094. }
  9095. else
  9096. {
  9097. fprintf(outfile,"%s\n",buf);
  9098. }
  9099. }
  9100. else if(tempstackLevelInt < stackLevelInt)
  9101. {
  9102. if(ChargingProfileAdded == FALSE)
  9103. {
  9104. fprintf(outfile,"%s\n",buf);
  9105. fprintf(outfile,"%s\n",payload);
  9106. ChargingProfileAdded = TRUE;
  9107. }
  9108. else
  9109. {
  9110. fprintf(outfile,"%s\n",buf);
  9111. }
  9112. }
  9113. else
  9114. {
  9115. if(ChargingProfileAdded == FALSE)
  9116. {
  9117. fprintf(outfile,"%s\n",buf);
  9118. fprintf(outfile,"%s\n",payload);
  9119. ChargingProfileAdded = TRUE;
  9120. }
  9121. else
  9122. {
  9123. fprintf(outfile,"%s\n",buf);
  9124. }
  9125. }
  9126. }
  9127. } // end of while loop
  9128. fclose(infile);
  9129. fclose(outfile);
  9130. sprintf(rmFileCmd,"rm -f %s",filename);
  9131. system(rmFileCmd);
  9132. rename(tempfile, filename);
  9133. }
  9134. sleep(1);
  9135. result = TRUE;
  9136. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9137. end:
  9138. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  9139. {
  9140. if(connectorIdInt == 0)
  9141. {
  9142. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9143. {
  9144. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx]);
  9145. }
  9146. }
  9147. else
  9148. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1]);
  9149. }
  9150. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  9151. return result;
  9152. }
  9153. int handleTriggerMessageRequest(char *uuid, char *payload)
  9154. {
  9155. mtrace();
  9156. int result = FAIL;
  9157. int connectorIdIsNULL = FALSE;
  9158. int connectorIdInt =0;
  9159. char sstr[40]={0},sstrtemp[100]={ 0 };
  9160. char requestedMessagestr[40]={0};
  9161. char comfirmstr[20]={0};
  9162. int c = 0;
  9163. char *loc;
  9164. DEBUG_INFO("handleTriggerMessageRequest\n");
  9165. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  9166. strcpy(sstrtemp, stringtrimspace(payload));
  9167. c = 0;
  9168. loc = strstr(sstrtemp, "requestedMessage");
  9169. while (loc[3+strlen("requestedMessage")+c] != '\"')
  9170. {
  9171. sstr[c] = loc[3+strlen("requestedMessage")+c];
  9172. c++;
  9173. }
  9174. sstr[c] = '\0';
  9175. strcpy(requestedMessagestr, sstr);
  9176. c = 0;
  9177. loc = strstr(sstrtemp, "connectorId");
  9178. if(loc == NULL)
  9179. {
  9180. connectorIdIsNULL = TRUE;
  9181. }
  9182. else
  9183. {
  9184. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9185. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  9186. {
  9187. sstr[c] = loc[strlen("connectorId")+2+c];
  9188. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9189. c++;
  9190. }
  9191. sstr[c] = '\0';
  9192. connectorIdInt = atoi(sstr);
  9193. }
  9194. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  9195. {
  9196. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  9197. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  9198. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  9199. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  9200. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  9201. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  9202. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  9203. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  9204. {
  9205. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  9206. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9207. return TRUE;
  9208. }
  9209. else
  9210. {
  9211. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9212. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9213. }
  9214. }
  9215. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  9216. {
  9217. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  9218. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9219. return TRUE;
  9220. }
  9221. //==========================
  9222. // Trigger message
  9223. //==========================
  9224. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  9225. {
  9226. if((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) &&
  9227. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) &&
  9228. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) &&
  9229. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING) )
  9230. {
  9231. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  9232. }
  9233. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  9234. }
  9235. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  9236. {
  9237. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  9238. }
  9239. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  9240. {
  9241. //sendBootNotificationRequest();
  9242. server_sign = FALSE;
  9243. }
  9244. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  9245. {
  9246. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  9247. }
  9248. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  9249. {
  9250. if(connectorIdIsNULL == FALSE)
  9251. {
  9252. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9253. {
  9254. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  9255. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  9256. }
  9257. }
  9258. else
  9259. {
  9260. for(int idx=0;idx< gunTotalNumber;idx++)
  9261. {
  9262. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  9263. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  9264. }
  9265. }
  9266. }
  9267. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  9268. {
  9269. if(connectorIdIsNULL == FALSE)
  9270. {
  9271. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9272. {
  9273. cpinitateMsg.bits[connectorIdInt -1].StatusNotificationReq = 1;
  9274. }
  9275. }
  9276. else
  9277. {
  9278. for(int idx=0;idx< gunTotalNumber;idx++)
  9279. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  9280. }
  9281. }
  9282. return result;
  9283. }
  9284. int handleUnlockConnectorRequest(char *uuid, char *payload)
  9285. {
  9286. mtrace();
  9287. int result = FAIL;
  9288. int connectorIdInt =0;
  9289. char comfirmstr[20]={0};
  9290. int tempIndex = 0;
  9291. json_object *UnlockConnector;
  9292. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  9293. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  9294. UnlockConnector = json_tokener_parse(payload);
  9295. if(!is_error(UnlockConnector))
  9296. {
  9297. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  9298. {
  9299. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  9300. }
  9301. }
  9302. json_object_put(UnlockConnector);
  9303. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  9304. if(gunTotalNumber == 0)
  9305. {
  9306. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9307. goto end;
  9308. }
  9309. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  9310. {
  9311. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9312. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9313. goto end;
  9314. }
  9315. else
  9316. {
  9317. //check Transaction active
  9318. if(gunType[connectorIdInt-1] == 'J')
  9319. {
  9320. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9321. {
  9322. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9323. }
  9324. else
  9325. {
  9326. tempIndex = connectorIdInt -1;
  9327. }
  9328. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9329. {
  9330. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9331. {
  9332. //stop Transaction
  9333. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9334. }
  9335. }
  9336. }
  9337. else if((gunType[connectorIdInt-1] == 'U')||(gunType[connectorIdInt-1] == 'E'))
  9338. {
  9339. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9340. {
  9341. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9342. }
  9343. else
  9344. {
  9345. tempIndex = connectorIdInt -1;
  9346. }
  9347. for (int index = 0; index < CCS_QUANTITY; index++)
  9348. {
  9349. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9350. {
  9351. //stop Transaction
  9352. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9353. }
  9354. }
  9355. }
  9356. else if(gunType[connectorIdInt-1] == 'G')
  9357. {
  9358. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9359. {
  9360. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9361. }
  9362. else
  9363. {
  9364. tempIndex = connectorIdInt -1;
  9365. }
  9366. for (int index = 0; index < GB_QUANTITY; index++)
  9367. {
  9368. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  9369. {
  9370. //stop Transaction
  9371. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9372. }
  9373. }
  9374. }
  9375. else if(gunType[connectorIdInt-1] == 'O')
  9376. {
  9377. tempIndex = connectorIdInt -1;
  9378. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9379. {
  9380. 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)))
  9381. {
  9382. //stop Transaction
  9383. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9384. }
  9385. }
  9386. }
  9387. else
  9388. {
  9389. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9390. {
  9391. tempIndex = 2;
  9392. }
  9393. else
  9394. {
  9395. tempIndex = connectorIdInt-1;
  9396. }
  9397. for (int index = 0; index < AC_QUANTITY; index++)
  9398. {
  9399. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9400. {
  9401. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9402. }
  9403. }
  9404. }
  9405. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  9406. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  9407. result = TRUE;
  9408. return result;
  9409. }
  9410. end:
  9411. //json_object_put(obj); --- remove temporally
  9412. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  9413. return result;
  9414. }
  9415. static char UpdateFirmwarepayloadData[300]={0};
  9416. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  9417. {
  9418. mtrace();
  9419. int result = FAIL;
  9420. pthread_t t;
  9421. sendUpdateFirmwareConfirmation(uuid);
  9422. memset(UpdateFirmwarepayloadData, 0, 300);
  9423. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  9424. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  9425. ////pthread_join(t, NULL); //
  9426. //pthread_detach(t);
  9427. //sendUpdateFirmwareConfirmation(uuid);
  9428. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  9429. return result;
  9430. }
  9431. void *UpdateFirmwareProcess(void *data)
  9432. {
  9433. pthread_detach(pthread_self());
  9434. mtrace();
  9435. int retriesInt =0, retryIntervalInt=0;
  9436. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  9437. int port=0;
  9438. char locationstr[160]={0}, retrieveDatestr[30]={0};
  9439. int isSuccess = 0;
  9440. char ftpbuf[200];
  9441. char temp[100];
  9442. char * pch;
  9443. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  9444. json_object *UpdateFirmware;
  9445. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  9446. if(!is_error(UpdateFirmware))
  9447. {
  9448. // Required data
  9449. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  9450. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  9451. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  9452. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  9453. // Optional data
  9454. if(json_object_object_get(UpdateFirmware, "retries"))
  9455. {
  9456. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  9457. }
  9458. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  9459. {
  9460. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  9461. }
  9462. }
  9463. json_object_put(UpdateFirmware);
  9464. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9465. memset(path, 0, ARRAY_SIZE(path));
  9466. system("rm -f /mnt/*");
  9467. if(strncmp(locationstr,"http", 4) == 0)
  9468. {
  9469. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9470. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  9471. // protocol, user, password, host, path);
  9472. sprintf(ftppath,"/%s", path);
  9473. DEBUG_INFO("locationstr: %s\n", locationstr);
  9474. DEBUG_INFO("protocol: %s\n",protocol);
  9475. DEBUG_INFO("host: %s\n",host);
  9476. DEBUG_INFO("path: %s\n",path);
  9477. DEBUG_INFO("ftppath: %s\n",ftppath);
  9478. int ftppathlen=strlen(ftppath);
  9479. int i=1;
  9480. char filenametemp[50];
  9481. while(i < ftppathlen)
  9482. {
  9483. int len=ftppathlen-i;
  9484. if(ftppath[len]== 47) // '/' ascll code: 47
  9485. {
  9486. DEBUG_INFO("compare '/' all right\n");
  9487. break;
  9488. }
  9489. i=i+1;
  9490. }
  9491. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9492. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9493. filenametemp[i+1] = 0;
  9494. do
  9495. {
  9496. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9497. sleep(3);
  9498. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9499. if(!isSuccess)
  9500. {
  9501. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9502. sleep(retryIntervalInt);
  9503. }
  9504. else
  9505. {
  9506. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9507. }
  9508. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  9509. }
  9510. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  9511. {
  9512. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9513. memset(temp, 0, ARRAY_SIZE(temp));
  9514. //DEBUG_INFO("locationstr=%s\n",locationstr);
  9515. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  9516. int ftppathlen=strlen(ftpbuf);
  9517. int i=1;
  9518. char filenametemp[50];
  9519. while(i < ftppathlen)
  9520. {
  9521. int len=ftppathlen-i;
  9522. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9523. {
  9524. DEBUG_INFO(" compare '/' all right\n");
  9525. break;
  9526. }
  9527. i=i+1;
  9528. }
  9529. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9530. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9531. filenametemp[i+1] = 0;
  9532. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9533. pch=strchr(temp,'@');
  9534. if(pch==NULL)
  9535. {
  9536. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9537. protocol, host, &port, path);
  9538. strcpy(user,"anonymous");
  9539. strcpy(password,"");
  9540. }
  9541. else
  9542. {
  9543. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9544. protocol, user, password, host, &port, path);
  9545. }
  9546. sscanf(host,"%[^/]%s",host1, path1);
  9547. sprintf(ftppath,"%s", path1);
  9548. //DEBUG_INFO("protocol =%s\n",protocol);
  9549. //DEBUG_INFO("user =%s\n",user);
  9550. //DEBUG_INFO("password =%s\n",password);
  9551. //DEBUG_INFO("host1 =%s\n",host1);
  9552. //DEBUG_INFO("port =%d\n",port);
  9553. //DEBUG_INFO("path1 =%s\n",path1);
  9554. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9555. //ftpFile(host, user, password, port, ftppath, fname);
  9556. //download firmware pthred
  9557. if(port == 0)
  9558. {
  9559. port = 21;
  9560. }
  9561. do
  9562. {
  9563. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9564. sleep(3);
  9565. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9566. if(!isSuccess)
  9567. {
  9568. //BulldogUtil.sleepMs(interval*1000);
  9569. DEBUG_INFO("Update firmware request and download file fail.\n");
  9570. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9571. sleep(retryIntervalInt);
  9572. }
  9573. else
  9574. {
  9575. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9576. }
  9577. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9578. }
  9579. else
  9580. {
  9581. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9582. }
  9583. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9584. pthread_exit(NULL);
  9585. }
  9586. //==========================================
  9587. // Handle server response routine
  9588. //==========================================
  9589. void handleAuthorizeResponse(char *payload, int gun_index)
  9590. {
  9591. mtrace();
  9592. char expiryDatestr[30]={0};
  9593. char parentIdTagstr[20]={0};
  9594. char statusstr[20]={0};
  9595. int expiryDateISNULL=FALSE;
  9596. int parentIdTagISNULL=FALSE;
  9597. DEBUG_INFO("handleAuthorizeResponse...\n");
  9598. json_object *Authorize;
  9599. Authorize = json_tokener_parse(payload);
  9600. if(!is_error(Authorize))
  9601. {
  9602. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  9603. {
  9604. // Required data
  9605. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  9606. // Optional data
  9607. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  9608. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  9609. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  9610. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  9611. }
  9612. }
  9613. json_object_put(Authorize);
  9614. if(expiryDateISNULL == FALSE)
  9615. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9616. if(parentIdTagISNULL == FALSE)
  9617. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9618. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9619. //Update idTag information to authorization cache if supproted
  9620. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9621. {
  9622. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  9623. }
  9624. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9625. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9626. authorizeRetryTimes = 0;
  9627. }
  9628. void handleBootNotificationResponse(char *payload, int gun_index)
  9629. {
  9630. mtrace();
  9631. char statusStr[12]={0};
  9632. char currentTimeStr[30]={0};
  9633. int intervalInt = 0;
  9634. struct tm tp;
  9635. char buf[28]={0};
  9636. char timebuf[50]={0};
  9637. DEBUG_INFO("handleBootNotificationResponse...\n");
  9638. json_object *BootNotification;
  9639. BootNotification = json_tokener_parse(payload);
  9640. if(!is_error(BootNotification))
  9641. {
  9642. // Required data
  9643. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  9644. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  9645. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  9646. }
  9647. json_object_put(BootNotification);
  9648. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9649. BootNotificationInterval = intervalInt;
  9650. HeartBeatWaitTime = intervalInt;
  9651. //write back to ShmOCPP16Data->BootNotification
  9652. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  9653. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9654. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  9655. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  9656. {
  9657. server_sign = TRUE;
  9658. server_pending =FALSE;
  9659. }
  9660. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  9661. {
  9662. server_pending = TRUE;
  9663. }
  9664. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9665. tp.tm_isdst = -1;
  9666. //time_t utc = mktime(&tp);
  9667. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9668. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9669. sprintf(timebuf,"date -s '%s'",buf);
  9670. system(timebuf);
  9671. srand(time(NULL));
  9672. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  9673. //==============================================
  9674. // RTC sync
  9675. //==============================================
  9676. system("/sbin/hwclock -w --systohc");
  9677. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  9678. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  9679. }
  9680. void handleDataTransferResponse(char *payload, int gun_index)
  9681. {
  9682. char sstr[160]={0};//sstr[200]={ 0 };
  9683. int c = 0;
  9684. char *loc;
  9685. DEBUG_INFO("handleDataTransferResponse ...\n");
  9686. loc = strstr(payload, "status");
  9687. printf("loc=%s\n",loc);
  9688. c = 0;
  9689. while (loc[3+strlen("status")+c] != '\"')
  9690. {
  9691. sstr[c] = loc[3+strlen("status")+c];
  9692. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9693. c++;
  9694. }
  9695. sstr[c] = '\0';
  9696. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  9697. }
  9698. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  9699. {
  9700. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  9701. //struct json_object *obj;
  9702. // obj = json_tokener_parse(payload);
  9703. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  9704. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  9705. //No fields are defined.
  9706. }
  9707. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  9708. {
  9709. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  9710. //struct json_object *obj;
  9711. // obj = json_tokener_parse(payload);
  9712. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  9713. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  9714. //No fields are defined.
  9715. }
  9716. void handleHeartbeatResponse(char *payload, int gun_index)
  9717. {
  9718. mtrace();
  9719. struct tm tp;
  9720. char buf[28]={0};
  9721. char timebuf[50]={0};
  9722. DEBUG_INFO("handleHeartbeatResponse...\n");
  9723. json_object *Heartbeat;
  9724. Heartbeat = json_tokener_parse(payload);
  9725. if(!is_error(Heartbeat))
  9726. {
  9727. // Required data
  9728. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  9729. }
  9730. json_object_put(Heartbeat);
  9731. if(FirstHeartBeat == 0)
  9732. {
  9733. FirstHeartBeat = 1;
  9734. DEBUG_INFO("FirstHeartBeat \n");
  9735. }
  9736. HeartBeatWithNOResponse = 0;
  9737. clientTime.Heartbeat=time((time_t*)NULL);
  9738. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9739. tp.tm_isdst = -1;
  9740. //time_t utc = mktime(&tp);
  9741. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9742. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9743. sprintf(timebuf,"date -s '%s'",buf);
  9744. system(timebuf);
  9745. //==============================================
  9746. // RTC sync
  9747. //==============================================
  9748. system("/sbin/hwclock -w --systohc");
  9749. }
  9750. void handleMeterValuesResponse(char *payload, int gun_index)
  9751. {
  9752. mtrace();
  9753. DEBUG_INFO("handleMeterValuesResponse...\n");
  9754. }
  9755. void handleStartTransactionResponse(char *payload, int gun_index)
  9756. {
  9757. mtrace();
  9758. //int transactionIdInt = 0;
  9759. FILE *outfile;
  9760. char data[100]={0};
  9761. DEBUG_INFO("handleStartTransactionResponse...\n");
  9762. json_object *StartTransaction;
  9763. StartTransaction = json_tokener_parse(payload);
  9764. if(!is_error(StartTransaction))
  9765. {
  9766. // Required data
  9767. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  9768. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  9769. // Optional data
  9770. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  9771. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  9772. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  9773. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  9774. }
  9775. json_object_put(StartTransaction);
  9776. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  9777. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  9778. //-----------Start : write to the Queue TransactionId file -----------------//
  9779. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  9780. {}
  9781. else
  9782. {
  9783. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  9784. if(log == NULL)
  9785. {
  9786. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  9787. return ;
  9788. }
  9789. else
  9790. {
  9791. fclose(log);
  9792. }
  9793. }
  9794. // open file for writing
  9795. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  9796. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  9797. {
  9798. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  9799. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  9800. fputs(data, outfile);
  9801. fclose (outfile);
  9802. }
  9803. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9804. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9805. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  9806. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  9807. }
  9808. void handleStatusNotificationResponse(char *payload, int gun_index)
  9809. {
  9810. mtrace();
  9811. DEBUG_INFO("handleStatusNotificationResponse...\n");
  9812. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  9813. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  9814. }
  9815. void handleStopTransactionnResponse(char *payload, int gun_index)
  9816. {
  9817. mtrace();
  9818. DEBUG_INFO("handleStopTransactionnResponse...\n");
  9819. json_object *StopTransaction;
  9820. StopTransaction = json_tokener_parse(payload);
  9821. if(!is_error(StopTransaction))
  9822. {
  9823. // Optional data
  9824. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  9825. {
  9826. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  9827. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  9828. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  9829. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  9830. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  9831. }
  9832. }
  9833. json_object_put(StopTransaction);
  9834. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  9835. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  9836. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9837. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9838. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  9839. }
  9840. //==========================================
  9841. // Handle Error routine
  9842. //==========================================
  9843. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  9844. {
  9845. mtrace();
  9846. #ifdef SystemLogMessage
  9847. DEBUG_INFO("errorCode: %s\n", errorCode);
  9848. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  9849. DEBUG_INFO("errorDetails: %s\n", payload);
  9850. #endif
  9851. }
  9852. //===============================================
  9853. // Common routine
  9854. //===============================================
  9855. int initialConfigurationTable(void)
  9856. {
  9857. //clock_t start_t, end_t, total_t;
  9858. FILE *fp;
  9859. FILE *outfile;
  9860. char str[200]={0};
  9861. char sstr[100]={0};
  9862. int c = 0;
  9863. char *loc;
  9864. DEBUG_INFO("initialConfigurationTable...\n");
  9865. //start_t = clock();
  9866. //printf("Starting of the program, start_t = %ld\n", start_t);
  9867. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  9868. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  9869. {
  9870. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  9871. if(outfile == NULL)
  9872. {
  9873. DEBUG_INFO("Error opening file\n");
  9874. return FALSE;
  9875. }
  9876. /*Core Profile*/
  9877. //AllowOfflineTxForUnknownId
  9878. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  9879. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  9880. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  9881. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  9882. //AuthorizationCacheEnabled
  9883. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  9884. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  9885. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  9886. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  9887. //AuthorizeRemoteTxRequests
  9888. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  9889. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  9890. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  9891. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  9892. //BlinkRepeat
  9893. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  9894. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  9895. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  9896. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  9897. //ClockAlignedDataInterval
  9898. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  9899. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  9900. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  9901. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  9902. //ConnectionTimeOut
  9903. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  9904. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  9905. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  9906. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  9907. //GetConfigurationMaxKeys
  9908. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  9909. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  9910. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "44" );
  9911. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  9912. // HeartbeatInterval
  9913. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  9914. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  9915. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  9916. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  9917. // LightIntensity
  9918. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  9919. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  9920. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  9921. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  9922. // LocalAuthorizeOffline
  9923. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  9924. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  9925. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  9926. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  9927. // LocalPreAuthorize
  9928. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  9929. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  9930. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  9931. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  9932. // MaxEnergyOnInvalidId
  9933. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  9934. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  9935. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  9936. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  9937. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  9938. // MeterValuesAlignedData
  9939. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 0;
  9940. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  9941. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9942. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  9943. else
  9944. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  9945. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  9946. // MeterValuesAlignedDataMaxLength
  9947. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  9948. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  9949. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9950. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  9951. else
  9952. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  9953. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  9954. // MeterValuesSampledData
  9955. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 0;
  9956. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  9957. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9958. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  9959. else
  9960. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  9961. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  9962. // MeterValuesSampledDataMaxLength
  9963. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  9964. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  9965. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9966. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  9967. else
  9968. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  9969. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  9970. // MeterValueSampleInterval
  9971. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  9972. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  9973. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  9974. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  9975. // MinimumStatusDuration
  9976. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  9977. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  9978. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  9979. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  9980. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  9981. // NumberOfConnectors
  9982. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  9983. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  9984. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9985. {
  9986. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  9987. }
  9988. else
  9989. {
  9990. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  9991. }
  9992. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  9993. // ResetRetries
  9994. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  9995. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  9996. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  9997. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  9998. // ConnectorPhaseRotation
  9999. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10000. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10001. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10002. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10003. // ConnectorPhaseRotationMaxLength
  10004. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10005. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10006. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10007. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10008. // StopTransactionOnEVSideDisconnect
  10009. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10010. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10011. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10012. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10013. // StopTransactionOnInvalidId
  10014. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  10015. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10016. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10017. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10018. // StopTxnAlignedData
  10019. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  10020. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10021. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10022. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10023. // StopTxnAlignedDataMaxLength
  10024. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10025. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10026. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10027. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10028. // StopTxnSampledData
  10029. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 0;
  10030. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10031. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10032. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10033. else
  10034. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10035. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10036. // StopTxnSampledDataMaxLength
  10037. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10038. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10039. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10040. {
  10041. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  10042. }
  10043. else
  10044. {
  10045. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  10046. }
  10047. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10048. // SupportedFeatureProfiles
  10049. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10050. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10051. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10052. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10053. // SupportedFeatureProfilesMaxLength
  10054. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10055. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10056. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10057. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10058. // TransactionMessageAttempts
  10059. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10060. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10061. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10062. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10063. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10064. // TransactionMessageRetryInterval
  10065. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10066. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10067. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10068. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10069. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10070. // UnlockConnectorOnEVSideDisconnect
  10071. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10072. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10073. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10074. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10075. // WebSocketPingInterval
  10076. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10077. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10078. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10079. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10080. // QueueOffLineStartTransactionMessage
  10081. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  10082. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10084. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10085. // AuthorizationKey
  10086. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  10087. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  10088. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "" );
  10089. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  10090. // SecurityProfile
  10091. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  10092. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  10093. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "0" );
  10094. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  10095. // DefaultPrice
  10096. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  10097. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  10098. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  10099. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  10100. // CustomDisplayCostAndPrice
  10101. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  10102. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  10103. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  10104. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  10105. // CustomIdleFeeAfterStop
  10106. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  10107. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  10108. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  10109. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  10110. //* Local Auth List Management Profile*/
  10111. #if 0
  10112. //For OCTT Test Case
  10113. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10114. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  10115. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10116. #endif
  10117. #if 1
  10118. //LocalAuthListEnabled
  10119. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10120. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10121. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10122. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10123. #endif
  10124. //LocalAuthListMaxLength
  10125. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10126. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10127. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10128. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10129. //SendLocalListMaxLength
  10130. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10131. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10132. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  10133. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10134. //ReserveConnectorZeroSupported
  10135. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10136. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10137. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10138. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10139. //* Smart Charging Profile */
  10140. //ChargeProfileMaxStackLevel
  10141. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10142. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10143. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10144. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10145. // ChargingScheduleAllowedChargingRateUnit
  10146. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10148. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10149. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10150. // ChargingScheduleMaxPeriods
  10151. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10152. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10153. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10154. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10155. // ConnectorSwitch3to1PhaseSupported
  10156. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10157. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10158. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10159. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10160. // MaxChargingProfilesInstalled
  10161. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10162. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10163. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  10164. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10165. fclose(outfile);
  10166. }
  10167. else
  10168. {
  10169. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10170. char keystr[60]={0};
  10171. char readonlystr[10]={0};
  10172. char valuestr[100]={0};
  10173. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10174. if(fp == NULL) {
  10175. DEBUG_INFO("Error opening file");
  10176. return FALSE;
  10177. }
  10178. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  10179. {
  10180. //DEBUG_INFO("Get Configuration \n");
  10181. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10182. //*************************key*********************************/
  10183. loc = strstr(str, "key");
  10184. c = 0;
  10185. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10186. while (loc[strlen("key")+3+c] != '\"')
  10187. {
  10188. sstr[c] = loc[strlen("key")+3+c];
  10189. c++;
  10190. }
  10191. sstr[c] = '\0';
  10192. strcpy(keystr,sstr);
  10193. //*************************readonly*********************************/
  10194. loc = strstr(str, "readonly");
  10195. c = 0;
  10196. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10197. while (loc[strlen("readonly")+2+c] != ',')
  10198. {
  10199. sstr[c] = loc[strlen("readonly")+2+c];
  10200. c++;
  10201. }
  10202. sstr[c] = '\0';
  10203. strcpy(readonlystr,sstr);
  10204. //*************************value*********************************/
  10205. loc = strstr(str, "value");
  10206. c = 0;
  10207. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10208. while (loc[strlen("value")+3+c] != '\"')
  10209. {
  10210. sstr[c] = loc[strlen("value")+3+c];
  10211. c++;
  10212. }
  10213. sstr[c] = '\0';
  10214. strcpy(valuestr,sstr);
  10215. // DEBUG_INFO("keystr=%s\n",keystr);
  10216. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10217. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10218. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10219. {
  10220. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10221. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10222. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10223. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10224. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10225. }
  10226. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10227. {
  10228. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10229. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10230. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10231. }
  10232. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10233. {
  10234. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10235. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10236. }
  10237. if(strcmp(keystr, "BlinkRepeat") == 0)
  10238. {
  10239. //Charger.BlinkRepeat = Integer.parseInt(value);
  10240. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10241. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10242. }
  10243. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10244. {
  10245. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10246. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10247. }
  10248. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10249. {
  10250. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10251. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10252. }
  10253. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10254. {
  10255. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10256. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  10257. }
  10258. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10259. {
  10260. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10261. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10262. HeartBeatWaitTime = atoi(valuestr);
  10263. }
  10264. if(strcmp(keystr, "LightIntensity") == 0)
  10265. {
  10266. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10267. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10268. }
  10269. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10270. {
  10271. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10272. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10273. }
  10274. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10275. {
  10276. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10277. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10278. }
  10279. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10280. {
  10281. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10282. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10283. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10284. }
  10285. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10286. {
  10287. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10288. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10289. }
  10290. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10291. {
  10292. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10293. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10294. }
  10295. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10296. {
  10297. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10298. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10299. }
  10300. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10301. {
  10302. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10303. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10304. }
  10305. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10306. {
  10307. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10308. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10309. }
  10310. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10311. {
  10312. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10313. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10314. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10315. }
  10316. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10317. {
  10318. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10319. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10320. }
  10321. if(strcmp(keystr, "ResetRetries") == 0)
  10322. {
  10323. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10324. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10325. }
  10326. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10327. {
  10328. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10329. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10330. }
  10331. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10332. {
  10333. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10334. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10335. }
  10336. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10337. {
  10338. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10339. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10340. }
  10341. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10342. {
  10343. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10344. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10345. }
  10346. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10347. {
  10348. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10349. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10350. }
  10351. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10352. {
  10353. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10354. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10355. }
  10356. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10357. {
  10358. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10359. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10360. }
  10361. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10362. {
  10363. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10364. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10365. }
  10366. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10367. {
  10368. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10369. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10370. }
  10371. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10372. {
  10373. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10374. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10375. }
  10376. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10377. {
  10378. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10379. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10380. TransactionMessageAttemptsValue = atoi(valuestr);
  10381. }
  10382. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10383. {
  10384. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10385. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10386. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10387. }
  10388. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10389. {
  10390. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10391. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10392. }
  10393. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10394. {
  10395. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10396. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10397. }
  10398. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  10399. {
  10400. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10401. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  10402. }
  10403. if(strcmp(keystr, "AuthorizationKey") == 0)
  10404. {
  10405. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10406. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  10407. }
  10408. if(strcmp(keystr, "SecurityProfile") == 0)
  10409. {
  10410. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10411. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  10412. }
  10413. if(strcmp(keystr, "DefaultPrice") == 0)
  10414. {
  10415. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10416. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  10417. }
  10418. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  10419. {
  10420. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10421. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  10422. }
  10423. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  10424. {
  10425. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10426. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  10427. }
  10428. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10429. {
  10430. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10431. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10432. }
  10433. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10434. {
  10435. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10436. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10437. }
  10438. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10439. {
  10440. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10441. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10442. }
  10443. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10444. {
  10445. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10446. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10447. }
  10448. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10449. {
  10450. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10451. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10452. }
  10453. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10454. {
  10455. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10456. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10457. }
  10458. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10459. {
  10460. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10461. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10462. }
  10463. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10464. {
  10465. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10466. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10467. }
  10468. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10469. {
  10470. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10471. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10472. }
  10473. }
  10474. fclose(fp);
  10475. }
  10476. return 0;
  10477. }
  10478. void StoreConfigurationTable(void)
  10479. {
  10480. FILE *outfile;
  10481. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10482. if(outfile == NULL)
  10483. {
  10484. DEBUG_INFO("Error opening file");
  10485. return ;
  10486. }
  10487. /*Core Profile*/
  10488. //AllowOfflineTxForUnknownId
  10489. /*
  10490. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10491. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10492. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10493. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10494. */
  10495. //DEBUG_INFO("data=%s\n",data);
  10496. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10497. //AuthorizationCacheEnabled
  10498. /*
  10499. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10500. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10501. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10502. */
  10503. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10504. //AuthorizeRemoteTxRequests
  10505. /*
  10506. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10507. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10508. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10509. */
  10510. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10511. //BlinkRepeat
  10512. /*
  10513. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10514. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10515. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10516. */
  10517. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10518. //ClockAlignedDataInterval
  10519. /*
  10520. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10521. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10522. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10523. */
  10524. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10525. //ConnectionTimeOut
  10526. /*
  10527. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10528. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10529. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10530. */
  10531. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10532. //GetConfigurationMaxKeys
  10533. /*
  10534. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10535. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10536. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10537. */
  10538. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10539. // HeartbeatInterval
  10540. /*
  10541. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10542. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10543. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10544. */
  10545. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10546. // LightIntensity
  10547. /*
  10548. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10549. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10550. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10551. */
  10552. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10553. // LocalAuthorizeOffline
  10554. /*
  10555. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10556. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10557. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10558. */
  10559. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10560. // LocalPreAuthorize
  10561. /*
  10562. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10563. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10564. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10565. */
  10566. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10567. // MaxEnergyOnInvalidId
  10568. /*
  10569. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10570. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10571. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10572. */
  10573. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10574. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10575. // MeterValuesAlignedData
  10576. /*
  10577. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10578. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10579. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10580. */
  10581. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10582. // MeterValuesAlignedDataMaxLength
  10583. /*
  10584. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10585. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10586. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10587. */
  10588. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10589. // MeterValuesSampledData
  10590. /*
  10591. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10592. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10593. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10594. */
  10595. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10596. // MeterValuesSampledDataMaxLength
  10597. /*
  10598. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10599. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10600. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10601. */
  10602. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10603. // MeterValueSampleInterval
  10604. /*
  10605. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10606. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10607. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10608. */
  10609. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10610. // MinimumStatusDuration
  10611. /*
  10612. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10613. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10614. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10615. */
  10616. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10617. // NumberOfConnectors
  10618. /*
  10619. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10620. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10621. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10622. {
  10623. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10624. }
  10625. else
  10626. {
  10627. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10628. }
  10629. */
  10630. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10631. // ResetRetries
  10632. /*
  10633. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10634. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10635. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10636. */
  10637. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10638. // ConnectorPhaseRotation
  10639. /*
  10640. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10641. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10642. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10643. */
  10644. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10645. // ConnectorPhaseRotationMaxLength
  10646. /*
  10647. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10648. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10649. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10650. */
  10651. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10652. // StopTransactionOnEVSideDisconnect
  10653. /*
  10654. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10655. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10656. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10657. */
  10658. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10659. // StopTransactionOnInvalidId
  10660. /*
  10661. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  10662. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10663. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10664. */
  10665. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10666. // StopTxnAlignedData
  10667. /*
  10668. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  10669. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10670. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10671. */
  10672. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10673. // StopTxnAlignedDataMaxLength
  10674. /*
  10675. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10676. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10677. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10678. */
  10679. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10680. // StopTxnSampledData
  10681. /*
  10682. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10683. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10684. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  10685. */
  10686. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10687. // StopTxnSampledDataMaxLength
  10688. /*
  10689. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10690. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10691. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10692. */
  10693. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10694. // SupportedFeatureProfiles
  10695. /*
  10696. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10697. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10698. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10699. */
  10700. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10701. // SupportedFeatureProfilesMaxLength
  10702. /*
  10703. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10704. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10705. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10706. */
  10707. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10708. // TransactionMessageAttempts
  10709. /*
  10710. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10711. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10712. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10713. */
  10714. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10715. // TransactionMessageRetryInterval
  10716. /*
  10717. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10718. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10719. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10720. */
  10721. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10722. // UnlockConnectorOnEVSideDisconnect
  10723. /*
  10724. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10725. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10726. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10727. */
  10728. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10729. // WebSocketPingInterval
  10730. /*
  10731. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10732. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10733. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10734. */
  10735. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10736. // QueueOffLineStartTransactionMessage
  10737. /*
  10738. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  10739. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10740. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10741. */
  10742. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10743. // AuthorizationKey
  10744. /*
  10745. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  10746. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  10747. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  10748. */
  10749. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  10750. // SecurityProfile
  10751. /*
  10752. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  10753. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  10754. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  10755. */
  10756. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  10757. // DefaultPrice
  10758. /*
  10759. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  10760. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  10761. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  10762. */
  10763. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  10764. // CustomDisplayCostAndPrice
  10765. /*
  10766. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  10767. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  10768. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  10769. */
  10770. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  10771. // CustomIdleFeeAfterStop
  10772. /*
  10773. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  10774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  10775. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  10776. */
  10777. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  10778. //* Local Auth List Management Profile*/
  10779. //LocalAuthListEnabled
  10780. /*
  10781. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10782. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10783. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10784. */
  10785. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10786. //LocalAuthListMaxLength
  10787. /*
  10788. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10789. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10790. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10791. */
  10792. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10793. //SendLocalListMaxLength
  10794. /*
  10795. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10796. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10797. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10798. */
  10799. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10800. //ReserveConnectorZeroSupported
  10801. /*
  10802. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10803. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10804. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10805. */
  10806. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10807. //* Smart Charging Profile */
  10808. //ChargeProfileMaxStackLevel
  10809. /*
  10810. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10811. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10812. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10813. */
  10814. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10815. // ChargingScheduleAllowedChargingRateUnit
  10816. /*
  10817. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10818. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10819. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10820. */
  10821. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10822. // ChargingScheduleMaxPeriods
  10823. /*
  10824. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10825. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10826. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10827. */
  10828. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10829. // ConnectorSwitch3to1PhaseSupported
  10830. /*
  10831. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10832. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10833. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10834. */
  10835. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10836. // MaxChargingProfilesInstalled
  10837. /*
  10838. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10839. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10840. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  10841. */
  10842. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10843. fclose(outfile);
  10844. }
  10845. void getKeyValue(char *keyReq)
  10846. {
  10847. int isEmpty = FALSE;
  10848. int isKnowKey = FALSE;
  10849. DEBUG_INFO("keyReq = %s\n", keyReq);
  10850. if((keyReq == NULL) || (strlen(keyReq) == 0))
  10851. isEmpty = TRUE;
  10852. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  10853. {
  10854. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  10855. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  10856. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  10857. {
  10858. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  10859. }
  10860. else
  10861. {
  10862. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  10863. }
  10864. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  10865. isKnowKey = TRUE;
  10866. }
  10867. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  10868. {
  10869. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  10870. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  10871. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  10872. {
  10873. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  10874. }
  10875. else
  10876. {
  10877. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  10878. }
  10879. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  10880. isKnowKey = TRUE;
  10881. }
  10882. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  10883. {
  10884. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  10885. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  10886. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  10887. {
  10888. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  10889. }
  10890. else
  10891. {
  10892. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  10893. }
  10894. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  10895. isKnowKey = TRUE;
  10896. }
  10897. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  10898. {
  10899. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  10900. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  10901. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  10902. {
  10903. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  10904. }
  10905. else
  10906. {
  10907. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  10908. }
  10909. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  10910. isKnowKey = TRUE;
  10911. }
  10912. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  10913. {
  10914. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  10915. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  10916. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  10917. {
  10918. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  10919. }
  10920. else
  10921. {
  10922. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  10923. }
  10924. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  10925. isKnowKey = TRUE;
  10926. }
  10927. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  10928. {
  10929. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  10930. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  10931. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  10932. {
  10933. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  10934. }
  10935. else
  10936. {
  10937. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  10938. }
  10939. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  10940. isKnowKey = TRUE;
  10941. }
  10942. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  10943. {
  10944. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  10945. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  10946. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  10947. {
  10948. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  10949. }
  10950. else
  10951. {
  10952. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  10953. }
  10954. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  10955. isKnowKey = TRUE;
  10956. }
  10957. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  10958. {
  10959. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  10960. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  10961. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  10962. {
  10963. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  10964. }
  10965. else
  10966. {
  10967. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  10968. }
  10969. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  10970. isKnowKey = TRUE;
  10971. }
  10972. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  10973. {
  10974. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  10975. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  10976. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  10977. {
  10978. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  10979. }
  10980. else
  10981. {
  10982. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  10983. }
  10984. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  10985. isKnowKey = TRUE;
  10986. }
  10987. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  10988. {
  10989. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  10990. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  10991. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  10992. {
  10993. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  10994. }
  10995. else
  10996. {
  10997. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  10998. }
  10999. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  11000. isKnowKey = TRUE;
  11001. }
  11002. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  11003. {
  11004. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  11005. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  11006. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11007. {
  11008. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  11009. }
  11010. else
  11011. {
  11012. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  11013. }
  11014. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  11015. isKnowKey = TRUE;
  11016. }
  11017. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  11018. {
  11019. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  11020. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  11021. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11022. {
  11023. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11024. }
  11025. else
  11026. {
  11027. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11028. }
  11029. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  11030. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  11031. isKnowKey = TRUE;
  11032. }
  11033. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  11034. {
  11035. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  11036. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  11037. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11038. {
  11039. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11040. }
  11041. else
  11042. {
  11043. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11044. }
  11045. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  11046. isKnowKey = TRUE;
  11047. }
  11048. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  11049. {
  11050. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  11051. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  11052. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11053. {
  11054. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11055. }
  11056. else
  11057. {
  11058. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11059. }
  11060. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  11061. isKnowKey = TRUE;
  11062. }
  11063. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  11064. {
  11065. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  11066. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  11067. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11068. {
  11069. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  11070. }
  11071. else
  11072. {
  11073. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  11074. }
  11075. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  11076. isKnowKey = TRUE;
  11077. }
  11078. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  11079. {
  11080. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  11081. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  11082. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11083. {
  11084. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11085. }
  11086. else
  11087. {
  11088. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11089. }
  11090. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  11091. isKnowKey = TRUE;
  11092. }
  11093. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  11094. {
  11095. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  11096. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  11097. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11098. {
  11099. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  11100. }
  11101. else
  11102. {
  11103. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  11104. }
  11105. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  11106. isKnowKey = TRUE;
  11107. }
  11108. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  11109. {
  11110. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  11111. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  11112. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11113. {
  11114. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  11115. }
  11116. else
  11117. {
  11118. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  11119. }
  11120. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  11121. isKnowKey = TRUE;
  11122. }
  11123. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  11124. {
  11125. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  11126. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  11127. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11128. {
  11129. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  11130. }
  11131. else
  11132. {
  11133. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  11134. }
  11135. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  11136. isKnowKey = TRUE;
  11137. }
  11138. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  11139. {
  11140. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  11141. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11142. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11143. {
  11144. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11145. }
  11146. else
  11147. {
  11148. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11149. }
  11150. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11151. isKnowKey = TRUE;
  11152. }
  11153. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11154. {
  11155. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11156. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11157. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11158. {
  11159. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11160. }
  11161. else
  11162. {
  11163. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11164. }
  11165. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11166. isKnowKey = TRUE;
  11167. }
  11168. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11169. {
  11170. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11171. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11172. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11173. {
  11174. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11175. }
  11176. else
  11177. {
  11178. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11179. }
  11180. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11181. isKnowKey = TRUE;
  11182. }
  11183. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11184. {
  11185. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11186. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11187. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11188. {
  11189. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11190. }
  11191. else
  11192. {
  11193. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11194. }
  11195. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11196. isKnowKey = TRUE;
  11197. }
  11198. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11199. {
  11200. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11201. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11202. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11203. {
  11204. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11205. }
  11206. else
  11207. {
  11208. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11209. }
  11210. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11211. isKnowKey = TRUE;
  11212. }
  11213. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11214. {
  11215. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11216. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11217. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11218. {
  11219. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11220. }
  11221. else
  11222. {
  11223. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11224. }
  11225. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11226. isKnowKey = TRUE;
  11227. }
  11228. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11229. {
  11230. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11231. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11232. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11233. {
  11234. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11235. }
  11236. else
  11237. {
  11238. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11239. }
  11240. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11241. isKnowKey = TRUE;
  11242. }
  11243. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11244. {
  11245. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11246. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11247. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11248. {
  11249. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11250. }
  11251. else
  11252. {
  11253. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11254. }
  11255. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11256. isKnowKey = TRUE;
  11257. }
  11258. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11259. {
  11260. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11261. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11262. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11263. {
  11264. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11265. }
  11266. else
  11267. {
  11268. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11269. }
  11270. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11271. isKnowKey = TRUE;
  11272. }
  11273. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11274. {
  11275. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11276. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11277. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11278. {
  11279. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11280. }
  11281. else
  11282. {
  11283. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11284. }
  11285. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11286. isKnowKey = TRUE;
  11287. }
  11288. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11289. {
  11290. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11291. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11292. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11293. {
  11294. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11295. }
  11296. else
  11297. {
  11298. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11299. }
  11300. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11301. isKnowKey = TRUE;
  11302. }
  11303. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11304. {
  11305. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11306. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11307. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11308. {
  11309. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11310. }
  11311. else
  11312. {
  11313. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11314. }
  11315. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11316. isKnowKey = TRUE;
  11317. }
  11318. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11319. {
  11320. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11321. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11322. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11323. {
  11324. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11325. }
  11326. else
  11327. {
  11328. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11329. }
  11330. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11331. isKnowKey = TRUE;
  11332. }
  11333. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11334. {
  11335. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11336. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11337. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11338. {
  11339. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11340. }
  11341. else
  11342. {
  11343. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11344. }
  11345. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11346. isKnowKey = TRUE;
  11347. }
  11348. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11349. {
  11350. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11351. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11352. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11353. {
  11354. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11355. }
  11356. else
  11357. {
  11358. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11359. }
  11360. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11361. isKnowKey = TRUE;
  11362. }
  11363. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  11364. {
  11365. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  11366. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  11367. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  11368. {
  11369. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  11370. }
  11371. else
  11372. {
  11373. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  11374. }
  11375. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  11376. isKnowKey = TRUE;
  11377. }
  11378. /*
  11379. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  11380. {
  11381. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  11382. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  11383. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  11384. {
  11385. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  11386. }
  11387. else
  11388. {
  11389. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  11390. }
  11391. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  11392. isKnowKey = TRUE;
  11393. }*/
  11394. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  11395. {
  11396. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  11397. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  11398. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  11399. {
  11400. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  11401. }
  11402. else
  11403. {
  11404. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  11405. }
  11406. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  11407. isKnowKey = TRUE;
  11408. }
  11409. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  11410. {
  11411. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  11412. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  11413. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  11414. {
  11415. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  11416. }
  11417. else
  11418. {
  11419. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  11420. }
  11421. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  11422. isKnowKey = TRUE;
  11423. }
  11424. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  11425. {
  11426. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  11427. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  11428. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  11429. {
  11430. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  11431. }
  11432. else
  11433. {
  11434. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  11435. }
  11436. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  11437. isKnowKey = TRUE;
  11438. }
  11439. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  11440. {
  11441. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  11442. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  11443. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  11444. {
  11445. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  11446. }
  11447. else
  11448. {
  11449. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  11450. }
  11451. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  11452. isKnowKey = TRUE;
  11453. }
  11454. #if 1
  11455. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11456. {
  11457. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11458. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11459. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11460. {
  11461. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11462. }
  11463. else
  11464. {
  11465. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11466. }
  11467. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11468. isKnowKey = TRUE;
  11469. }
  11470. #endif
  11471. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11472. {
  11473. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11474. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11475. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11476. {
  11477. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11478. }
  11479. else
  11480. {
  11481. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11482. }
  11483. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11484. isKnowKey = TRUE;
  11485. }
  11486. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11487. {
  11488. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11489. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11490. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11491. {
  11492. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11493. }
  11494. else
  11495. {
  11496. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11497. }
  11498. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11499. isKnowKey = TRUE;
  11500. }
  11501. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11502. {
  11503. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11504. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11505. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11506. {
  11507. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11508. }
  11509. else
  11510. {
  11511. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11512. }
  11513. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11514. isKnowKey = TRUE;
  11515. }
  11516. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11517. {
  11518. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11519. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11520. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11521. {
  11522. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11523. }
  11524. else
  11525. {
  11526. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11527. }
  11528. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11529. isKnowKey = TRUE;
  11530. }
  11531. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11532. {
  11533. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11534. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11535. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11536. {
  11537. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11538. }
  11539. else
  11540. {
  11541. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11542. }
  11543. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11544. isKnowKey = TRUE;
  11545. }
  11546. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11547. {
  11548. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11549. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11550. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11551. {
  11552. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11553. }
  11554. else
  11555. {
  11556. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11557. }
  11558. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11559. isKnowKey = TRUE;
  11560. }
  11561. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11562. {
  11563. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11565. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11566. {
  11567. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11568. }
  11569. else
  11570. {
  11571. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11572. }
  11573. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11574. isKnowKey = TRUE;
  11575. }
  11576. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11577. {
  11578. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11579. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11580. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11581. {
  11582. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11583. }
  11584. else
  11585. {
  11586. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11587. }
  11588. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11589. isKnowKey = TRUE;
  11590. }
  11591. //=========================================================
  11592. if(!isEmpty && !isKnowKey)
  11593. {
  11594. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11595. strcpy(unknownkey[UnknownKeynum], keyReq);
  11596. UnknownKeynum = UnknownKeynum + 1;
  11597. }
  11598. }
  11599. void processUnkownKey(void)
  11600. {
  11601. DEBUG_INFO("processUnkownKey...\n");
  11602. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11603. for(int index=0; index < UnknownKeynum; index++)
  11604. {
  11605. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11606. {
  11607. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11608. }
  11609. }
  11610. }
  11611. int setKeyValue(char *key, char *value)
  11612. {
  11613. int isSuccess = NotSupported;
  11614. int check_ascii=0;
  11615. char str[10]={0};
  11616. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  11617. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11618. {
  11619. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11620. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11621. {
  11622. strcpy(str, (const char*)value);
  11623. for(int i = 0; str[i]; i++){
  11624. str[i] = tolower(str[i]);
  11625. }
  11626. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11627. isSuccess = ConfigurationStatus_Accepted;
  11628. }
  11629. else
  11630. {
  11631. isSuccess = ConfigurationStatus_Rejected;
  11632. }
  11633. }
  11634. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11635. {
  11636. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11637. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11638. {
  11639. strcpy(str, (const char*)value);
  11640. for(int i = 0; str[i]; i++){
  11641. str[i] = tolower(str[i]);
  11642. }
  11643. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11644. isSuccess = ConfigurationStatus_Accepted;
  11645. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11646. }
  11647. else
  11648. {
  11649. isSuccess = ConfigurationStatus_Rejected;
  11650. }
  11651. }
  11652. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11653. {
  11654. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11655. {
  11656. strcpy(str, (const char*)value);
  11657. for(int i = 0; str[i]; i++)
  11658. {
  11659. str[i] = tolower(str[i]);
  11660. }
  11661. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  11662. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11663. isSuccess = ConfigurationStatus_Accepted;
  11664. }
  11665. else
  11666. {
  11667. isSuccess = ConfigurationStatus_Rejected;
  11668. }
  11669. }
  11670. if(strcmp(key, "BlinkRepeat") == 0)
  11671. {
  11672. //Charger.BlinkRepeat = Integer.parseInt(value);
  11673. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11674. {
  11675. check_ascii = value[0];
  11676. if( (check_ascii < 48) || (check_ascii > 57) )
  11677. {
  11678. isSuccess = ConfigurationStatus_Rejected;
  11679. }
  11680. else
  11681. {
  11682. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  11683. isSuccess = ConfigurationStatus_Accepted;
  11684. }
  11685. }
  11686. else
  11687. {
  11688. isSuccess = ConfigurationStatus_Rejected;
  11689. }
  11690. }
  11691. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  11692. {
  11693. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11694. {
  11695. check_ascii = value[0];
  11696. if( (check_ascii < 48) || (check_ascii > 57) )
  11697. {
  11698. isSuccess = ConfigurationStatus_Rejected;
  11699. }
  11700. else
  11701. {
  11702. if((atoi(value) == 0) || (atoi(value) >= 10))
  11703. {
  11704. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  11705. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  11706. isSuccess = ConfigurationStatus_Accepted;
  11707. }
  11708. else
  11709. isSuccess = ConfigurationStatus_Rejected;
  11710. }
  11711. }
  11712. else
  11713. {
  11714. isSuccess = ConfigurationStatus_Rejected;
  11715. }
  11716. }
  11717. if(strcmp(key, "ConnectionTimeOut") == 0 )
  11718. {
  11719. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11720. {
  11721. check_ascii = value[0];
  11722. if( (check_ascii < 48) || (check_ascii > 57) )
  11723. {
  11724. isSuccess = ConfigurationStatus_Rejected;
  11725. }
  11726. else
  11727. {
  11728. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  11729. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  11730. isSuccess = ConfigurationStatus_Accepted;
  11731. }
  11732. }
  11733. else
  11734. {
  11735. isSuccess = ConfigurationStatus_Rejected;
  11736. }
  11737. }
  11738. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  11739. {
  11740. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11741. {
  11742. check_ascii = value[0];
  11743. if( (check_ascii < 48) || (check_ascii > 57) )
  11744. {
  11745. isSuccess = ConfigurationStatus_Rejected;
  11746. }
  11747. else
  11748. {
  11749. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11750. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  11751. isSuccess = ConfigurationStatus_Accepted;
  11752. }
  11753. }
  11754. else
  11755. {
  11756. isSuccess = ConfigurationStatus_Rejected;
  11757. }
  11758. }
  11759. if(strcmp(key, "HeartbeatInterval") == 0)
  11760. {
  11761. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].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. if((atoi(value) == 0) || (atoi(value) >= 10))
  11771. {
  11772. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11773. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  11774. HeartBeatWaitTime = atoi(value);
  11775. isSuccess = ConfigurationStatus_Accepted;
  11776. }
  11777. else
  11778. {
  11779. isSuccess = ConfigurationStatus_Rejected;
  11780. }
  11781. }
  11782. }
  11783. else
  11784. {
  11785. isSuccess = ConfigurationStatus_Rejected;
  11786. }
  11787. }
  11788. if(strcmp(key, "LightIntensity") == 0)
  11789. {
  11790. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11791. {
  11792. check_ascii = value[0];
  11793. if( (check_ascii < 48) || (check_ascii > 57) )
  11794. {
  11795. isSuccess = ConfigurationStatus_Rejected;
  11796. }
  11797. else
  11798. {
  11799. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  11800. isSuccess = ConfigurationStatus_Accepted;
  11801. }
  11802. }
  11803. else
  11804. {
  11805. isSuccess = ConfigurationStatus_Rejected;
  11806. }
  11807. }
  11808. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  11809. {
  11810. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11811. {
  11812. strcpy(str, (const char*)value);
  11813. for(int i = 0; str[i]; i++)
  11814. {
  11815. str[i] = tolower(str[i]);
  11816. }
  11817. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11818. isSuccess = ConfigurationStatus_Accepted;
  11819. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11820. }
  11821. else
  11822. {
  11823. isSuccess = ConfigurationStatus_Rejected;
  11824. }
  11825. }
  11826. if(strcmp(key, "LocalPreAuthorize") == 0)
  11827. {
  11828. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11829. {
  11830. strcpy(str, (const char*)value);
  11831. for(int i = 0; str[i]; i++)
  11832. {
  11833. str[i] = tolower(str[i]);
  11834. }
  11835. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11836. isSuccess = ConfigurationStatus_Accepted;
  11837. }
  11838. else
  11839. {
  11840. isSuccess = ConfigurationStatus_Rejected;
  11841. }
  11842. }
  11843. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  11844. {
  11845. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11846. {
  11847. check_ascii = value[0];
  11848. if( (check_ascii < 48) || (check_ascii > 57) )
  11849. {
  11850. isSuccess = ConfigurationStatus_Rejected;
  11851. }
  11852. else
  11853. {
  11854. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  11855. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  11856. isSuccess = ConfigurationStatus_Accepted;
  11857. }
  11858. }
  11859. else
  11860. {
  11861. isSuccess = ConfigurationStatus_Rejected;
  11862. }
  11863. }
  11864. if(strcmp(key, "MeterValuesAlignedData") == 0)
  11865. {
  11866. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11867. {
  11868. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  11869. isSuccess = ConfigurationStatus_Accepted;
  11870. }
  11871. else
  11872. {
  11873. isSuccess = ConfigurationStatus_Rejected;
  11874. }
  11875. }
  11876. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  11877. {
  11878. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11879. {
  11880. check_ascii = value[0];
  11881. if( (check_ascii < 48) || (check_ascii > 57) )
  11882. {
  11883. isSuccess = ConfigurationStatus_Rejected;
  11884. }
  11885. else
  11886. {
  11887. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11888. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  11889. isSuccess = ConfigurationStatus_Accepted;
  11890. }
  11891. }
  11892. else
  11893. {
  11894. isSuccess = ConfigurationStatus_Rejected;
  11895. }
  11896. }
  11897. if(strcmp(key, "MeterValuesSampledData") == 0 )
  11898. {
  11899. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11900. {
  11901. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  11902. isSuccess = ConfigurationStatus_Accepted;
  11903. }
  11904. else
  11905. {
  11906. isSuccess = ConfigurationStatus_Rejected;
  11907. }
  11908. }
  11909. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  11910. {
  11911. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11912. {
  11913. check_ascii = value[0];
  11914. if( (check_ascii < 48) || (check_ascii > 57) )
  11915. {
  11916. isSuccess = ConfigurationStatus_Rejected;
  11917. }
  11918. else
  11919. {
  11920. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11921. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  11922. isSuccess = ConfigurationStatus_Accepted;
  11923. }
  11924. }
  11925. else
  11926. {
  11927. isSuccess = ConfigurationStatus_Rejected;
  11928. }
  11929. }
  11930. if(strcmp(key, "MeterValueSampleInterval") == 0)
  11931. {
  11932. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11933. {
  11934. check_ascii = value[0];
  11935. if( (check_ascii < 48) || (check_ascii > 57) )
  11936. {
  11937. isSuccess = ConfigurationStatus_Rejected;
  11938. }
  11939. else
  11940. {
  11941. if((atoi(value) == 0) || (atoi(value) >= 10))
  11942. {
  11943. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11944. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  11945. isSuccess = ConfigurationStatus_Accepted;
  11946. }
  11947. else
  11948. {
  11949. isSuccess = ConfigurationStatus_Rejected;
  11950. }
  11951. }
  11952. }
  11953. else
  11954. {
  11955. isSuccess = ConfigurationStatus_Rejected;
  11956. }
  11957. }
  11958. if(strcmp(key, "MinimumStatusDuration") == 0)
  11959. {
  11960. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11961. {
  11962. check_ascii = value[0];
  11963. if( (check_ascii < 48) || (check_ascii > 57) )
  11964. {
  11965. isSuccess = ConfigurationStatus_Rejected;
  11966. }
  11967. else
  11968. {
  11969. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  11970. {
  11971. isSuccess = ConfigurationStatus_Rejected;
  11972. }
  11973. else
  11974. {
  11975. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  11976. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  11977. server_cycle_Status = atoi(value); //StatusNotification Cycle
  11978. isSuccess = ConfigurationStatus_Accepted;
  11979. }
  11980. }
  11981. }
  11982. else
  11983. {
  11984. isSuccess = ConfigurationStatus_Rejected;
  11985. }
  11986. }
  11987. if(strcmp(key, "NumberOfConnectors") == 0)
  11988. {
  11989. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11990. {
  11991. check_ascii = value[0];
  11992. if( (check_ascii < 48) || (check_ascii > 57) )
  11993. {
  11994. isSuccess = ConfigurationStatus_Rejected;
  11995. }
  11996. else
  11997. {
  11998. //Charger.ResetRetries = Integer.parseInt(value);
  11999. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  12000. isSuccess = ConfigurationStatus_Accepted;
  12001. }
  12002. }
  12003. else
  12004. {
  12005. isSuccess = ConfigurationStatus_Rejected;
  12006. }
  12007. }
  12008. if(strcmp(key, "ResetRetries") == 0)
  12009. {
  12010. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12011. {
  12012. check_ascii = value[0];
  12013. if( (check_ascii < 48) || (check_ascii > 57) )
  12014. {
  12015. isSuccess = ConfigurationStatus_Rejected;
  12016. }
  12017. else
  12018. {
  12019. //Charger.ResetRetries = Integer.parseInt(value);
  12020. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  12021. isSuccess = ConfigurationStatus_Accepted;
  12022. }
  12023. }
  12024. else
  12025. {
  12026. isSuccess = ConfigurationStatus_Rejected;
  12027. }
  12028. }
  12029. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  12030. {
  12031. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12032. {
  12033. strcpy(str, (const char*)value);
  12034. for(int i = 0; str[i]; i++)
  12035. {
  12036. str[i] = tolower(str[i]);
  12037. }
  12038. if(strcmp(str, "notapplicable")== 0)
  12039. {
  12040. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  12041. isSuccess = ConfigurationStatus_Accepted;
  12042. }
  12043. else if(strcmp(str, "unknown")== 0)
  12044. {
  12045. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  12046. isSuccess = ConfigurationStatus_Accepted;
  12047. }
  12048. else if(strcmp(str, "rst")== 0)
  12049. {
  12050. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  12051. isSuccess = ConfigurationStatus_Accepted;
  12052. }
  12053. else if(strcmp(str, "rts")== 0)
  12054. {
  12055. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  12056. isSuccess = ConfigurationStatus_Accepted;
  12057. }
  12058. else if(strcmp(str, "srt")== 0)
  12059. {
  12060. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  12061. isSuccess = ConfigurationStatus_Accepted;
  12062. }
  12063. else if(strcmp(str, "str")== 0)
  12064. {
  12065. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  12066. isSuccess = ConfigurationStatus_Accepted;
  12067. }
  12068. else if(strcmp(str, "trs")== 0)
  12069. {
  12070. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  12071. isSuccess = ConfigurationStatus_Accepted;
  12072. }
  12073. else if(strcmp(str, "tsr")== 0)
  12074. {
  12075. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  12076. isSuccess = ConfigurationStatus_Accepted;
  12077. }
  12078. else
  12079. {
  12080. isSuccess = ConfigurationStatus_Rejected;
  12081. }
  12082. }
  12083. else
  12084. {
  12085. isSuccess = ConfigurationStatus_Rejected;
  12086. }
  12087. }
  12088. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  12089. {
  12090. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12091. {
  12092. check_ascii = value[0];
  12093. if( (check_ascii < 48) || (check_ascii > 57) )
  12094. {
  12095. isSuccess = ConfigurationStatus_Rejected;
  12096. }
  12097. else
  12098. {
  12099. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  12100. isSuccess = ConfigurationStatus_Accepted;
  12101. }
  12102. }
  12103. else
  12104. {
  12105. isSuccess = ConfigurationStatus_Rejected;
  12106. }
  12107. }
  12108. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  12109. {
  12110. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12111. {
  12112. strcpy(str, (const char*)value);
  12113. for(int i = 0; str[i]; i++)
  12114. {
  12115. str[i] = tolower(str[i]);
  12116. }
  12117. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12118. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12119. isSuccess = ConfigurationStatus_Accepted;
  12120. }
  12121. else
  12122. {
  12123. isSuccess = ConfigurationStatus_Rejected;
  12124. }
  12125. }
  12126. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  12127. {
  12128. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12129. {
  12130. strcpy(str, (const char*)value);
  12131. for(int i = 0; str[i]; i++)
  12132. {
  12133. str[i] = tolower(str[i]);
  12134. }
  12135. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  12136. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12137. isSuccess = ConfigurationStatus_Accepted;
  12138. }
  12139. else
  12140. {
  12141. isSuccess = ConfigurationStatus_Rejected;
  12142. }
  12143. }
  12144. if(strcmp(key, "StopTxnAlignedData") == 0)
  12145. {
  12146. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12147. {
  12148. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  12149. isSuccess = ConfigurationStatus_Accepted;
  12150. }
  12151. else
  12152. {
  12153. isSuccess = ConfigurationStatus_Rejected;
  12154. }
  12155. }
  12156. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  12157. {
  12158. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12159. {
  12160. check_ascii = value[0];
  12161. if( (check_ascii < 48) || (check_ascii > 57) )
  12162. {
  12163. isSuccess = ConfigurationStatus_Rejected;
  12164. }
  12165. else
  12166. {
  12167. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  12168. isSuccess = ConfigurationStatus_Accepted;
  12169. }
  12170. }
  12171. else
  12172. {
  12173. isSuccess = ConfigurationStatus_Rejected;
  12174. }
  12175. }
  12176. if(strcmp(key, "StopTxnSampledData") == 0)
  12177. {
  12178. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12179. {
  12180. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  12181. isSuccess = ConfigurationStatus_Accepted;
  12182. }
  12183. else
  12184. {
  12185. isSuccess = ConfigurationStatus_Rejected;
  12186. }
  12187. }
  12188. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  12189. {
  12190. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12191. {
  12192. check_ascii = value[0];
  12193. if( (check_ascii < 48) || (check_ascii > 57) )
  12194. {
  12195. isSuccess = ConfigurationStatus_Rejected;
  12196. }
  12197. else
  12198. {
  12199. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  12200. isSuccess = ConfigurationStatus_Accepted;
  12201. }
  12202. }
  12203. else
  12204. {
  12205. isSuccess = ConfigurationStatus_Rejected;
  12206. }
  12207. }
  12208. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  12209. {
  12210. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12211. {
  12212. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  12213. isSuccess = ConfigurationStatus_Accepted;
  12214. }
  12215. else
  12216. {
  12217. isSuccess = ConfigurationStatus_Rejected;
  12218. }
  12219. }
  12220. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  12221. {
  12222. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12223. {
  12224. check_ascii = value[0];
  12225. if( (check_ascii < 48) || (check_ascii > 57) )
  12226. {
  12227. isSuccess = ConfigurationStatus_Rejected;
  12228. }
  12229. else
  12230. {
  12231. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  12232. isSuccess = ConfigurationStatus_Accepted;
  12233. }
  12234. }
  12235. else
  12236. {
  12237. isSuccess = ConfigurationStatus_Rejected;
  12238. }
  12239. }
  12240. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12241. {
  12242. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12243. {
  12244. check_ascii = value[0];
  12245. if( (check_ascii < 48) || (check_ascii > 57) )
  12246. {
  12247. isSuccess = ConfigurationStatus_Rejected;
  12248. }
  12249. else
  12250. {
  12251. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12252. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12253. TransactionMessageAttemptsValue = atoi(value);
  12254. isSuccess = ConfigurationStatus_Accepted;
  12255. }
  12256. }
  12257. else
  12258. {
  12259. isSuccess = ConfigurationStatus_Rejected;
  12260. }
  12261. }
  12262. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12263. {
  12264. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].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. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12274. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12275. TransactionMessageRetryIntervalValue = atoi(value);
  12276. isSuccess = ConfigurationStatus_Accepted;
  12277. }
  12278. }
  12279. else
  12280. {
  12281. isSuccess = ConfigurationStatus_Rejected;
  12282. }
  12283. }
  12284. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12285. {
  12286. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12287. {
  12288. strcpy(str, (const char*)value);
  12289. for(int i = 0; str[i]; i++)
  12290. {
  12291. str[i] = tolower(str[i]);
  12292. }
  12293. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12294. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12295. isSuccess = ConfigurationStatus_Accepted;
  12296. }
  12297. else
  12298. {
  12299. isSuccess = ConfigurationStatus_Rejected;
  12300. }
  12301. }
  12302. if(strcmp(key, "WebSocketPingInterval") == 0)
  12303. {
  12304. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12305. {
  12306. check_ascii = value[0];
  12307. if( (check_ascii < 48) || (check_ascii > 57) )
  12308. {
  12309. isSuccess = ConfigurationStatus_Rejected;
  12310. }
  12311. else
  12312. {
  12313. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12314. isSuccess = ConfigurationStatus_Accepted;
  12315. }
  12316. }
  12317. else
  12318. {
  12319. isSuccess = ConfigurationStatus_Rejected;
  12320. }
  12321. }
  12322. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  12323. {
  12324. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12325. {
  12326. strcpy(str, (const char*)value);
  12327. for(int i = 0; str[i]; i++)
  12328. {
  12329. str[i] = tolower(str[i]);
  12330. }
  12331. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12332. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12333. isSuccess = ConfigurationStatus_Accepted;
  12334. }
  12335. else
  12336. {
  12337. isSuccess = ConfigurationStatus_Rejected;
  12338. }
  12339. }
  12340. if(strcmp(key, "AuthorizationKey") == 0)
  12341. {
  12342. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  12343. {
  12344. strcpy(str, (const char*)value);
  12345. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  12346. isSuccess = ConfigurationStatus_Accepted;
  12347. }
  12348. else
  12349. {
  12350. isSuccess = ConfigurationStatus_Rejected;
  12351. }
  12352. }
  12353. if(strcmp(key, "SecurityProfile") == 0)
  12354. {
  12355. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  12356. {
  12357. check_ascii = value[0];
  12358. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  12359. {
  12360. isSuccess = ConfigurationStatus_Rejected;
  12361. }
  12362. else if(check_ascii == 0x33)
  12363. {
  12364. isSuccess = NotSupported;
  12365. }
  12366. else
  12367. {
  12368. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  12369. {
  12370. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  12371. isSuccess = ConfigurationStatus_Accepted;
  12372. }
  12373. else
  12374. isSuccess = ConfigurationStatus_Rejected;
  12375. }
  12376. }
  12377. else
  12378. {
  12379. isSuccess = ConfigurationStatus_Rejected;
  12380. }
  12381. }
  12382. if(strcmp(key, "DefaultPrice") == 0)
  12383. {
  12384. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  12385. {
  12386. strcpy(str, (const char*)value);
  12387. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  12388. isSuccess = ConfigurationStatus_Accepted;
  12389. }
  12390. else
  12391. {
  12392. isSuccess = ConfigurationStatus_Rejected;
  12393. }
  12394. }
  12395. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  12396. {
  12397. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  12398. {
  12399. strcpy(str, (const char*)value);
  12400. for(int i = 0; str[i]; i++)
  12401. {
  12402. str[i] = tolower(str[i]);
  12403. }
  12404. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12405. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12406. isSuccess = ConfigurationStatus_Accepted;
  12407. }
  12408. else
  12409. {
  12410. isSuccess = ConfigurationStatus_Rejected;
  12411. }
  12412. }
  12413. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  12414. {
  12415. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  12416. {
  12417. strcpy(str, (const char*)value);
  12418. for(int i = 0; str[i]; i++)
  12419. {
  12420. str[i] = tolower(str[i]);
  12421. }
  12422. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12423. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12424. isSuccess = ConfigurationStatus_Accepted;
  12425. }
  12426. else
  12427. {
  12428. isSuccess = ConfigurationStatus_Rejected;
  12429. }
  12430. }
  12431. #if 0
  12432. //For OCPP Test Case
  12433. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  12434. {
  12435. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12436. {
  12437. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  12438. isSuccess = ConfigurationStatus_Accepted;
  12439. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12440. }
  12441. else
  12442. {
  12443. isSuccess = ConfigurationStatus_Rejected;
  12444. }
  12445. }
  12446. #endif
  12447. #if 1
  12448. if(strcmp(key, "LocalAuthListEnabled") == 0)
  12449. {
  12450. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12451. {
  12452. strcpy(str, (const char*)value);
  12453. for(int i = 0; str[i]; i++)
  12454. {
  12455. str[i] = tolower(str[i]);
  12456. }
  12457. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12458. isSuccess = ConfigurationStatus_Accepted;
  12459. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12460. }
  12461. else
  12462. {
  12463. isSuccess = ConfigurationStatus_Rejected;
  12464. }
  12465. }
  12466. #endif
  12467. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12468. {
  12469. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12470. {
  12471. check_ascii = value[0];
  12472. if( (check_ascii < 48) || (check_ascii > 57) )
  12473. {
  12474. isSuccess = ConfigurationStatus_Rejected;
  12475. }
  12476. else
  12477. {
  12478. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12479. isSuccess = ConfigurationStatus_Accepted;
  12480. }
  12481. }
  12482. else
  12483. {
  12484. isSuccess = ConfigurationStatus_Rejected;
  12485. }
  12486. }
  12487. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12488. {
  12489. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12490. {
  12491. check_ascii = value[0];
  12492. if( (check_ascii < 48) || (check_ascii > 57) )
  12493. {
  12494. isSuccess = ConfigurationStatus_Rejected;
  12495. }
  12496. else
  12497. {
  12498. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12499. isSuccess = ConfigurationStatus_Accepted;
  12500. }
  12501. }
  12502. else
  12503. {
  12504. isSuccess = ConfigurationStatus_Rejected;
  12505. }
  12506. }
  12507. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12508. {
  12509. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12510. {
  12511. strcpy(str, (const char*)value);
  12512. for(int i = 0; str[i]; i++)
  12513. {
  12514. str[i] = tolower(str[i]);
  12515. }
  12516. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12517. isSuccess = ConfigurationStatus_Accepted;
  12518. }
  12519. else
  12520. {
  12521. isSuccess = ConfigurationStatus_Rejected;
  12522. }
  12523. }
  12524. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12525. {
  12526. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12527. {
  12528. check_ascii = value[0];
  12529. if( (check_ascii < 48) || (check_ascii > 57) )
  12530. {
  12531. isSuccess = ConfigurationStatus_Rejected;
  12532. }
  12533. else
  12534. {
  12535. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12536. isSuccess = ConfigurationStatus_Accepted;
  12537. }
  12538. }
  12539. else
  12540. {
  12541. isSuccess = ConfigurationStatus_Rejected;
  12542. }
  12543. }
  12544. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12545. {
  12546. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12547. {
  12548. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12549. isSuccess = ConfigurationStatus_Accepted;
  12550. }
  12551. else
  12552. {
  12553. isSuccess = ConfigurationStatus_Rejected;
  12554. }
  12555. }
  12556. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12557. {
  12558. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12559. {
  12560. check_ascii = value[0];
  12561. if( (check_ascii < 48) || (check_ascii > 57) )
  12562. {
  12563. isSuccess = ConfigurationStatus_Rejected;
  12564. }
  12565. else
  12566. {
  12567. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12568. isSuccess = ConfigurationStatus_Accepted;
  12569. }
  12570. }
  12571. else
  12572. {
  12573. isSuccess = ConfigurationStatus_Rejected;
  12574. }
  12575. }
  12576. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12577. {
  12578. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12579. {
  12580. strcpy(str, (const char*)value);
  12581. for(int i = 0; str[i]; i++)
  12582. {
  12583. str[i] = tolower(str[i]);
  12584. }
  12585. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12586. isSuccess = ConfigurationStatus_Accepted;
  12587. }
  12588. else
  12589. {
  12590. isSuccess = ConfigurationStatus_Rejected;
  12591. }
  12592. }
  12593. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12594. {
  12595. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12596. {
  12597. check_ascii = value[0];
  12598. if( (check_ascii < 48) || (check_ascii > 57) )
  12599. {
  12600. isSuccess = ConfigurationStatus_Rejected;
  12601. }
  12602. else
  12603. {
  12604. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12605. isSuccess = ConfigurationStatus_Accepted;
  12606. }
  12607. }
  12608. else
  12609. {
  12610. isSuccess = ConfigurationStatus_Rejected;
  12611. }
  12612. }
  12613. return isSuccess;
  12614. }
  12615. int TransactionMessageAttemptsGet(void)
  12616. {
  12617. return TransactionMessageAttemptsValue;
  12618. }
  12619. int FirstHeartBeatResponse(void)
  12620. {
  12621. return FirstHeartBeat;
  12622. }
  12623. int TransactionMessageRetryIntervalGet(void)
  12624. {
  12625. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12626. }
  12627. int ReadHttpStatus(int sock)
  12628. {
  12629. //char c;
  12630. char buff[1024]="",*ptr=buff+1;
  12631. int bytes_received, status;
  12632. DEBUG_INFO("Begin Response ..\n");
  12633. while((bytes_received = recv(sock, ptr, 1, 0))){
  12634. if(bytes_received==-1){
  12635. perror("ReadHttpStatus");
  12636. exit(1);
  12637. }
  12638. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  12639. ptr++;
  12640. }
  12641. *ptr=0;
  12642. ptr=buff+1;
  12643. sscanf(ptr,"%*s %d ", &status);
  12644. DEBUG_INFO("%s\n",ptr);
  12645. DEBUG_INFO("status=%d\n",status);
  12646. DEBUG_INFO("End Response ..\n");
  12647. return (bytes_received>0)?status:0;
  12648. }
  12649. //the only filed that it parsed is 'Content-Length'
  12650. int ParseHeader(int sock)
  12651. {
  12652. //char c;
  12653. char buff[1024]="",*ptr=buff+4;
  12654. int bytes_received;
  12655. DEBUG_INFO("Begin HEADER ..\n");
  12656. while((bytes_received = recv(sock, ptr, 1, 0))){
  12657. if(bytes_received==-1){
  12658. perror("Parse Header");
  12659. exit(1);
  12660. }
  12661. if(
  12662. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  12663. (ptr[-1]=='\r') && (*ptr=='\n' )
  12664. ) break;
  12665. ptr++;
  12666. }
  12667. *ptr=0;
  12668. ptr=buff+4;
  12669. //printf("%s",ptr);
  12670. if(bytes_received){
  12671. ptr=strstr(ptr,"Content-Length:");
  12672. if(ptr){
  12673. sscanf(ptr,"%*s %d",&bytes_received);
  12674. }else
  12675. bytes_received=-1; //unknown size
  12676. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  12677. }
  12678. DEBUG_INFO("End HEADER ..\n");
  12679. return bytes_received ;
  12680. }
  12681. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  12682. {
  12683. char rmFileCmd[100]={0};
  12684. char FilePath[100]={0};
  12685. char ftpbuf[200];
  12686. int systemresult;
  12687. //DEBUG_INFO("filename=%s\n",filename);
  12688. //DEBUG_INFO("url=%s\n",url);
  12689. sprintf(FilePath,"/mnt/%s",filename);
  12690. if((access(FilePath,F_OK))!=-1)
  12691. {
  12692. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12693. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12694. system(rmFileCmd);
  12695. }
  12696. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12697. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  12698. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12699. systemresult = system(ftpbuf);
  12700. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12701. if(systemresult != 0)
  12702. {
  12703. DEBUG_INFO("http DownLoad error!\n");
  12704. return FALSE;
  12705. }
  12706. return TRUE;
  12707. }
  12708. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  12709. {
  12710. char rmFileCmd[100]={0};
  12711. char FilePath[100]={0};
  12712. char ftpbuf[200];
  12713. int systemresult;
  12714. //char temp[100];
  12715. sprintf(FilePath,"/mnt/%s",filename);
  12716. if((access(FilePath,F_OK))!=-1)
  12717. {
  12718. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12719. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12720. system(rmFileCmd);
  12721. }
  12722. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12723. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  12724. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  12725. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12726. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12727. systemresult = system(ftpbuf);
  12728. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12729. if(systemresult != 0)
  12730. {
  12731. printf("wget error!\n");
  12732. return FALSE;
  12733. }
  12734. return TRUE;
  12735. }
  12736. int httpUploadFile(char *location, char *path, char *filename,char *url)
  12737. {
  12738. char rmFileCmd[100]={0};
  12739. char FilePath[100]={0};
  12740. char ftpbuf[200];
  12741. int systemresult;
  12742. //DEBUG_INFO("filename=%s\n",filename);
  12743. //DEBUG_INFO("url=%s\n",url);
  12744. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  12745. if((access(FilePath,F_OK))!=-1)
  12746. {
  12747. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12748. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12749. system(rmFileCmd);
  12750. }
  12751. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  12752. if(fp == NULL)
  12753. {
  12754. DEBUG_INFO("log is NULL\n");
  12755. return FALSE;
  12756. }
  12757. else
  12758. {
  12759. fprintf(fp, "%s\n", url);
  12760. fprintf(fp, "%s\n", filename);
  12761. fclose(fp);
  12762. }
  12763. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12764. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  12765. systemresult = system(ftpbuf);
  12766. DEBUG_INFO("systemresult = %d\n",systemresult);
  12767. if(systemresult != 0)
  12768. {
  12769. DEBUG_INFO("http upload error!\n");
  12770. return FALSE;
  12771. }
  12772. return TRUE;
  12773. }
  12774. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  12775. {
  12776. struct hostent* server;
  12777. char *IPbuffer;
  12778. char ftpbuf[200];
  12779. int systemresult;
  12780. // To retrieve host information
  12781. server = gethostbyname(location);
  12782. // To convert an Internet network
  12783. // address into ASCII string
  12784. IPbuffer = inet_ntoa(*((struct in_addr*)
  12785. server->h_addr_list[0]));
  12786. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12787. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  12788. /* format : ftpput -u username -p passwd IP target source*/
  12789. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  12790. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12791. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12792. systemresult = system(ftpbuf);
  12793. DEBUG_INFO("systemresult=%d\n",systemresult);
  12794. if(systemresult != 0)
  12795. {
  12796. DEBUG_INFO("ftpput error!\n");
  12797. return FALSE;
  12798. }
  12799. return TRUE;
  12800. }
  12801. /**
  12802. * Place the contents of the specified file into a memory buffer
  12803. *
  12804. * @param[in] filename The path and name of the file to read
  12805. * @param[out] filebuffer A pointer to the contents in memory
  12806. * @return status 0 success, 1 on failure
  12807. */
  12808. int get_file_contents(const char* filename, char** outbuffer) {
  12809. FILE* file = NULL;
  12810. long filesize;
  12811. const int blocksize = 1;
  12812. size_t readsize;
  12813. char* filebuffer;
  12814. // Open the file
  12815. file = fopen(filename, "r");
  12816. if (NULL == file)
  12817. {
  12818. printf("'%s' not opened\n", filename);
  12819. exit(EXIT_FAILURE);
  12820. }
  12821. // Determine the file size
  12822. fseek(file, 0, SEEK_END);
  12823. filesize = ftell(file);
  12824. rewind (file);
  12825. // Allocate memory for the file contents
  12826. filebuffer = (char*) malloc(sizeof(char) * filesize);
  12827. *outbuffer = filebuffer;
  12828. if (filebuffer == NULL)
  12829. {
  12830. fputs ("malloc out-of-memory", stderr);
  12831. exit(EXIT_FAILURE);
  12832. }
  12833. // Read in the file
  12834. readsize = fread(filebuffer, blocksize, filesize, file);
  12835. if (readsize != filesize)
  12836. {
  12837. fputs ("didn't read file completely",stderr);
  12838. exit(EXIT_FAILURE);
  12839. }
  12840. // Clean exit
  12841. fclose(file);
  12842. return EXIT_SUCCESS;
  12843. }
  12844. static int selectSqlCount = 0;
  12845. static int callback(void *data, int argc, char **argv, char **azColName){
  12846. int i;
  12847. //printf("%s: ", (const char*)data);
  12848. selectSqlCount = argc;
  12849. for(i = 0; i<argc; i++){
  12850. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  12851. }
  12852. //printf("\n");
  12853. return 0;
  12854. }
  12855. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  12856. //int i;
  12857. //printf("%s:\n", (const char*)data);
  12858. localversion = argv[5] ? atoi(argv[5]) : 0;
  12859. //printf("localversion=%d\n", localversion);
  12860. return 0;
  12861. }
  12862. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  12863. //printf("%s:\n", (const char*)data);
  12864. //idTag
  12865. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  12866. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  12867. //parentIdTag
  12868. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  12869. //expir_date
  12870. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  12871. //status
  12872. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  12873. //version
  12874. if(columenCount > 5)
  12875. idTagQuery.listVersionInt = atoi(columnValue[5]);
  12876. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  12877. return 0;
  12878. }
  12879. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  12880. {
  12881. // localversion = argv[5] ? atoi(argv[5]) : 0;
  12882. // printf("localversion=%d\n", localversion);
  12883. return 0;
  12884. }
  12885. //=========================================
  12886. // Sqlite3 related function
  12887. //=========================================
  12888. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  12889. {
  12890. for (int i = 0; i < n_columns; i++)
  12891. {
  12892. DEBUG_INFO("%s\t", col_values[i]);
  12893. }
  12894. DEBUG_INFO("\n");
  12895. return 0;
  12896. }
  12897. int OCPP_cleanLocalCache()
  12898. {
  12899. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  12900. char *errMsg = 0;
  12901. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  12902. if (SQLITE_OK != rc)
  12903. {
  12904. DEBUG_INFO("SQL error: %s\n",errMsg);
  12905. return FALSE;
  12906. }
  12907. return TRUE;
  12908. }
  12909. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  12910. {
  12911. int isSuccess = TRUE;
  12912. int ret = 0;
  12913. //const char* data = "Callback function called";
  12914. char sql[300];
  12915. char zErrMsg[200];
  12916. memset(sql, 0, 300);
  12917. memset(zErrMsg, 0, 200);
  12918. 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);
  12919. //* Execute SQL statement */
  12920. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  12921. if( ret != SQLITE_OK )
  12922. {
  12923. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12924. isSuccess = FALSE;
  12925. }
  12926. return isSuccess;
  12927. }
  12928. void OCPP_getIdTagFromLocalCache(char idTag[])
  12929. {
  12930. int rc = 0;
  12931. char sql[100];
  12932. char zErrMsg[100];
  12933. memset(sql, 0, 100);
  12934. memset(zErrMsg, 0, 100);
  12935. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  12936. memset(&idTagQuery, 0, sizeof(idTagQuery));
  12937. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  12938. /* Execute SQL statement */
  12939. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  12940. if( rc != SQLITE_OK )
  12941. {
  12942. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12943. }
  12944. }
  12945. void OCPP_getListVerion()
  12946. {
  12947. int rc = 0;
  12948. // const char* data = "Callback function called";
  12949. char sql[100];
  12950. char zErrMsg[100];
  12951. memset(sql, 0, 100);
  12952. memset(zErrMsg, 0, 100);
  12953. strcpy(sql, "select * from ocpp_auth_local order by idx");
  12954. /* Execute SQL statement */
  12955. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  12956. if( rc != SQLITE_OK )
  12957. {
  12958. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12959. }
  12960. }
  12961. void OCPP_get_TableAuthlocalAllData(void)
  12962. {
  12963. int rc = 0;
  12964. char sql[100];
  12965. char zErrMsg[100];
  12966. memset(sql, 0, 100);
  12967. memset(zErrMsg, 0, 100);
  12968. sprintf(sql,"select * from ocpp_auth_local ");
  12969. /* Execute SQL statement */
  12970. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  12971. if( rc != SQLITE_OK )
  12972. {
  12973. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12974. }
  12975. //return ver;
  12976. }
  12977. int OCPP_cleanLocalList()
  12978. {
  12979. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  12980. char *errMsg = 0;
  12981. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  12982. if (SQLITE_OK != rc)
  12983. {
  12984. DEBUG_INFO("%s\n",errMsg);
  12985. return FALSE;
  12986. }
  12987. return TRUE;
  12988. }
  12989. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  12990. {
  12991. int isSuccess = FALSE;
  12992. int ret = 0;
  12993. //const char* data = "Callback function called";
  12994. char sql[300];
  12995. char zErrMsg[200];
  12996. memset(sql, 0, 300);
  12997. memset(zErrMsg, 0, 200);
  12998. 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);
  12999. //* Execute SQL statement */
  13000. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  13001. if( ret != SQLITE_OK )
  13002. {
  13003. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13004. return isSuccess;
  13005. }
  13006. memset(sql, 0, 300);
  13007. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  13008. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  13009. if( ret != SQLITE_OK )
  13010. {
  13011. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13012. return isSuccess;
  13013. }
  13014. isSuccess = TRUE;
  13015. return isSuccess;
  13016. }
  13017. void OCPP_getIdTagFromLocalList(char idTag[])
  13018. {
  13019. int rc = 0;
  13020. // const char* data = "Callback function called";
  13021. char sql[100];
  13022. char zErrMsg[100];
  13023. memset(sql, 0, 100);
  13024. memset(zErrMsg, 0, 100);
  13025. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  13026. memset(&idTagQuery, 0, sizeof(idTagQuery));
  13027. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  13028. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  13029. /* Execute SQL statement */
  13030. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  13031. if( rc != SQLITE_OK )
  13032. {
  13033. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13034. }
  13035. //return ver;
  13036. }
  13037. void OCPP_deleteIdTagFromLocalList(char idTag[])
  13038. {
  13039. //int ver = 0;
  13040. //int isSuccess = FALSE;
  13041. int rc = 0;
  13042. char sql[100];
  13043. char zErrMsg[100];
  13044. memset(sql, 0, 100);
  13045. memset(zErrMsg, 0, 100);
  13046. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  13047. //* Execute SQL statement */
  13048. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  13049. if( rc != SQLITE_OK )
  13050. {
  13051. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13052. }
  13053. }
  13054. int GetOcppServerURL()
  13055. {
  13056. int result = FALSE;
  13057. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  13058. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  13059. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  13060. struct yuarel url;
  13061. char urlStr[512];
  13062. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  13063. {
  13064. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  13065. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13066. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  13067. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  13068. if(yuarel_parse(&url, urlStr) != -1)
  13069. {
  13070. sprintf(OcppProtocol, "%s", url.scheme);
  13071. sprintf(OcppHost, "%s", url.host);
  13072. if(url.path == NULL)
  13073. OcppTempPath[0] = '\0';
  13074. else
  13075. sprintf(OcppTempPath, "%s", url.path);
  13076. if(url.port == 0)
  13077. {
  13078. if(strcmp(OcppProtocol, "wss") == 0)
  13079. OcppPort = 443;
  13080. else
  13081. OcppPort = 80;
  13082. }
  13083. else
  13084. OcppPort = url.port;
  13085. result = TRUE;
  13086. }
  13087. }
  13088. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  13089. {
  13090. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  13091. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13092. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  13093. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  13094. if(yuarel_parse(&url, urlStr) != -1)
  13095. {
  13096. sprintf(OcppProtocol, "%s", url.scheme);
  13097. sprintf(OcppHost, "%s", url.host);
  13098. if(url.path == NULL)
  13099. OcppTempPath[0] = '\0';
  13100. else
  13101. sprintf(OcppTempPath, "%s", url.path);
  13102. if(url.port == 0)
  13103. {
  13104. if(strcmp(OcppProtocol, "wss") == 0)
  13105. OcppPort = 443;
  13106. else
  13107. OcppPort = 80;
  13108. }
  13109. else
  13110. OcppPort = url.port;
  13111. result = TRUE;
  13112. }
  13113. }
  13114. else
  13115. {
  13116. strcpy(OcppHost,"");
  13117. }
  13118. return result;
  13119. }
  13120. int GetOcppPath()
  13121. {
  13122. int result = FALSE;
  13123. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  13124. {
  13125. if(OcppTempPath == NULL)
  13126. {
  13127. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13128. }
  13129. else
  13130. {
  13131. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13132. }
  13133. result = TRUE;
  13134. goto End;
  13135. }
  13136. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  13137. {
  13138. if(OcppTempPath == NULL)
  13139. {
  13140. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  13141. }
  13142. else
  13143. {
  13144. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  13145. }
  13146. result = TRUE;
  13147. goto End;
  13148. }
  13149. else
  13150. {
  13151. strcpy(OcppPath,"");
  13152. }
  13153. End:
  13154. return result;
  13155. }
  13156. int GetOcppPort()
  13157. {
  13158. return OcppPort;
  13159. }
  13160. int GetOcppConnStatus(void)
  13161. {
  13162. return ShmOCPP16Data->OcppConnStatus;
  13163. }
  13164. void SetOcppConnStatus(uint8_t status)
  13165. {
  13166. ShmOCPP16Data->OcppConnStatus = status;
  13167. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  13168. }
  13169. int GetHeartBeatWithNOResponse(void)
  13170. {
  13171. return HeartBeatWithNOResponse;
  13172. }
  13173. void SetHeartBeatWithNOResponse(void)
  13174. {
  13175. HeartBeatWithNOResponse = 0;
  13176. }
  13177. void GetStartTransactionIdTag(int gun_index)
  13178. {
  13179. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  13180. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13181. }
  13182. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  13183. {
  13184. char ch;
  13185. FILE *fptr1;
  13186. int temptransactionId;
  13187. char str[100]={0};
  13188. temptransactionId = 0;
  13189. if((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0'))
  13190. {
  13191. DEBUG_INFO("IdTag is empty.\n");
  13192. return temptransactionId;
  13193. }
  13194. /*------ Read the file ----------------*/
  13195. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  13196. if (!fptr1)
  13197. {
  13198. DEBUG_INFO("QueueTransactionId file open error.\n");
  13199. //printf(" File not found or unable to open the input file!!\n");
  13200. return temptransactionId;
  13201. }
  13202. ch=fgetc(fptr1);
  13203. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  13204. rewind(fptr1);
  13205. if(ch!=EOF)
  13206. {
  13207. // printf("%c",ch);
  13208. while (fgets(str, 100, fptr1) != NULL)
  13209. {
  13210. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13211. if(str[0]=='\0')
  13212. {
  13213. break;
  13214. }
  13215. char *revbuf[8] = {0}; // Variable store string split
  13216. int num = 0;// Quantity after string split
  13217. DEBUG_INFO("Transaction queue data= %s\n", str);
  13218. splitstring(str,",",revbuf,&num); // String split
  13219. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  13220. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  13221. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  13222. DEBUG_INFO("------------------------------\n");
  13223. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  13224. {
  13225. if(isStopTransaction)
  13226. {
  13227. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  13228. {
  13229. temptransactionId = atoi(revbuf[2]);
  13230. break;
  13231. }
  13232. }
  13233. else
  13234. {
  13235. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  13236. {
  13237. temptransactionId = atoi(revbuf[2]);
  13238. break;
  13239. }
  13240. }
  13241. }
  13242. }
  13243. }
  13244. else
  13245. DEBUG_INFO("EOF\n");
  13246. fclose(fptr1);
  13247. /*------- End of reading ---------------*/
  13248. return temptransactionId;
  13249. }
  13250. void SetTransactionIdZero(int transactionId)
  13251. {
  13252. char ch;
  13253. FILE *fptr1, *fptr2;
  13254. int temptransactionId = 0;
  13255. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  13256. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  13257. if (!fptr1)
  13258. {
  13259. //printf(" File not found or unable to open the input file!!\n");
  13260. return ;
  13261. }
  13262. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13263. if (!fptr2)
  13264. {
  13265. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  13266. fclose(fptr1);
  13267. return ;
  13268. }
  13269. ch=fgetc(fptr1);
  13270. rewind(fptr1);
  13271. if(ch!=EOF)
  13272. {
  13273. // copy all contents to the temporary file except the specific line
  13274. while (fgets(str, 100, fptr1) != NULL)
  13275. {
  13276. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13277. if(str[0]=='\0')
  13278. {
  13279. break;
  13280. }
  13281. char *revbuf[8] = {0};
  13282. int num = 0;
  13283. strcpy(strtemp, str);
  13284. splitstring(str,",",revbuf,&num);
  13285. if(revbuf[2][0] != '\0')
  13286. {
  13287. temptransactionId = atoi(revbuf[2]);
  13288. if(transactionId != temptransactionId)
  13289. {
  13290. fprintf(fptr2, "%s\n", strtemp);
  13291. }
  13292. }
  13293. }
  13294. }
  13295. fclose(fptr1);
  13296. fclose(fptr2);
  13297. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13298. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13299. /*------ Read the file ----------------*/
  13300. }
  13301. int InternetDisconnect(void)
  13302. {
  13303. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13304. }
  13305. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  13306. void storeTempStopTransaction(int gun_index)
  13307. {
  13308. char guid[37]={0};
  13309. int tempIndex = 0;
  13310. char TempStopTransaction[256];
  13311. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  13312. DEBUG_INFO("storeTempStopTransaction...\n");
  13313. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  13314. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  13315. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  13316. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13317. if(gunType[gun_index] == 'J')
  13318. {
  13319. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13320. {
  13321. tempIndex = ((gun_index==2) ? 1: 0);
  13322. }
  13323. else
  13324. {
  13325. tempIndex = gun_index;
  13326. }
  13327. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13328. {
  13329. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13330. {
  13331. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  13332. }
  13333. }// END OF CHAdeMO_QUANTITY
  13334. }
  13335. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13336. {
  13337. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13338. {
  13339. tempIndex = ((gun_index==2) ? 1: 0);
  13340. }
  13341. else
  13342. {
  13343. tempIndex = gun_index;
  13344. }
  13345. for (int index = 0; index < CCS_QUANTITY; index++)
  13346. {
  13347. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13348. {
  13349. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  13350. }
  13351. }// END OF CCS_QUANTITY
  13352. }
  13353. else if(gunType[gun_index] == 'G')
  13354. {
  13355. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13356. {
  13357. tempIndex = ((gun_index==2) ? 1: 0);
  13358. }
  13359. else
  13360. {
  13361. tempIndex = gun_index;
  13362. }
  13363. for (int index = 0; index < GB_QUANTITY; index++)
  13364. {
  13365. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13366. {
  13367. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  13368. }
  13369. }// END OF GB_QUANTITY
  13370. }
  13371. else if(gunType[gun_index] == 'O')
  13372. {
  13373. tempIndex = gun_index;
  13374. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13375. {
  13376. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13377. {
  13378. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  13379. }
  13380. }
  13381. }
  13382. else
  13383. {
  13384. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13385. {
  13386. tempIndex = 2;
  13387. }
  13388. else
  13389. {
  13390. tempIndex = gun_index;
  13391. }
  13392. for (int index = 0; index < AC_QUANTITY; index++)
  13393. {
  13394. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13395. {
  13396. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  13397. }
  13398. }// END OF AC_QUANTITY
  13399. }
  13400. //Stop Transaction Time
  13401. struct timeval tmnow;
  13402. struct tm *tm;
  13403. char buf[28];//, usec_buf[6];
  13404. gettimeofday(&tmnow, NULL);
  13405. time_t t;
  13406. t = time(NULL);
  13407. /*UTC time and date*/
  13408. tm = gmtime(&t);
  13409. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  13410. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  13411. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  13412. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13413. random_uuid(guid);
  13414. /***********************************transactionData******************************************************/
  13415. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  13416. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  13417. //=================================
  13418. //1. Transaction_Begin
  13419. //=================================
  13420. //============================== Energy.Active.Import.Interval ===========================================
  13421. //idx_sample=0;
  13422. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  13423. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  13424. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  13425. 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*/]);
  13426. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13427. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13428. {
  13429. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  13430. }
  13431. else
  13432. {
  13433. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  13434. }
  13435. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  13436. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13437. //=================================
  13438. //2. Transaction_End
  13439. //=================================
  13440. //2.1====================================== Current.Import L1 ==============================================
  13441. //idx_sample=1;
  13442. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  13443. if(gunType[gun_index] == 'J')
  13444. {
  13445. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13446. {
  13447. tempIndex = ((gun_index==2) ? 1: 0);
  13448. }
  13449. else
  13450. {
  13451. tempIndex = gun_index;
  13452. }
  13453. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13454. {
  13455. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13456. {
  13457. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13458. }
  13459. }// End of for CHAdeMO_QUANTITY
  13460. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13461. }
  13462. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13463. {
  13464. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13465. {
  13466. tempIndex = ((gun_index==2) ? 1: 0);
  13467. }
  13468. else
  13469. {
  13470. tempIndex = gun_index;
  13471. }
  13472. for (int index = 0; index < CCS_QUANTITY; index++)
  13473. {
  13474. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13475. {
  13476. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13477. }
  13478. }// End of for CCS_QUANTITY
  13479. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13480. }
  13481. else if(gunType[gun_index] == 'G')
  13482. {
  13483. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13484. {
  13485. tempIndex = ((gun_index==2) ? 1: 0);
  13486. }
  13487. else
  13488. {
  13489. tempIndex = gun_index;
  13490. }
  13491. for (int index = 0; index < GB_QUANTITY; index++)
  13492. {
  13493. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13494. {
  13495. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13496. }
  13497. }// End of for GB_QUANTITY
  13498. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13499. }
  13500. else if(gunType[gun_index] == 'O')
  13501. {
  13502. tempIndex = gun_index;
  13503. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13504. {
  13505. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13506. {
  13507. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13508. }
  13509. }
  13510. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13511. }
  13512. else
  13513. {
  13514. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13515. {
  13516. tempIndex = 2;
  13517. }
  13518. else
  13519. {
  13520. tempIndex = gun_index;
  13521. }
  13522. for (int index = 0; index < AC_QUANTITY; index++)
  13523. {
  13524. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13525. {
  13526. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  13527. }
  13528. }// End of for AC_QUANTITY
  13529. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13530. }
  13531. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13532. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  13533. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  13534. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13535. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  13536. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13537. //2.2===================================== Energy.Active.Import.Interval ==========================================
  13538. //idx_sample=2;
  13539. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13540. if(gunType[gun_index] == 'J')
  13541. {
  13542. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13543. {
  13544. tempIndex = ((gun_index==2) ? 1: 0);
  13545. }
  13546. else
  13547. {
  13548. tempIndex = gun_index;
  13549. }
  13550. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13551. {
  13552. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13553. {
  13554. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13555. }
  13556. }// END OF CHAdeMO_QUANTITY
  13557. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13558. }
  13559. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13560. {
  13561. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13562. {
  13563. tempIndex = ((gun_index==2) ? 1: 0);
  13564. }
  13565. else
  13566. {
  13567. tempIndex = gun_index;
  13568. }
  13569. for (int index = 0; index < CCS_QUANTITY; index++)
  13570. {
  13571. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13572. {
  13573. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13574. }
  13575. }// END OF CCS_QUANTITY
  13576. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13577. }
  13578. else if(gunType[gun_index] == 'G')
  13579. {
  13580. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13581. {
  13582. tempIndex = ((gun_index==2) ? 1: 0);
  13583. }
  13584. else
  13585. {
  13586. tempIndex = gun_index;
  13587. }
  13588. for (int index = 0; index < GB_QUANTITY; index++)
  13589. {
  13590. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13591. {
  13592. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13593. }
  13594. }// END OF GB_QUANTITY
  13595. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13596. }
  13597. else if(gunType[gun_index] == 'O')
  13598. {
  13599. tempIndex = gun_index;
  13600. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13601. {
  13602. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13603. {
  13604. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13605. }
  13606. }
  13607. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13608. }
  13609. else
  13610. {
  13611. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13612. {
  13613. tempIndex = 2;
  13614. }
  13615. else
  13616. {
  13617. tempIndex = gun_index;
  13618. }
  13619. for (int index = 0; index < AC_QUANTITY; index++)
  13620. {
  13621. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13622. {
  13623. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13624. }
  13625. }// END OF AC_QUANTITY
  13626. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13627. }
  13628. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13629. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  13630. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  13631. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13632. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  13633. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13634. //2.3====================================== Power.Active.Import =========================================
  13635. //idx_sample=3;
  13636. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13637. if(gunType[gun_index] == 'J')
  13638. {
  13639. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13640. {
  13641. tempIndex = ((gun_index==2) ? 1: 0);
  13642. }
  13643. else
  13644. {
  13645. tempIndex = gun_index;
  13646. }
  13647. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13648. {
  13649. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13650. {
  13651. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13652. }
  13653. } // End for CHAdeMO_QUANTITY
  13654. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13655. }
  13656. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13657. {
  13658. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13659. {
  13660. tempIndex = ((gun_index==2) ? 1: 0);
  13661. }
  13662. else
  13663. {
  13664. tempIndex = gun_index;
  13665. }
  13666. for (int index = 0; index < CCS_QUANTITY; index++)
  13667. {
  13668. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13669. {
  13670. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13671. }
  13672. } // END for CCS_QUANTITY
  13673. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13674. }
  13675. else if(gunType[gun_index] == 'G')
  13676. {
  13677. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13678. {
  13679. tempIndex = ((gun_index==2) ? 1: 0);
  13680. }
  13681. else
  13682. {
  13683. tempIndex = gun_index;
  13684. }
  13685. for (int index = 0; index < GB_QUANTITY; index++)
  13686. {
  13687. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13688. {
  13689. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13690. }
  13691. }// END for GB_QUANTITY
  13692. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13693. }
  13694. else if(gunType[gun_index] == 'O')
  13695. {
  13696. tempIndex = gun_index;
  13697. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13698. {
  13699. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13700. {
  13701. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13702. }
  13703. }
  13704. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13705. }
  13706. else
  13707. {
  13708. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13709. {
  13710. tempIndex = 2;
  13711. }
  13712. else
  13713. {
  13714. tempIndex = gun_index;
  13715. }
  13716. for (int index = 0; index < AC_QUANTITY; index++)
  13717. {
  13718. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13719. {
  13720. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13721. }
  13722. } // END for AC_QUANTITY
  13723. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13724. }
  13725. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13726. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  13727. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  13728. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13729. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  13730. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  13731. //2.4====================================== Voltage L1 ====================================================
  13732. //idx_sample=4;
  13733. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13734. if(gunType[gun_index] == 'J')
  13735. {
  13736. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13737. {
  13738. tempIndex = ((gun_index==2) ? 1: 0);
  13739. }
  13740. else
  13741. {
  13742. tempIndex = gun_index;
  13743. }
  13744. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13745. {
  13746. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13747. {
  13748. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13749. }
  13750. } // END OF FOR CHAdeMO_QUANTITY
  13751. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13752. }
  13753. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13754. {
  13755. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13756. {
  13757. tempIndex = ((gun_index==2) ? 1: 0);
  13758. }
  13759. else
  13760. {
  13761. tempIndex = gun_index;
  13762. }
  13763. for (int index = 0; index < CCS_QUANTITY; index++)
  13764. {
  13765. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13766. {
  13767. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13768. }
  13769. } // END OF FOR CCS_QUANTITY
  13770. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13771. }
  13772. else if(gunType[gun_index] == 'G')
  13773. {
  13774. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13775. {
  13776. tempIndex = ((gun_index==2) ? 1: 0);
  13777. }
  13778. else
  13779. {
  13780. tempIndex = gun_index;
  13781. }
  13782. for (int index = 0; index < GB_QUANTITY; index++)
  13783. {
  13784. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13785. {
  13786. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13787. }
  13788. } // END OF FOR GB_QUANTITY
  13789. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13790. }
  13791. else if(gunType[gun_index] == 'O')
  13792. {
  13793. tempIndex = gun_index;
  13794. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13795. {
  13796. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13797. {
  13798. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13799. }
  13800. }
  13801. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13802. }
  13803. else
  13804. {
  13805. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13806. {
  13807. tempIndex = 2;
  13808. }
  13809. else
  13810. {
  13811. tempIndex = gun_index;
  13812. }
  13813. for (int index = 0; index < AC_QUANTITY; index++)
  13814. {
  13815. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13816. {
  13817. 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
  13818. }
  13819. } // END OF FOR AC_QUANTITY
  13820. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13821. }
  13822. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13823. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  13824. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  13825. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13826. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  13827. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13828. //2.5============================================== End SoC =========================================================
  13829. //idx_sample=5;
  13830. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13831. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  13832. {
  13833. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != 'O'))
  13834. {
  13835. tempIndex = ((gun_index==2) ? 1: 0);
  13836. }
  13837. else
  13838. {
  13839. tempIndex = gun_index;
  13840. }
  13841. if(gunType[gun_index] == 'J')
  13842. {
  13843. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13844. {
  13845. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13846. {
  13847. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  13848. }
  13849. }
  13850. }
  13851. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13852. {
  13853. for (int index = 0; index < CCS_QUANTITY; index++)
  13854. {
  13855. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13856. {
  13857. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  13858. }
  13859. }
  13860. }
  13861. else if(gunType[gun_index] == 'G')
  13862. {
  13863. for (int index = 0; index < GB_QUANTITY; index++)
  13864. {
  13865. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13866. {
  13867. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  13868. }
  13869. }
  13870. }
  13871. else if(gunType[gun_index] == 'O')
  13872. {
  13873. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13874. {
  13875. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13876. {
  13877. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  13878. }
  13879. }
  13880. }
  13881. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13882. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  13883. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  13884. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  13885. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  13886. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  13887. } // END FOR DC CASE
  13888. //2.6====================================== Current.Import L2 ==============================================
  13889. // idx_sample=6;
  13890. // AC 3 phase L2 current
  13891. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13892. {
  13893. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13894. {
  13895. tempIndex = 2;
  13896. }
  13897. else
  13898. {
  13899. tempIndex = gun_index;
  13900. }
  13901. for (int index = 0; index < AC_QUANTITY; index++)
  13902. {
  13903. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13904. {
  13905. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  13906. }
  13907. }// End of for AC_QUANTITY
  13908. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  13909. }
  13910. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13911. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  13912. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  13913. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  13914. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13915. //2.7====================================== Current.Import L3 ==============================================
  13916. // idx_sample=7;
  13917. // AC 3 phase L3 current
  13918. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13919. {
  13920. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13921. {
  13922. tempIndex = 2;
  13923. }
  13924. else
  13925. {
  13926. tempIndex = gun_index;
  13927. }
  13928. for (int index = 0; index < AC_QUANTITY; index++)
  13929. {
  13930. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13931. {
  13932. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  13933. }
  13934. }// End of for AC_QUANTITY
  13935. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  13936. }
  13937. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13938. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  13939. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  13940. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  13941. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13942. //2.9====================================== Voltage L2 ====================================================
  13943. //idx_sample=8;
  13944. // AC 3 phase L2 volatge
  13945. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13946. {
  13947. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13948. {
  13949. tempIndex = 2;
  13950. }
  13951. else
  13952. {
  13953. tempIndex = gun_index;
  13954. }
  13955. for (int index = 0; index < AC_QUANTITY; index++)
  13956. {
  13957. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13958. {
  13959. 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
  13960. }
  13961. } // END OF FOR AC_QUANTITY
  13962. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  13963. }
  13964. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13965. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  13966. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  13967. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  13968. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13969. //2.10====================================== Voltage L3 ====================================================
  13970. //idx_sample=9;
  13971. // AC 3 phase L3 volatge
  13972. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13973. {
  13974. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13975. {
  13976. tempIndex = 2;
  13977. }
  13978. else
  13979. {
  13980. tempIndex = gun_index;
  13981. }
  13982. for (int index = 0; index < AC_QUANTITY; index++)
  13983. {
  13984. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13985. {
  13986. 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
  13987. }
  13988. } // END OF FOR AC_QUANTITY
  13989. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  13990. }
  13991. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13992. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  13993. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  13994. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  13995. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13996. //====================== Start SoC ================================
  13997. //idx_sample=10;
  13998. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13999. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  14000. {
  14001. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != 'O'))
  14002. {
  14003. tempIndex = ((gun_index==2) ? 1: 0);
  14004. }
  14005. else
  14006. {
  14007. tempIndex = gun_index;
  14008. }
  14009. if(gunType[gun_index] == 'J')
  14010. {
  14011. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14012. {
  14013. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14014. {
  14015. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  14016. }
  14017. }
  14018. }
  14019. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  14020. {
  14021. for (int index = 0; index < CCS_QUANTITY; index++)
  14022. {
  14023. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14024. {
  14025. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  14026. }
  14027. }
  14028. }
  14029. else if(gunType[gun_index] == 'G')
  14030. {
  14031. for (int index = 0; index < GB_QUANTITY; index++)
  14032. {
  14033. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14034. {
  14035. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  14036. }
  14037. }
  14038. }
  14039. else if(gunType[gun_index] == 'O')
  14040. {
  14041. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14042. {
  14043. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14044. {
  14045. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  14046. }
  14047. }
  14048. }
  14049. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  14050. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  14051. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  14052. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  14053. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  14054. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  14055. } // END FOR DC CASE
  14056. //======================================== Message create ==============================================
  14057. json_object *StopTransaction = json_object_new_object();
  14058. json_object *transactionDatas = json_object_new_array();
  14059. json_object *sampledValues = json_object_new_array();
  14060. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  14061. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  14062. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  14063. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  14064. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  14065. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  14066. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  14067. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  14068. {
  14069. json_object *transactionData = json_object_new_object();
  14070. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  14071. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  14072. {
  14073. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  14074. {
  14075. json_object *sampledValue = json_object_new_object();
  14076. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  14077. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  14078. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  14079. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  14080. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  14081. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  14082. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  14083. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  14084. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  14085. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  14086. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  14087. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  14088. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  14089. json_object_array_add(sampledValues, sampledValue);
  14090. }
  14091. }
  14092. json_object_object_add(transactionData, "sampledValue", sampledValues);
  14093. json_object_array_add(transactionDatas, transactionData);
  14094. }
  14095. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  14096. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  14097. ,MESSAGE_TYPE_CALL
  14098. ,guid
  14099. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  14100. json_object_put(StopTransaction);
  14101. // Check File "TempStopTransaction" Exist
  14102. if((access(TempStopTransaction,F_OK))!=-1)
  14103. {
  14104. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  14105. fclose(fopen(TempStopTransaction, "w"));
  14106. }
  14107. else
  14108. {
  14109. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  14110. FILE *log = fopen(TempStopTransaction, "w+");
  14111. if(log == NULL)
  14112. {
  14113. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  14114. return ;
  14115. }
  14116. else
  14117. {
  14118. fclose(log);
  14119. }
  14120. }
  14121. //Add TempStopTransaction | Update TempStopTransaction
  14122. // open file for writing
  14123. FILE *outfile;
  14124. outfile = fopen (TempStopTransaction, "a");
  14125. //DEBUG_INFO("data = %s\n", queuedata);
  14126. fputs(queuedata, outfile);
  14127. fputs("\n", outfile);
  14128. fclose (outfile);
  14129. }
  14130. void checkTempStopTransaction(int gun_index)
  14131. {
  14132. FILE *fptr1;
  14133. char ch;
  14134. char str[QUEUE_MESSAGE_LENGTH]={0};
  14135. char guid[37]={0};
  14136. char tempdata[65]={0};
  14137. char connectorStr[2]={0};
  14138. char TempStopTransaction[256];
  14139. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  14140. fptr1 = fopen(TempStopTransaction, "r");
  14141. //TempStopTransaction格式: 槍號,StopTransaction封包
  14142. if (!fptr1)
  14143. {
  14144. //printf(" File not found or unable to open the input file!!\n");
  14145. return ;
  14146. }
  14147. ch=fgetc(fptr1);
  14148. //printf(" Now the content of the file %s is : \n",fname);
  14149. rewind(fptr1);
  14150. if(ch!=EOF)
  14151. {
  14152. // copy all contents to the temporary file except the specific line
  14153. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  14154. {
  14155. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14156. if(str[0]=='\0')
  14157. {
  14158. break;
  14159. }
  14160. //TempStopTransaction格式: 槍號,StopTransaction封包
  14161. strncpy(connectorStr, str, 1);
  14162. if(atoi(connectorStr) != (gun_index+1))
  14163. {
  14164. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  14165. fclose(fptr1);
  14166. return ;
  14167. }
  14168. //random_uuid(guid);
  14169. strncpy(guid, str+6, 36); //copy guid
  14170. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  14171. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  14172. {
  14173. //DEBUG_INFO("StopTransaction mapitem pass\n");
  14174. }
  14175. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  14176. memset(str,0,ARRAY_SIZE(str));
  14177. }
  14178. }
  14179. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  14180. fclose(fptr1);
  14181. remove(TempStopTransaction); // remove the original file
  14182. }
  14183. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  14184. {
  14185. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  14186. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  14187. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  14188. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  14189. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  14190. }
  14191. int GetWebSocketPingInterval(void)
  14192. {
  14193. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14194. }
  14195. int GetServerSign(void)
  14196. {
  14197. return server_sign;
  14198. }
  14199. uint8_t GetOcppSecurityProfile()
  14200. {
  14201. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14202. }
  14203. void GetOcppChargerBoxId(uint8_t *data)
  14204. {
  14205. sprintf((char*)data, "%s", ShmOCPP16Data->ChargeBoxId);
  14206. }
  14207. void GetOcppSecurityPassword(uint8_t *data)
  14208. {
  14209. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14210. }
  14211. void SetServerSign(int value)
  14212. {
  14213. server_sign = value;
  14214. }
  14215. int GetBootNotificationInterval(void)
  14216. {
  14217. return BootNotificationInterval;
  14218. }
  14219. int GetInternetConn(void)
  14220. {
  14221. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  14222. }
  14223. void InitialSystemValue(void)
  14224. {
  14225. int connectorIndex = 0;
  14226. //int valueASCII = 0;
  14227. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14228. gunTotalNumber=0;
  14229. SystemInitial = 0;
  14230. localversion=0;
  14231. BootNotificationInterval = 0;
  14232. authorizeRetryTimes = 0;
  14233. GunStatusInterval = 10;
  14234. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14235. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14236. //Hear Beat
  14237. HeartBeatWithNOResponse = 0;
  14238. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  14239. FirstHeartBeat = 0;
  14240. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  14241. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  14242. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  14243. memset(statusModeChage, 0, ARRAY_SIZE(statusModeChage));
  14244. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  14245. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  14246. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  14247. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  14248. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  14249. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  14250. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  14251. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  14252. memset(gunType, 0, ARRAY_SIZE(gunType));
  14253. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14254. {
  14255. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O')
  14256. {
  14257. // DO series
  14258. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  14259. {
  14260. SystemInitial = SystemInitial + 1;
  14261. gunTotalNumber = gunTotalNumber + 1;
  14262. gunType[connectorIndex] = 'O';
  14263. connectorIndex = connectorIndex + 1;
  14264. }
  14265. }
  14266. else
  14267. {
  14268. // DM, DW, DS series
  14269. //check connector / socket type (index: 8, 9, 10)
  14270. for(int index=7; index <10 ; index++)
  14271. {
  14272. if(index != 8)
  14273. {
  14274. // DC Connector
  14275. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] >= 'A') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= 'Z'))
  14276. {
  14277. SystemInitial = SystemInitial + 1;
  14278. gunTotalNumber = gunTotalNumber + 1;
  14279. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14280. connectorIndex = connectorIndex + 1;
  14281. }
  14282. }
  14283. else
  14284. {
  14285. // AC Connector
  14286. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14287. {
  14288. SystemInitial = SystemInitial + 1;
  14289. gunTotalNumber = gunTotalNumber + 1;
  14290. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14291. connectorIndex = connectorIndex + 1;
  14292. }
  14293. }
  14294. }
  14295. }
  14296. //DEBUG_INFO("DC ...\n");
  14297. }
  14298. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  14299. {
  14300. //check connector / socket type (index: 8, 9, 10)
  14301. for(int index=7; index <10 ; index++)
  14302. {
  14303. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14304. {
  14305. SystemInitial = SystemInitial + 1;
  14306. gunTotalNumber = gunTotalNumber + 1;
  14307. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14308. connectorIndex = connectorIndex + 1;
  14309. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  14310. }
  14311. }
  14312. }
  14313. //Status && ConnectorPlugIn Setting
  14314. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14315. {
  14316. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  14317. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  14318. }
  14319. for (int index = 0; index < CCS_QUANTITY; index++)
  14320. {
  14321. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  14322. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  14323. }
  14324. for (int index = 0; index < GB_QUANTITY; index++)
  14325. {
  14326. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  14327. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  14328. }
  14329. for (int index = 0; index < AC_QUANTITY; index++)
  14330. {
  14331. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  14332. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  14333. }
  14334. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14335. {
  14336. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  14337. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  14338. }
  14339. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  14340. {
  14341. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  14342. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  14343. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  14344. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  14345. }
  14346. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  14347. clientTime.Heartbeat=time((time_t*)NULL);
  14348. sleep(1);
  14349. }
  14350. void LWS_Send(char * str)
  14351. {
  14352. //=====================================================
  14353. // Check InternetConn 0: disconnected, 1: connected
  14354. //====================================================
  14355. if(GetOcppConnStatus() == 0)
  14356. {
  14357. DEBUG_INFO("offline now !!!\n");
  14358. return;
  14359. }
  14360. pthread_mutex_lock(&lock_send);
  14361. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14362. sprintf((char *)SendBuffer, "%s", str);
  14363. SendBufLen = strlen(str);
  14364. pthread_mutex_unlock(&lock_send);
  14365. lws_callback_on_writable(wsi_client);
  14366. //lws_service(context, 0);
  14367. //sleep(1);
  14368. }
  14369. void LWS_SendNow(char * str)
  14370. {
  14371. //=====================================================
  14372. // Check InternetConn 0: disconnected, 1: connected
  14373. //====================================================
  14374. if(GetOcppConnStatus() == 0)
  14375. {
  14376. DEBUG_INFO("offline now !!!\n");
  14377. return;
  14378. }
  14379. pthread_mutex_lock(&lock_send);
  14380. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14381. sprintf((char *)SendBuffer, "%s", str);
  14382. SendBufLen = strlen(str);
  14383. pthread_mutex_unlock(&lock_send);
  14384. lws_callback_on_writable(wsi_client);
  14385. lws_service(context, 0);
  14386. //sleep(1);
  14387. }