MessageHandler.c 718 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. //ConfigurationMaxKeys
  12. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  13. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  14. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  15. //=================================
  16. // StatusNotification cycle
  17. //=================================
  18. static int server_cycle_Status = 120;
  19. //===============================
  20. // Configuration: unknownkey
  21. //===============================
  22. static char unknownkey[10][20] = {0};
  23. static int UnknownKeynum = 0;
  24. //===============================
  25. // Gun Total Numbers
  26. //===============================
  27. static int gunTotalNumber = 0;
  28. static uint8_t gunType[4] = {0};
  29. //===============================
  30. // Local List Version
  31. //===============================
  32. static int localversion=0;
  33. static char idTagAuthorization[32] = {0};
  34. //===============================
  35. // OCPP sign variable
  36. //===============================
  37. static int server_sign = FALSE;
  38. int server_pending = FALSE;
  39. static int BootNotificationInterval = 0;
  40. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  41. //===============================
  42. // OCPP auth variable
  43. //===============================
  44. static int authorizeRetryTimes = 0; //number of Retry times
  45. //===============================
  46. // OCPP other variables
  47. //===============================
  48. static int HeartBeatWaitTime = 10;
  49. static int FirstHeartBeat = 0;
  50. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  51. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  52. static char CurrentChargingProfileScheduleStr[30] = {0};
  53. //========================================
  54. // OCPP status/previous related variables
  55. //========================================
  56. static int GunStatusInterval = 10;
  57. static uint8_t statusModeChage[CONNECTOR_QUANTITY] = {FALSE};
  58. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  59. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  60. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  61. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  62. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  63. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  64. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  65. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  66. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  67. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  68. static int TransactionMessageAttemptsValue = 0;
  69. static int TransactionMessageRetryIntervalValue = 0;
  70. static int TempMeterValueInterval = 0;
  71. static struct OCPPAuthLocalElemet
  72. {
  73. int listVersionInt;
  74. char idTagstr[20];
  75. char parentIdTag[20];
  76. char expiryDate[30];
  77. char idTagstatus[16];
  78. }idTagQuery;
  79. //=============================================
  80. // OCPP HeartBeat Response Not Receive Counts
  81. //============================================
  82. static int HeartBeatWithNOResponse = 0;
  83. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  84. extern sqlite3 *db;
  85. int TransactionMessageAttemptsGet(void);
  86. int TransactionMessageRetryIntervalGet(void);
  87. int GetOcppConnStatus(void);
  88. void SetOcppConnStatus(uint8_t status);
  89. int setKeyValue(char *key, char *value);
  90. void OCPP_get_TableAuthlocalAllData(void);
  91. void processUnkownKey(void);
  92. struct StructOCPPMeterValue
  93. {
  94. unsigned char TimeStamp[28];
  95. struct StructSampledValue SampledValue[10];
  96. };
  97. struct ClientTime
  98. {
  99. unsigned int Heartbeat;
  100. unsigned int StatusNotification[CONNECTOR_QUANTITY];
  101. unsigned int StartTransaction;
  102. unsigned int StopTransaction;
  103. unsigned int MeterValues[CONNECTOR_QUANTITY];
  104. }clientTime;
  105. typedef union
  106. {
  107. //Operations Initiated by Central System
  108. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  109. struct
  110. {
  111. //CsMsgValue[0]
  112. unsigned char StatusNotificationReq:1; //bit 0,
  113. unsigned char StatusNotificationConf:1; //bit 1,
  114. unsigned char TriggerMeterValue:1; //bit 2,
  115. unsigned char :5; //bit 5~7
  116. }bits[CONNECTOR_QUANTITY];
  117. }CpinitiateMsg;
  118. CpinitiateMsg cpinitateMsg;
  119. //GetConfiguration Array
  120. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  121. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  122. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  123. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  124. #if 0
  125. static char *ChargePointErrorCodeStr[] = {
  126. MACROSTR(ConnectorLockFailure),
  127. MACROSTR(EVCommunicationError),
  128. MACROSTR(GroundFailure),
  129. MACROSTR(HighTemperature),
  130. MACROSTR(InternalError),
  131. MACROSTR(LocalListConflict),
  132. MACROSTR(NoError),
  133. MACROSTR(OtherError),
  134. MACROSTR(OverCurrentFailure),
  135. MACROSTR(OverVoltage),
  136. MACROSTR(PowerMeterFailure),
  137. MACROSTR(PowerSwitchFailure),
  138. MACROSTR(ReaderFailure),
  139. MACROSTR(ResetFailure),
  140. MACROSTR(UnderVoltage),
  141. MACROSTR(WeakSignal)
  142. };
  143. #endif
  144. static char * ChargePointStatusStr[] = {
  145. MACROSTR(Available),
  146. MACROSTR(Preparing),
  147. MACROSTR(Charging),
  148. MACROSTR(SuspendedEVSE),
  149. MACROSTR(SuspendedEV),
  150. MACROSTR(Finishing),
  151. MACROSTR(Reserved),
  152. MACROSTR(Unavailable),
  153. MACROSTR(Faulted)
  154. };
  155. static char *RegistrationStatusStr[] = {
  156. MACROSTR(Accepted),
  157. MACROSTR(Pending),
  158. MACROSTR(Rejected)
  159. };
  160. static char *AvailabilityTypeStr[] = {
  161. MACROSTR(Inoperative),
  162. MACROSTR(Operative)
  163. };
  164. static char *AvailabilityStatusStr[] = {
  165. MACROSTR(Accepted),
  166. MACROSTR(Rejected),
  167. MACROSTR(Scheduled)
  168. };
  169. static char *ConfigurationStatusStr[] = {
  170. MACROSTR(Accepted),
  171. MACROSTR(Rejected),
  172. MACROSTR(RebootRequired),
  173. MACROSTR(NotSupported)
  174. };
  175. static char *ClearCacheStatusStr[] = {
  176. MACROSTR(Accepted),
  177. MACROSTR(Rejected)
  178. };
  179. static char *ChargingProfilePurposeTypeStr[] = {
  180. MACROSTR(ChargePointMaxProfile),
  181. MACROSTR(TxDefaultProfile),
  182. MACROSTR(TxProfile)
  183. };
  184. static char *ChargingProfileStatusStr[] = {
  185. MACROSTR(Accepted),
  186. MACROSTR(Rejected),
  187. MACROSTR(NotSupported)
  188. };
  189. static char *ClearChargingProfileStatusStr[] = {
  190. MACROSTR(Accepted),
  191. MACROSTR(Unknown)
  192. };
  193. static char *GetCompositeScheduleStatusStr[] = {
  194. MACROSTR(Accepted),
  195. MACROSTR(Rejected)
  196. };
  197. static char *UpdateTypeStr[] = {
  198. MACROSTR(Differential),
  199. MACROSTR(Full)
  200. };
  201. static char *UpdateStatusStr[] = {
  202. MACROSTR(Accepted),
  203. MACROSTR(Failed),
  204. MACROSTR(NotSupported),
  205. MACROSTR(VersionMismatch)
  206. };
  207. static char *RemoteStartStopStatusStr[] = {
  208. MACROSTR(Accepted),
  209. MACROSTR(Rejected)
  210. };
  211. static char *ReservationStatusStr[] = {
  212. MACROSTR(Accepted),
  213. MACROSTR(Faulted),
  214. MACROSTR(Occupied),
  215. MACROSTR(Rejected),
  216. MACROSTR(Unavailable)
  217. };
  218. static char *ResetTypeStr[] = {
  219. MACROSTR(Hard),
  220. MACROSTR(Soft)
  221. };
  222. static char *ResetStatusStr[] = {
  223. MACROSTR(Accepted),
  224. MACROSTR(Rejected)
  225. };
  226. static char * DiagnosticsStatusStr[] = {
  227. MACROSTR(Idle),
  228. MACROSTR(Uploaded),
  229. MACROSTR(UploadFailed),
  230. MACROSTR(Uploading)
  231. };
  232. static char * FirmwareStatusStr[] = {
  233. MACROSTR(Downloaded),
  234. MACROSTR(DownloadFailed),
  235. MACROSTR(Downloading),
  236. MACROSTR(Idle),
  237. MACROSTR(InstallationFailed),
  238. MACROSTR(Installing),
  239. MACROSTR(Installed)
  240. };
  241. static char * MessageTriggerStr[] = {
  242. MACROSTR(BootNotification),
  243. MACROSTR(DiagnosticsStatusNotification),
  244. MACROSTR(FirmwareStatusNotification),
  245. MACROSTR(Heartbeat),
  246. MACROSTR(MeterValues),
  247. MACROSTR(StatusNotification)
  248. };
  249. static char * TriggerMessageStatusStr[] = {
  250. MACROSTR(Accepted),
  251. MACROSTR(Rejected),
  252. MACROSTR(NotImplemented)
  253. };
  254. static char * UnlockStatusStr[] = {
  255. MACROSTR(Unlocked),
  256. MACROSTR(UnlockFailed),
  257. MACROSTR(NotSupported)
  258. };
  259. #if 0
  260. static char * StopTransactionReasonStr[] = {
  261. MACROSTR(EmergencyStop),
  262. MACROSTR(EVDisconnected),
  263. MACROSTR(HardReset),
  264. MACROSTR(Local),
  265. MACROSTR(Other),
  266. MACROSTR(PowerLoss),
  267. MACROSTR(Reboot),
  268. MACROSTR(Remote),
  269. MACROSTR(SoftReset),
  270. MACROSTR(UnlockCommand),
  271. MACROSTR(DeAuthorized)
  272. };
  273. #endif
  274. static char * CancelReservationStatusStr[] = {
  275. MACROSTR(Accepted),
  276. MACROSTR(Rejected)
  277. };
  278. static char * ReadingContextStr[] = {
  279. MACROSTR(Interruption.Begin),
  280. MACROSTR(Interruption.End),
  281. MACROSTR(Other),
  282. MACROSTR(Sample.Clock),
  283. MACROSTR(Sample.Periodic),
  284. MACROSTR(Transaction.Begin),
  285. MACROSTR(Transaction.End),
  286. MACROSTR(Trigger)
  287. };
  288. static char * ValueFormatStr[] = {
  289. MACROSTR(Raw),
  290. MACROSTR(SignedData)
  291. };
  292. static char * MeasurandStr[] = {
  293. MACROSTR(Current.Export),
  294. MACROSTR(Current.Import),
  295. MACROSTR(Current.Offered),
  296. MACROSTR(Energy.Active.Export.Register),
  297. MACROSTR(Energy.Active.Import.Register),
  298. MACROSTR(Energy.Reactive.Export.Register),
  299. MACROSTR(Energy.Reactive.Import.Register),
  300. MACROSTR(Energy.Active.Export.Interval),
  301. MACROSTR(Energy.Active.Import.Interval),
  302. MACROSTR(Energy.Reactive.Export.Interval),
  303. MACROSTR(Energy.Reactive.Import.Interval),
  304. MACROSTR(Frequency),
  305. MACROSTR(Power.Active.Export),
  306. MACROSTR(Power.Active.Import),
  307. MACROSTR(Power.Factor),
  308. MACROSTR(Power.Offered),
  309. MACROSTR(Power.Reactive.ExportMACROSTR),
  310. MACROSTR(Power.Reactive.Import),
  311. MACROSTR(RPM),
  312. MACROSTR(SoC),
  313. MACROSTR(Temperature),
  314. MACROSTR(Voltage)
  315. };
  316. static char * LocationStr[] = {
  317. MACROSTR(Body),
  318. MACROSTR(Cable),
  319. MACROSTR(EV),
  320. MACROSTR(Inlet),
  321. MACROSTR(Outlet)
  322. };
  323. static char * PhaseStr[] = {
  324. MACROSTR(L1),
  325. MACROSTR(L2),
  326. MACROSTR(L3),
  327. MACROSTR(N),
  328. MACROSTR(L1-N),
  329. MACROSTR(L2-N),
  330. MACROSTR(L3-N),
  331. MACROSTR(L1-L2),
  332. MACROSTR(L2-L3),
  333. MACROSTR(L3-L1)
  334. };
  335. static char * UnitOfMeasureStr[] = {
  336. MACROSTR(Wh),
  337. MACROSTR(kWh),
  338. MACROSTR(varh),
  339. MACROSTR(kvarh),
  340. MACROSTR(W),
  341. MACROSTR(kW),
  342. MACROSTR(VA),
  343. MACROSTR(kVA),
  344. MACROSTR(var),
  345. MACROSTR(kvar),
  346. MACROSTR(A),
  347. MACROSTR(V),
  348. MACROSTR(Celsius),
  349. MACROSTR(Fahrenheit),
  350. MACROSTR(K),
  351. MACROSTR(Percent)
  352. };
  353. //==========================================
  354. // Check time passed since today
  355. //==========================================
  356. long long DiffTimebWithNow(struct timeb ST)
  357. {
  358. //return milli-second
  359. struct timeb ET;
  360. long long StartTime,StopTime;
  361. ftime(&ET);
  362. StartTime=(long long)ST.time;
  363. StopTime=(long long)ET.time;
  364. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  365. }
  366. int getTimePassSinceToday()
  367. {
  368. int result = -1;
  369. static time_t lastTime;
  370. time_t t;
  371. struct tm *tmStartToday;
  372. struct timeb tbStartToday;
  373. t=time(NULL);
  374. if(difftime(t, lastTime)>0)
  375. {
  376. tmStartToday=localtime(&t);
  377. tmStartToday->tm_hour = 0;
  378. tmStartToday->tm_min = 0;
  379. tmStartToday->tm_sec = 0;
  380. tbStartToday.time = mktime(tmStartToday);
  381. tbStartToday.millitm = 0;
  382. result = DiffTimebWithNow(tbStartToday)/1000;
  383. lastTime = t;
  384. }
  385. return result;
  386. }
  387. void getNowDatetime(uint8_t *data)
  388. {
  389. time_t t = time(NULL);
  390. struct tm tm = *localtime(&t);
  391. sprintf((char*)data, "%04d-%02d-%02dT%02d:%02d:%02dZ", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
  392. }
  393. //==========================================
  394. // GetCompositeSchedule logic related function
  395. //==========================================
  396. int DiffTimebSec(struct timeb ST, struct timeb ET)
  397. {
  398. //return milli-second
  399. unsigned int StartTime,StopTime;
  400. StartTime=(unsigned int)ST.time;
  401. StopTime=(unsigned int)ET.time;
  402. return (StopTime-StartTime);
  403. }
  404. int DiffTimebWithNowSec(struct timeb ST)
  405. {
  406. //return milli-second
  407. struct timeb ET;
  408. unsigned int StartTime,StopTime;
  409. ftime(&ET);
  410. StartTime=(unsigned int)ST.time;
  411. StopTime=(unsigned int)ET.time;
  412. return (StopTime-StartTime);
  413. }
  414. int getStartStop(uint8_t *start, uint8_t *stop)
  415. {
  416. int result = -1;
  417. struct tm tmStart;
  418. struct timeb tbStart;
  419. struct tm tmStop;
  420. struct timeb tbStop;
  421. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  422. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  423. {
  424. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  425. //DEBUG_INFO("Stop: %d-%d-%d %d:%d:%d\n", tmStop.tm_year, tmStop.tm_mon, tmStop.tm_mday, tmStop.tm_hour, tmStop.tm_min, tmStop.tm_sec);
  426. tmStart.tm_year -= 1900;
  427. tmStart.tm_mon -= 1;
  428. tbStart.time = mktime(&tmStart);
  429. tbStart.millitm = 0;
  430. tmStop.tm_year -= 1900;
  431. tmStop.tm_mon -= 1;
  432. tbStop.time = mktime(&tmStop);
  433. tbStop.millitm = 0;
  434. result = DiffTimebSec(tbStart, tbStop);
  435. //DEBUG_INFO("getStartStop(): %d\n", result);
  436. }
  437. else
  438. {
  439. DEBUG_WARN("Start or stop date parsing error.\r\n");
  440. }
  441. return result;
  442. }
  443. int isOvertNow(uint8_t *start)
  444. {
  445. int result = NO;
  446. struct tm tmStart;
  447. struct timeb tbStart;
  448. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6))
  449. {
  450. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  451. tmStart.tm_year -= 1900;
  452. tmStart.tm_mon -= 1;
  453. tbStart.time = mktime(&tmStart);
  454. tbStart.millitm = 0;
  455. if(DiffTimebWithNowSec(tbStart) <= 0)
  456. result = NO;
  457. else
  458. result = YES;
  459. }
  460. else
  461. {
  462. DEBUG_WARN("Start date parsing error.\n");
  463. }
  464. return result;
  465. }
  466. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  467. {
  468. int result = -1;
  469. struct tm tmStart;
  470. struct timeb tbStart;
  471. struct tm tmStop;
  472. struct timeb tbStop;
  473. 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) &&
  474. (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))
  475. {
  476. tmStart.tm_year -= 1900;
  477. tmStart.tm_mon -= 1;
  478. tbStart.time = mktime(&tmStart);
  479. tbStart.millitm = 0;
  480. tmStop.tm_year -= 1900;
  481. tmStop.tm_mon -= 1;
  482. tbStop.time = mktime(&tmStop);
  483. tbStop.millitm = 0;
  484. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  485. }
  486. return result;
  487. }
  488. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  489. {
  490. FILE *fp;
  491. char profileFileName[128];
  492. char *line = NULL;
  493. size_t len = 0;
  494. time_t CurrentTime;
  495. struct tm *tmComposite;
  496. struct StructChargingProfile maxProfile;
  497. struct StructChargingProfile defaultTxProfile;
  498. struct StructChargingProfile txProfile;
  499. struct StructChargingSchedulePeriod tmpPeriod;
  500. uint8_t limitMax=0;
  501. uint8_t limitDef=0;
  502. uint8_t limitTx=0;
  503. int compositePeriodIdx = 0;
  504. CurrentTime = time(NULL);
  505. tmComposite=localtime(&CurrentTime);
  506. 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);
  507. if(isUnitA)
  508. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  509. else
  510. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  511. compositeProfile->ChargingSchedule.Duration = durationReq;
  512. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  513. {
  514. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  515. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  516. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  517. }
  518. compositeProfile->ChargingProfileId = 0;
  519. compositeProfile->StackLevel = 99 ;
  520. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  521. maxProfile.ChargingProfileId = -1;
  522. defaultTxProfile.ChargingProfileId = -1;
  523. txProfile.ChargingProfileId = -1;
  524. maxProfile.ChargingSchedule.Duration = -1;
  525. defaultTxProfile.ChargingSchedule.Duration = -1;
  526. txProfile.ChargingSchedule.Duration = -1;
  527. system("yes|rm /tmp/*.json");
  528. system("cp /Storage/OCPP/*.json /tmp");
  529. /*
  530. * Search valid charging profile
  531. */
  532. //DEBUG_INFO("====================================\n");
  533. // Search tx profile
  534. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  535. if((access(profileFileName, F_OK))!=-1)
  536. {
  537. fp = fopen(profileFileName, "r");
  538. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  539. {
  540. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  541. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  542. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  543. }
  544. txProfile.ChargingProfileId = -1;
  545. txProfile.StackLevel = -1;
  546. while(getline(&line, &len, fp) != -1)
  547. {
  548. json_object *obj = NULL;
  549. obj = json_tokener_parse(line);
  550. if(is_error(obj))
  551. {
  552. DEBUG_ERROR("Parse txProfile from file error.\n");
  553. }
  554. else
  555. {
  556. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  557. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  558. )
  559. {
  560. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  561. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  562. )
  563. {
  564. struct tm tmFrom, tmTo;
  565. struct timeb tbFrom, tbTo;
  566. 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) &&
  567. (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))
  568. {
  569. tmFrom.tm_year -= 1900;
  570. tmFrom.tm_mon -= 1;
  571. tbFrom.time = mktime(&tmFrom);
  572. tmTo.tm_year -= 1900;
  573. tmTo.tm_mon -= 1;
  574. tbTo.time = mktime(&tmTo);
  575. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  576. {
  577. if(txProfile.ChargingProfileId == -1)
  578. DEBUG_INFO("TxProfile found.\n");
  579. else
  580. DEBUG_INFO("TxProfile updated.\n");
  581. // Required item
  582. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  583. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  584. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  585. if(isUnitA)
  586. {
  587. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  588. 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++)
  589. {
  590. 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"));
  591. 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?
  592. 3:
  593. 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")));
  594. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  595. }
  596. }
  597. else
  598. {
  599. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  600. 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++)
  601. {
  602. 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"));
  603. 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?
  604. 3:
  605. 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")));
  606. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  607. }
  608. }
  609. // Optional item
  610. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  611. {
  612. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  613. }
  614. else
  615. {
  616. sprintf((char*)txProfile.ValidFrom, " ");
  617. }
  618. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  619. {
  620. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  621. }
  622. else
  623. {
  624. sprintf((char*)txProfile.ValidTo, " ");
  625. }
  626. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  627. {
  628. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  629. }
  630. else
  631. {
  632. sprintf((char*)txProfile.RecurrencyKind, " ");
  633. }
  634. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  635. {
  636. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  637. }
  638. else
  639. {
  640. txProfile.TransactionId = -1;
  641. }
  642. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  643. {
  644. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  645. }
  646. else
  647. {
  648. txProfile.ChargingSchedule.Duration = 86400;
  649. }
  650. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  651. {
  652. 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")));
  653. }
  654. else
  655. {
  656. 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));
  657. }
  658. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  659. {
  660. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  661. }
  662. else
  663. {
  664. txProfile.ChargingSchedule.MinChargingRate = -1;
  665. }
  666. }
  667. }
  668. }
  669. else
  670. {
  671. if(txProfile.ChargingProfileId == -1)
  672. DEBUG_INFO("TxProfile found.\n");
  673. else
  674. DEBUG_INFO("TxProfile updated.\n");
  675. // Required item
  676. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  677. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  678. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  679. if(isUnitA)
  680. {
  681. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  682. 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++)
  683. {
  684. 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"));
  685. 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?
  686. 3:
  687. 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")));
  688. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  689. }
  690. }
  691. else
  692. {
  693. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  694. 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++)
  695. {
  696. 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"));
  697. 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?
  698. 3:
  699. 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")));
  700. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  701. }
  702. }
  703. // Optional item
  704. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  705. {
  706. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  707. }
  708. else
  709. {
  710. sprintf((char*)txProfile.ValidFrom, " ");
  711. }
  712. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  713. {
  714. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  715. }
  716. else
  717. {
  718. sprintf((char*)txProfile.ValidTo, " ");
  719. }
  720. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  721. {
  722. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  723. }
  724. else
  725. {
  726. sprintf((char*)txProfile.RecurrencyKind, " ");
  727. }
  728. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  729. {
  730. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  731. }
  732. else
  733. {
  734. txProfile.TransactionId = -1;
  735. }
  736. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  737. {
  738. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  739. }
  740. else
  741. {
  742. txProfile.ChargingSchedule.Duration = 86400;
  743. }
  744. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  745. {
  746. 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")));
  747. }
  748. else
  749. {
  750. 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));
  751. }
  752. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  753. {
  754. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  755. }
  756. else
  757. {
  758. txProfile.ChargingSchedule.MinChargingRate = -1;
  759. }
  760. }
  761. }
  762. }
  763. json_object_put(obj);
  764. }
  765. fclose(fp);
  766. /*
  767. if(txProfile.ChargingProfileId != -1)
  768. {
  769. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  770. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  771. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  772. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  773. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  774. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  775. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  776. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  777. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  778. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  779. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  780. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  781. {
  782. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  783. {
  784. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  785. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  786. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  787. }
  788. }
  789. }
  790. else
  791. DEBUG_INFO("TxProfile not found.\n");*/
  792. }
  793. // Search default tx profile
  794. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  795. if((access(profileFileName, F_OK))==-1)
  796. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  797. if((access(profileFileName, F_OK))!=-1)
  798. {
  799. fp = fopen(profileFileName, "r");
  800. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  801. {
  802. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  803. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  804. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  805. }
  806. defaultTxProfile.ChargingProfileId = -1;
  807. defaultTxProfile.StackLevel = -1;
  808. while(getline(&line, &len, fp) != -1)
  809. {
  810. json_object *obj = NULL;
  811. obj = json_tokener_parse(line);
  812. if(is_error(obj))
  813. {
  814. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  815. }
  816. else
  817. {
  818. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  819. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  820. )
  821. {
  822. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  823. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  824. )
  825. {
  826. struct tm tmFrom, tmTo;
  827. struct timeb tbFrom, tbTo;
  828. 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) &&
  829. (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))
  830. {
  831. tmFrom.tm_year -= 1900;
  832. tmFrom.tm_mon -= 1;
  833. tbFrom.time = mktime(&tmFrom);
  834. tmTo.tm_year -= 1900;
  835. tmTo.tm_mon -= 1;
  836. tbTo.time = mktime(&tmTo);
  837. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  838. {
  839. if(defaultTxProfile.ChargingProfileId == -1)
  840. DEBUG_INFO("TxDefaultProfile found.\n");
  841. else
  842. DEBUG_INFO("TxDefaultProfile updated.\n");
  843. // Required item
  844. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  845. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  846. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  847. if(isUnitA)
  848. {
  849. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  850. 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++)
  851. {
  852. 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"));
  853. 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?
  854. 3:
  855. 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")));
  856. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  857. }
  858. }
  859. else
  860. {
  861. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  862. 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++)
  863. {
  864. 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"));
  865. 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?
  866. 3:
  867. 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")));
  868. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  869. }
  870. }
  871. // Optional item
  872. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  873. {
  874. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  875. }
  876. else
  877. {
  878. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  879. }
  880. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  881. {
  882. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  883. }
  884. else
  885. {
  886. sprintf((char*)defaultTxProfile.ValidTo, " ");
  887. }
  888. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  889. {
  890. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  891. }
  892. else
  893. {
  894. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  895. }
  896. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  897. {
  898. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  899. }
  900. else
  901. {
  902. defaultTxProfile.TransactionId = -1;
  903. }
  904. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  905. {
  906. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  907. }
  908. else
  909. {
  910. defaultTxProfile.ChargingSchedule.Duration = 86400;
  911. }
  912. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  913. {
  914. 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")));
  915. }
  916. else
  917. {
  918. 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));
  919. }
  920. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  921. {
  922. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  923. }
  924. else
  925. {
  926. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  927. }
  928. }
  929. }
  930. }
  931. else
  932. {
  933. if(defaultTxProfile.ChargingProfileId == -1)
  934. DEBUG_INFO("TxDefaultProfile found.\n");
  935. else
  936. DEBUG_INFO("TxDefaultProfile updated.\n");
  937. // Required item
  938. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  939. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  940. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  941. if(isUnitA)
  942. {
  943. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  944. 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++)
  945. {
  946. 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"));
  947. 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?
  948. 3:
  949. 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")));
  950. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  951. }
  952. }
  953. else
  954. {
  955. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  956. 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++)
  957. {
  958. 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"));
  959. 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?
  960. 3:
  961. 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")));
  962. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  963. }
  964. }
  965. // Optional item
  966. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  967. {
  968. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  969. }
  970. else
  971. {
  972. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  973. }
  974. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  975. {
  976. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  977. }
  978. else
  979. {
  980. sprintf((char*)defaultTxProfile.ValidTo, " ");
  981. }
  982. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  983. {
  984. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  985. }
  986. else
  987. {
  988. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  989. }
  990. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  991. {
  992. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  993. }
  994. else
  995. {
  996. defaultTxProfile.TransactionId = -1;
  997. }
  998. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  999. {
  1000. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1001. }
  1002. else
  1003. {
  1004. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1005. }
  1006. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1007. {
  1008. 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")));
  1009. }
  1010. else
  1011. {
  1012. 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));
  1013. }
  1014. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1015. {
  1016. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1017. }
  1018. else
  1019. {
  1020. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1021. }
  1022. }
  1023. }
  1024. }
  1025. json_object_put(obj);
  1026. }
  1027. fclose(fp);
  1028. /*
  1029. if(defaultTxProfile.ChargingProfileId != -1)
  1030. {
  1031. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1032. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1033. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1034. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1035. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1036. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1037. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1038. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  1039. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1040. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1041. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1042. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1043. {
  1044. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1045. {
  1046. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1047. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1048. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1049. }
  1050. }
  1051. }
  1052. else
  1053. DEBUG_INFO("TxDefaultProfile not found.\n");
  1054. DEBUG_INFO("------------------------------------\n");*/
  1055. }
  1056. // Search max profile
  1057. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1058. if((access(profileFileName, F_OK))!=-1)
  1059. {
  1060. fp = fopen(profileFileName, "r");
  1061. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1062. {
  1063. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1064. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1065. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1066. }
  1067. maxProfile.ChargingProfileId = -1;
  1068. maxProfile.StackLevel = -1;
  1069. while(getline(&line, &len, fp) != -1)
  1070. {
  1071. json_object *obj = NULL;
  1072. obj = json_tokener_parse(line);
  1073. if(is_error(obj))
  1074. {
  1075. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1076. }
  1077. else
  1078. {
  1079. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  1080. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1081. )
  1082. {
  1083. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1084. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1085. )
  1086. {
  1087. struct tm tmFrom, tmTo;
  1088. struct timeb tbFrom, tbTo;
  1089. 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) &&
  1090. (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))
  1091. {
  1092. tmFrom.tm_year -= 1900;
  1093. tmFrom.tm_mon -= 1;
  1094. tbFrom.time = mktime(&tmFrom);
  1095. tmTo.tm_year -= 1900;
  1096. tmTo.tm_mon -= 1;
  1097. tbTo.time = mktime(&tmTo);
  1098. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1099. {
  1100. if(maxProfile.ChargingProfileId == -1)
  1101. DEBUG_INFO("MaxProfile found.\n");
  1102. else
  1103. DEBUG_INFO("MaxProfile updated.\n");
  1104. // Required item
  1105. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1106. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1107. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1108. if(isUnitA)
  1109. {
  1110. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1111. 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++)
  1112. {
  1113. 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"));
  1114. 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?
  1115. 3:
  1116. 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")));
  1117. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1118. }
  1119. }
  1120. else
  1121. {
  1122. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1123. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1124. {
  1125. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1126. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].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?
  1127. 3:
  1128. 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")));
  1129. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1130. }
  1131. }
  1132. // Optional item
  1133. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1134. {
  1135. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1136. }
  1137. else
  1138. {
  1139. sprintf((char*)maxProfile.ValidFrom, " ");
  1140. }
  1141. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1142. {
  1143. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1144. }
  1145. else
  1146. {
  1147. sprintf((char*)maxProfile.ValidTo, " ");
  1148. }
  1149. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1150. {
  1151. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1152. }
  1153. else
  1154. {
  1155. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1156. }
  1157. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1158. {
  1159. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1160. }
  1161. else
  1162. {
  1163. maxProfile.TransactionId = -1;
  1164. }
  1165. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1166. {
  1167. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1168. }
  1169. else
  1170. {
  1171. maxProfile.ChargingSchedule.Duration = 86400;
  1172. }
  1173. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1174. {
  1175. 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")));
  1176. }
  1177. else
  1178. {
  1179. 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));
  1180. }
  1181. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1182. {
  1183. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1184. }
  1185. else
  1186. {
  1187. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1188. }
  1189. }
  1190. }
  1191. }
  1192. else
  1193. {
  1194. if(maxProfile.ChargingProfileId == -1)
  1195. DEBUG_INFO("MaxProfile found.\n");
  1196. else
  1197. DEBUG_INFO("MaxProfile updated.\n");
  1198. // Required item
  1199. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1200. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1201. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1202. if(isUnitA)
  1203. {
  1204. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1205. 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++)
  1206. {
  1207. 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"));
  1208. 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?
  1209. 3:
  1210. 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")));
  1211. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1212. }
  1213. }
  1214. else
  1215. {
  1216. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1217. 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++)
  1218. {
  1219. 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"));
  1220. 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?
  1221. 3:
  1222. 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")));
  1223. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1224. }
  1225. }
  1226. // Optional item
  1227. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1228. {
  1229. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1230. }
  1231. else
  1232. {
  1233. sprintf((char*)maxProfile.ValidFrom, " ");
  1234. }
  1235. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1236. {
  1237. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1238. }
  1239. else
  1240. {
  1241. sprintf((char*)maxProfile.ValidTo, " ");
  1242. }
  1243. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1244. {
  1245. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1246. }
  1247. else
  1248. {
  1249. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1250. }
  1251. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1252. {
  1253. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1254. }
  1255. else
  1256. {
  1257. maxProfile.TransactionId = -1;
  1258. }
  1259. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1260. {
  1261. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1262. }
  1263. else
  1264. {
  1265. maxProfile.ChargingSchedule.Duration = 86400;
  1266. }
  1267. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1268. {
  1269. 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")));
  1270. }
  1271. else
  1272. {
  1273. 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));
  1274. }
  1275. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1276. {
  1277. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1278. }
  1279. else
  1280. {
  1281. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1282. }
  1283. }
  1284. }
  1285. }
  1286. json_object_put(obj);
  1287. }
  1288. fclose(fp);
  1289. /*
  1290. if(maxProfile.ChargingProfileId !=-1)
  1291. {
  1292. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1293. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1294. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1295. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1296. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1297. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1298. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1299. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1300. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1301. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1302. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1303. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1304. {
  1305. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1306. {
  1307. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1308. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1309. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1310. }
  1311. }
  1312. }
  1313. else
  1314. DEBUG_INFO("MaxProfile not found.\n");
  1315. DEBUG_INFO("------------------------------------\n");*/
  1316. }
  1317. /*
  1318. * Align found profile start schedule & periods
  1319. */
  1320. //DEBUG_INFO("====================================\n");
  1321. /*
  1322. // For local test usage, force modify found profile start schedule info
  1323. 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);
  1324. 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);
  1325. 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);
  1326. */
  1327. if(txProfile.ChargingProfileId != -1)
  1328. {
  1329. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  1330. {
  1331. if(txProfile.ChargingSchedule.Duration != -1)
  1332. {
  1333. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1334. 0:
  1335. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1336. }
  1337. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1338. {
  1339. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1340. {
  1341. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1342. 0:
  1343. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1344. if(idxPeriod > 0)
  1345. {
  1346. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1347. {
  1348. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1349. }
  1350. }
  1351. }
  1352. }
  1353. }
  1354. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  1355. {
  1356. if(txProfile.ChargingSchedule.Duration != -1)
  1357. {
  1358. 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?
  1359. 0:
  1360. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1361. }
  1362. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1363. {
  1364. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1365. {
  1366. 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?
  1367. 0:
  1368. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1369. if(idxPeriod > 0)
  1370. {
  1371. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1372. {
  1373. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1374. }
  1375. }
  1376. }
  1377. }
  1378. }
  1379. else
  1380. {
  1381. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  1382. {
  1383. if(txProfile.ChargingSchedule.Duration != -1)
  1384. {
  1385. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1386. 0:
  1387. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1388. }
  1389. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1390. {
  1391. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1392. {
  1393. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1394. 0:
  1395. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1396. if(idxPeriod > 0)
  1397. {
  1398. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1399. {
  1400. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1401. }
  1402. }
  1403. }
  1404. }
  1405. }
  1406. else
  1407. {
  1408. if(txProfile.ChargingSchedule.Duration != -1)
  1409. {
  1410. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1411. 0:
  1412. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1413. }
  1414. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1415. {
  1416. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1417. {
  1418. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1419. 0:
  1420. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1421. if(idxPeriod > 0)
  1422. {
  1423. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1424. {
  1425. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1426. }
  1427. }
  1428. }
  1429. }
  1430. }
  1431. }
  1432. /*
  1433. DEBUG_INFO("txProfile after align.\n");
  1434. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1435. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1436. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1437. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1438. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1439. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1440. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1441. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1442. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1443. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1444. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1445. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1446. {
  1447. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1448. {
  1449. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1450. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1451. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1452. }
  1453. }*/
  1454. }
  1455. if(defaultTxProfile.ChargingProfileId != -1)
  1456. {
  1457. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  1458. {
  1459. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1460. {
  1461. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1462. 0:
  1463. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1464. }
  1465. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1466. {
  1467. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1468. {
  1469. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1470. 0:
  1471. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1472. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1473. {
  1474. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1475. }
  1476. if(idxPeriod > 0)
  1477. {
  1478. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1479. {
  1480. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1481. }
  1482. }
  1483. }
  1484. }
  1485. }
  1486. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  1487. {
  1488. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1489. {
  1490. 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?
  1491. 0:
  1492. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1493. }
  1494. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1495. {
  1496. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1497. {
  1498. 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?
  1499. 0:
  1500. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1501. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1502. {
  1503. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1504. }
  1505. if(idxPeriod > 0)
  1506. {
  1507. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1508. {
  1509. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1510. }
  1511. }
  1512. }
  1513. }
  1514. }
  1515. else
  1516. {
  1517. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  1518. {
  1519. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1520. {
  1521. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1522. 0:
  1523. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1524. }
  1525. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1526. {
  1527. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1528. {
  1529. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1530. 0:
  1531. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1532. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1533. {
  1534. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1535. }
  1536. if(idxPeriod > 0)
  1537. {
  1538. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1539. {
  1540. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1541. }
  1542. }
  1543. }
  1544. }
  1545. }
  1546. else
  1547. {
  1548. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1549. {
  1550. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1551. 0:
  1552. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1553. }
  1554. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1555. {
  1556. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1557. {
  1558. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1559. 0:
  1560. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1561. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1562. {
  1563. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1564. }
  1565. if(idxPeriod > 0)
  1566. {
  1567. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1568. {
  1569. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1570. }
  1571. }
  1572. }
  1573. }
  1574. }
  1575. }
  1576. /*
  1577. DEBUG_INFO("defaultTxProfile after align.\n");
  1578. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1579. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1580. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1581. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1582. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1583. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1584. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1585. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1586. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1587. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1588. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1589. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1590. {
  1591. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1592. {
  1593. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1594. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1595. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1596. }
  1597. }
  1598. DEBUG_INFO("------------------------------------\n");*/
  1599. }
  1600. if(maxProfile.ChargingProfileId != -1)
  1601. {
  1602. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1603. {
  1604. if(maxProfile.ChargingSchedule.Duration != -1)
  1605. {
  1606. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1607. 0:
  1608. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1609. }
  1610. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1611. {
  1612. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1613. {
  1614. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1615. 0:
  1616. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1617. if(idxPeriod > 0)
  1618. {
  1619. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1620. {
  1621. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1622. }
  1623. }
  1624. }
  1625. }
  1626. }
  1627. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1628. {
  1629. if(maxProfile.ChargingSchedule.Duration != -1)
  1630. {
  1631. 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?
  1632. 0:
  1633. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1634. }
  1635. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1636. {
  1637. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1638. {
  1639. 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?
  1640. 0:
  1641. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1642. if(idxPeriod > 0)
  1643. {
  1644. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1645. {
  1646. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1647. }
  1648. }
  1649. }
  1650. }
  1651. }
  1652. else
  1653. {
  1654. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1655. {
  1656. if(maxProfile.ChargingSchedule.Duration != -1)
  1657. {
  1658. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1659. 0:
  1660. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1661. }
  1662. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1663. {
  1664. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1665. {
  1666. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1667. 0:
  1668. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1669. if(idxPeriod > 0)
  1670. {
  1671. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1672. {
  1673. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1674. }
  1675. }
  1676. }
  1677. }
  1678. }
  1679. else
  1680. {
  1681. if(maxProfile.ChargingSchedule.Duration != -1)
  1682. {
  1683. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1684. 0:
  1685. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1686. }
  1687. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1688. {
  1689. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1690. {
  1691. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1692. 0:
  1693. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1694. if(idxPeriod > 0)
  1695. {
  1696. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1697. {
  1698. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1699. }
  1700. }
  1701. }
  1702. }
  1703. }
  1704. }
  1705. /*
  1706. DEBUG_INFO("MaxProfile after align.\n");
  1707. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1708. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1709. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1710. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1711. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1712. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1713. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1714. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1715. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1716. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1717. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1718. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1719. {
  1720. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1721. {
  1722. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1723. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1724. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1725. }
  1726. }
  1727. DEBUG_INFO("------------------------------------\n");*/
  1728. }
  1729. /*
  1730. * Merge to conposite schedule
  1731. */
  1732. //DEBUG_INFO("====================================\n");
  1733. // Find each profile period quantity
  1734. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1735. {
  1736. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1737. limitMax = idx+1;
  1738. }
  1739. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1740. {
  1741. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1742. limitDef = idx+1;
  1743. }
  1744. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1745. {
  1746. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1747. limitTx = idx+1;
  1748. }
  1749. // TxProfile found, composite schedule based on it
  1750. if(txProfile.ChargingProfileId != -1)
  1751. {
  1752. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  1753. {
  1754. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  1755. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  1756. (txProfile.ChargingSchedule.Duration > 0))
  1757. {
  1758. if(maxProfile.ChargingProfileId != -1)
  1759. {
  1760. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1761. {
  1762. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  1763. {
  1764. if((maxProfile.ChargingSchedule.Duration > 0))
  1765. {
  1766. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1767. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1768. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1769. }
  1770. else
  1771. {
  1772. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1773. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1774. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  1775. }
  1776. }
  1777. if(idxMaxPeriod == (limitMax-1))
  1778. {
  1779. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1780. {
  1781. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1782. {
  1783. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1784. compositePeriodIdx++;
  1785. }
  1786. else
  1787. {
  1788. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1789. }
  1790. }
  1791. }
  1792. }
  1793. }
  1794. else
  1795. {
  1796. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1797. {
  1798. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1799. compositePeriodIdx++;
  1800. }
  1801. else
  1802. {
  1803. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1804. }
  1805. }
  1806. }
  1807. if(idxTxPeriod == (limitTx-1))
  1808. {
  1809. if(defaultTxProfile.ChargingProfileId != -1)
  1810. {
  1811. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1812. {
  1813. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  1814. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  1815. (defaultTxProfile.ChargingSchedule.Duration>0))
  1816. {
  1817. if(maxProfile.ChargingProfileId != -1)
  1818. {
  1819. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1820. {
  1821. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1822. {
  1823. if((maxProfile.ChargingSchedule.Duration > 0))
  1824. {
  1825. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1826. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1827. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1828. }
  1829. else
  1830. {
  1831. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1832. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1833. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  1834. }
  1835. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1836. {
  1837. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1838. {
  1839. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1840. compositePeriodIdx++;
  1841. }
  1842. else
  1843. {
  1844. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1845. }
  1846. }
  1847. break;
  1848. }
  1849. }
  1850. }
  1851. else
  1852. {
  1853. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1854. {
  1855. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1856. compositePeriodIdx++;
  1857. }
  1858. else
  1859. {
  1860. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1861. }
  1862. }
  1863. }
  1864. }
  1865. }
  1866. }
  1867. }
  1868. }
  1869. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  1870. else if(defaultTxProfile.ChargingProfileId != -1)
  1871. {
  1872. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1873. {
  1874. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  1875. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  1876. (defaultTxProfile.ChargingSchedule.Duration > 0))
  1877. {
  1878. if(maxProfile.ChargingProfileId != -1)
  1879. {
  1880. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1881. {
  1882. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1883. {
  1884. if((maxProfile.ChargingSchedule.Duration > 0))
  1885. {
  1886. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1887. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1888. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  1889. }
  1890. else
  1891. {
  1892. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1893. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1894. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  1895. }
  1896. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1897. {
  1898. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1899. {
  1900. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1901. compositePeriodIdx++;
  1902. }
  1903. else
  1904. {
  1905. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1906. }
  1907. }
  1908. break;
  1909. }
  1910. }
  1911. }
  1912. else
  1913. {
  1914. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1915. {
  1916. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1917. compositePeriodIdx++;
  1918. }
  1919. else
  1920. {
  1921. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1922. }
  1923. }
  1924. }
  1925. }
  1926. }
  1927. // Fill other period by MaxProfile
  1928. if(maxProfile.ChargingProfileId != -1)
  1929. {
  1930. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1931. {
  1932. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1933. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1934. (maxProfile.ChargingSchedule.Duration > 0))
  1935. {
  1936. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  1937. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  1938. {
  1939. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  1940. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  1941. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1942. }
  1943. if((maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  1944. {
  1945. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.Duration;
  1946. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  1947. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1948. }
  1949. if(tmpPeriod.Limit != -1)
  1950. {
  1951. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1952. {
  1953. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1954. {
  1955. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1956. compositePeriodIdx++;
  1957. }
  1958. else
  1959. {
  1960. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1961. }
  1962. }
  1963. }
  1964. }
  1965. }
  1966. }
  1967. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  1968. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1969. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1970. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1971. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1972. {
  1973. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1974. {
  1975. compositeProfile->ChargingProfileId = 1;
  1976. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1977. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1978. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1979. }
  1980. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1981. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1982. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1983. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1984. }
  1985. if(line)
  1986. free(line);
  1987. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  1988. }
  1989. //==========================================
  1990. // Init all share memory
  1991. //==========================================
  1992. int InitShareMemory()
  1993. {
  1994. int result = PASS;
  1995. int MeterSMId;
  1996. //creat ShmSysConfigAndInfo
  1997. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  1998. {
  1999. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  2000. result = FAIL;
  2001. }
  2002. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2003. {
  2004. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  2005. result = FAIL;
  2006. }
  2007. else
  2008. {}
  2009. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  2010. {
  2011. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  2012. result = FAIL;
  2013. }
  2014. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2015. {
  2016. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  2017. result = FAIL;
  2018. }
  2019. else
  2020. {}
  2021. //creat ShmPsuData
  2022. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  2023. {
  2024. DEBUG_ERROR("shmget ShmPsuData NG\n");
  2025. result = FAIL;
  2026. }
  2027. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2028. {
  2029. DEBUG_ERROR("shmat ShmPsuData NG\n");
  2030. result = FAIL;
  2031. }
  2032. else
  2033. {}
  2034. //creat ShmOCPP16Data
  2035. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  2036. {
  2037. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  2038. result = FAIL;
  2039. }
  2040. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2041. {
  2042. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  2043. result = FAIL;
  2044. }
  2045. else
  2046. {}
  2047. /****************************** For Initial Settings************************************************/
  2048. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  2049. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  2050. // allocate Configuration memory address
  2051. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  2052. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  2053. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  2054. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  2055. //offline MeterValue Interval
  2056. TempMeterValueInterval = 0;
  2057. return result;
  2058. }
  2059. int ProcessShareMemory()
  2060. {
  2061. if(InitShareMemory() == FAIL)
  2062. {
  2063. DEBUG_ERROR("InitShareMemory NG\n");
  2064. if(ShmStatusCodeData!=NULL)
  2065. {
  2066. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  2067. }
  2068. sleep(5);
  2069. return FAIL;
  2070. }
  2071. return PASS;
  2072. }
  2073. //---------------------common routine---------------------------//
  2074. //---------------------------------------------
  2075. // new:
  2076. // enum SYSTEM_STATUS
  2077. // {
  2078. // SYS_MODE_BOOTING = 0,
  2079. // SYS_MODE_IDLE = 1,
  2080. // SYS_MODE_AUTHORIZING = 2,
  2081. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  2082. // SYS_MODE_REASSIGN = 4,
  2083. // SYS_MODE_PREPARING = 5,
  2084. // SYS_MODE_PREPARE_FOR_EV = 6,
  2085. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  2086. // SYS_MODE_CHARGING = 8,
  2087. // SYS_MODE_TERMINATING = 9,
  2088. // SYS_MODE_COMPLETE = 10,
  2089. // SYS_MODE_ALARM = 11,
  2090. // SYS_MODE_FAULT = 12,
  2091. // SYS_MODE_RESERVATION = 13,
  2092. // SYS_MODE_BOOKING = 14,
  2093. // SYS_MODE_MAINTAIN = 15,
  2094. // SYS_MODE_DEBUG = 16,
  2095. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  2096. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  2097. // SYS_MODE_UPDATE = 19
  2098. // };
  2099. //
  2100. //
  2101. //-----------------------------------------
  2102. void CheckSystemValue(void)
  2103. {
  2104. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  2105. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  2106. char filenmae[100]={0};
  2107. char str[100]={0};
  2108. int tempIndex = 0;
  2109. //===============================
  2110. // send Heartbeat
  2111. //===============================
  2112. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2113. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  2114. {
  2115. clientTime.Heartbeat=time((time_t*)NULL);
  2116. if(server_sign == TRUE)
  2117. {
  2118. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2119. }
  2120. else
  2121. {
  2122. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  2123. }
  2124. }
  2125. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  2126. {
  2127. //parameter for test
  2128. sendHeartbeatRequest(0);
  2129. //==============================================
  2130. // Reset Waiting Time
  2131. //==============================================
  2132. HeartBeatWithNOResponse += 1;
  2133. }
  2134. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  2135. {
  2136. //==========================================
  2137. // csu trigger DataTransferReq
  2138. //==========================================
  2139. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  2140. {
  2141. sendDataTransferRequest(gun_index);
  2142. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  2143. }
  2144. //===============================
  2145. // CSU Trigger Reset Conf
  2146. //===============================
  2147. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  2148. {
  2149. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  2150. }
  2151. //===============================
  2152. // CSU Trigger Authorize Request
  2153. //===============================
  2154. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  2155. {
  2156. sendAuthorizeRequest(0);
  2157. authorizeRetryTimes = authorizeRetryTimes + 1;
  2158. if(authorizeRetryTimes < 3)
  2159. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2160. }
  2161. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  2162. {
  2163. authorizeRetryTimes = 0;
  2164. SetOcppConnStatus(FALSE);
  2165. server_sign = FALSE;
  2166. }
  2167. 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))
  2168. {
  2169. sendAuthorizeRequest(0);
  2170. }
  2171. //==============================================
  2172. // CSU Trigger Smart Charging Profilw
  2173. //==============================================
  2174. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  2175. {
  2176. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  2177. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  2178. }
  2179. //==============================================
  2180. // Charger start transaction
  2181. //==============================================
  2182. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2183. {
  2184. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  2185. sendStartTransactionRequest(gun_index);
  2186. clientTime.StartTransaction = time((time_t*)NULL);
  2187. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2188. storeTempStopTransaction(gun_index);
  2189. }
  2190. //==============================================
  2191. // Charger stop transaction
  2192. //==============================================
  2193. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2194. {
  2195. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2196. sendStopTransactionRequest(gun_index);
  2197. clientTime.StopTransaction = time((time_t*)NULL);
  2198. }
  2199. //==============================================
  2200. // Charger status report
  2201. //==============================================
  2202. //--- Check Mode Change ---//
  2203. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2204. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2205. {
  2206. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2207. {
  2208. tempIndex = ((gun_index==2) ? 1: 0);
  2209. }
  2210. else
  2211. {
  2212. tempIndex = gun_index;
  2213. }
  2214. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2215. {
  2216. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2217. {
  2218. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  2219. {
  2220. // Sent unplug message for California pricing logic
  2221. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  2222. {
  2223. uint8_t ts[20];
  2224. getNowDatetime(ts);
  2225. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2226. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2227. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2228. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2229. }
  2230. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2231. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2232. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2233. statusModeChage[gun_index] = TRUE;
  2234. }
  2235. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2236. {
  2237. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2238. if((access(filenmae,F_OK))!=-1)
  2239. {
  2240. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2241. sprintf(str,"rm -f %s",filenmae);
  2242. system(str);
  2243. }
  2244. }
  2245. #if 1 // for TempStopTransaction
  2246. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2247. {
  2248. checkTempStopTransaction(gun_index);
  2249. }
  2250. #endif
  2251. }
  2252. }
  2253. }
  2254. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2255. {
  2256. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2257. {
  2258. tempIndex = ((gun_index==2) ? 1: 0);
  2259. }
  2260. else
  2261. {
  2262. tempIndex = gun_index;
  2263. }
  2264. for (int index = 0; index < CCS_QUANTITY; index++)
  2265. {
  2266. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2267. {
  2268. 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]*/ )
  2269. {
  2270. // Sent unplug message for California pricing logic
  2271. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  2272. {
  2273. uint8_t ts[20];
  2274. getNowDatetime(ts);
  2275. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2276. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2277. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2278. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2279. }
  2280. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2281. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2282. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2283. statusModeChage[gun_index] = TRUE;
  2284. }
  2285. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2286. {
  2287. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2288. if((access(filenmae,F_OK))!=-1)
  2289. {
  2290. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2291. sprintf(str,"rm -f %s",filenmae);
  2292. system(str);
  2293. }
  2294. }
  2295. #if 1 // for TempStopTransaction
  2296. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2297. {
  2298. checkTempStopTransaction(gun_index);
  2299. }
  2300. #endif
  2301. }
  2302. }
  2303. }
  2304. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2305. {
  2306. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2307. {
  2308. tempIndex = ((gun_index==2) ? 1: 0);
  2309. }
  2310. else
  2311. {
  2312. tempIndex = gun_index;
  2313. }
  2314. for (int index = 0; index < GB_QUANTITY; index++)
  2315. {
  2316. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2317. {
  2318. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  2319. {
  2320. // Sent unplug message for California pricing logic
  2321. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  2322. {
  2323. uint8_t ts[20];
  2324. getNowDatetime(ts);
  2325. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2326. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2327. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2328. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2329. }
  2330. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2331. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2332. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2333. statusModeChage[gun_index] = TRUE;
  2334. }
  2335. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2336. {
  2337. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2338. if((access(filenmae,F_OK))!=-1)
  2339. {
  2340. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2341. sprintf(str,"rm -f %s",filenmae);
  2342. system(str);
  2343. }
  2344. }
  2345. #if 1 // for TempStopTransaction
  2346. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2347. {
  2348. checkTempStopTransaction(gun_index);
  2349. }
  2350. #endif
  2351. }
  2352. }
  2353. }
  2354. else if(gunType[gun_index] == GUN_TYPE_DO)
  2355. {
  2356. tempIndex = gun_index;
  2357. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2358. {
  2359. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2360. {
  2361. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  2362. {
  2363. // Sent unplug message for California pricing logic
  2364. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  2365. {
  2366. uint8_t ts[20];
  2367. getNowDatetime(ts);
  2368. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2369. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2370. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2371. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2372. }
  2373. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  2374. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  2375. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2376. statusModeChage[gun_index] = TRUE;
  2377. }
  2378. 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
  2379. {
  2380. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2381. if((access(filenmae,F_OK))!=-1)
  2382. {
  2383. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2384. sprintf(str,"rm -f %s",filenmae);
  2385. system(str);
  2386. }
  2387. }
  2388. #if 1 // for TempStopTransaction
  2389. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2390. {
  2391. checkTempStopTransaction(gun_index);
  2392. }
  2393. #endif
  2394. }
  2395. }
  2396. }
  2397. else
  2398. {
  2399. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2400. {
  2401. tempIndex = 2;
  2402. }
  2403. else
  2404. {
  2405. tempIndex = gun_index;
  2406. }
  2407. for (int index = 0; index < AC_QUANTITY; index++)
  2408. {
  2409. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2410. {
  2411. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  2412. {
  2413. // Sent unplug message for California pricing logic
  2414. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)
  2415. {
  2416. uint8_t ts[20];
  2417. getNowDatetime(ts);
  2418. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2419. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2420. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2421. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2422. }
  2423. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2424. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2425. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2426. statusModeChage[gun_index] = TRUE;
  2427. }
  2428. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2429. {
  2430. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2431. if((access(filenmae,F_OK))!=-1)
  2432. {
  2433. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2434. sprintf(str,"rm -f %s",filenmae);
  2435. system(str);
  2436. }
  2437. }
  2438. #if 1 // for TempStopTransaction
  2439. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2440. {
  2441. checkTempStopTransaction(gun_index);
  2442. }
  2443. #endif
  2444. }
  2445. }// END
  2446. }
  2447. if(isWebsocketSendable &&
  2448. (
  2449. (statusModeChage[gun_index] == TRUE) ||
  2450. //((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index))) ||
  2451. ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 10))
  2452. )
  2453. )
  2454. {
  2455. if(SystemInitial > 0)
  2456. SystemInitial -= 1;
  2457. sendStatusNotificationRequest(gun_index);
  2458. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2459. statusModeChage[gun_index] = FALSE;
  2460. }
  2461. //==============================================
  2462. // Meter report
  2463. //==============================================
  2464. // Trigger MeterValue
  2465. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  2466. {
  2467. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  2468. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  2469. }
  2470. // ClockAlign MeterValue
  2471. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  2472. {
  2473. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2474. {
  2475. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2476. {
  2477. tempIndex = ((gun_index==2) ? 1: 0);
  2478. }
  2479. else
  2480. {
  2481. tempIndex = gun_index;
  2482. }
  2483. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2484. {
  2485. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2486. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2487. {
  2488. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2489. {
  2490. reqClockAlignMeter[gun_index] = 1;
  2491. }
  2492. }
  2493. }// End for CHAdeMO
  2494. }
  2495. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2496. {
  2497. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2498. {
  2499. tempIndex = ((gun_index==2) ? 1: 0);
  2500. }
  2501. else
  2502. {
  2503. tempIndex = gun_index;
  2504. }
  2505. for (int index = 0; index < CCS_QUANTITY; index++)
  2506. {
  2507. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2508. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2509. {
  2510. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2511. {
  2512. reqClockAlignMeter[gun_index] = 1;
  2513. }
  2514. }
  2515. } // End for CCS
  2516. }
  2517. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2518. {
  2519. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2520. {
  2521. tempIndex = ((gun_index==2) ? 1: 0);
  2522. }
  2523. else
  2524. {
  2525. tempIndex = gun_index;
  2526. }
  2527. for (int index = 0; index < GB_QUANTITY; index++)
  2528. {
  2529. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2530. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2531. {
  2532. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2533. {
  2534. reqClockAlignMeter[gun_index] = 1;
  2535. }
  2536. }
  2537. }// End for GB
  2538. }
  2539. else if(gunType[gun_index] == GUN_TYPE_DO)
  2540. {
  2541. tempIndex = gun_index;
  2542. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2543. {
  2544. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2545. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2546. {
  2547. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_CHARGING)
  2548. {
  2549. reqClockAlignMeter[gun_index] = 1;
  2550. }
  2551. }
  2552. }
  2553. }
  2554. else
  2555. {
  2556. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2557. {
  2558. tempIndex = 2;
  2559. }
  2560. else
  2561. {
  2562. tempIndex = gun_index;
  2563. }
  2564. for (int index = 0; index < AC_QUANTITY; index++)
  2565. {
  2566. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2567. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2568. {
  2569. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2570. {
  2571. reqClockAlignMeter[gun_index] = 1;
  2572. }
  2573. }
  2574. }//End for AC
  2575. }
  2576. if(reqClockAlignMeter[gun_index] == 1)
  2577. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  2578. }
  2579. // Sample period MeterValue
  2580. if((((time((time_t*)NULL) - clientTime.MeterValues[gun_index]) > (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1))))
  2581. {
  2582. //check Transaction active
  2583. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2584. {
  2585. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2586. {
  2587. tempIndex = ((gun_index==2) ? 1: 0);
  2588. }
  2589. else
  2590. {
  2591. tempIndex = gun_index;
  2592. }
  2593. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2594. {
  2595. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2596. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2597. {
  2598. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2599. {
  2600. reqSampleMeter[gun_index] = 1;
  2601. }
  2602. }
  2603. }// End for CHAdeMO
  2604. }
  2605. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2606. {
  2607. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2608. {
  2609. tempIndex = ((gun_index==2) ? 1: 0);
  2610. }
  2611. else
  2612. {
  2613. tempIndex = gun_index;
  2614. }
  2615. for (int index = 0; index < CCS_QUANTITY; index++)
  2616. {
  2617. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2618. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2619. {
  2620. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2621. {
  2622. reqSampleMeter[gun_index] = 1;
  2623. }
  2624. }
  2625. } // End for CCS
  2626. }
  2627. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2628. {
  2629. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2630. {
  2631. tempIndex = ((gun_index==2) ? 1: 0);
  2632. }
  2633. else
  2634. {
  2635. tempIndex = gun_index;
  2636. }
  2637. for (int index = 0; index < GB_QUANTITY; index++)
  2638. {
  2639. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2640. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2641. {
  2642. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2643. {
  2644. reqSampleMeter[gun_index] = 1;
  2645. }
  2646. }
  2647. }// End for GB
  2648. }
  2649. else if(gunType[gun_index] == GUN_TYPE_DO)
  2650. {
  2651. tempIndex = gun_index;
  2652. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2653. {
  2654. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2655. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2656. {
  2657. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  2658. {
  2659. reqSampleMeter[gun_index] = 1;
  2660. }
  2661. }
  2662. }
  2663. }
  2664. else
  2665. {
  2666. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2667. {
  2668. tempIndex = 2;
  2669. }
  2670. else
  2671. {
  2672. tempIndex = gun_index;
  2673. }
  2674. for (int index = 0; index < AC_QUANTITY; index++)
  2675. {
  2676. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2677. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2678. {
  2679. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  2680. {
  2681. reqSampleMeter[gun_index] = 1;
  2682. }
  2683. }
  2684. }//End for AC
  2685. }
  2686. if(reqSampleMeter[gun_index] == 1)
  2687. {
  2688. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  2689. storeTempStopTransaction(gun_index);
  2690. }
  2691. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2692. }
  2693. //==============================================
  2694. // Check Connector reserved
  2695. //==============================================
  2696. //===============================
  2697. // Check if Reserve is expired
  2698. //===============================
  2699. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  2700. {
  2701. double diff_t;
  2702. struct tm tp;
  2703. // current time
  2704. time_t t = time(NULL);
  2705. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  2706. tp.tm_isdst = -1;
  2707. time_t utc = mktime(&tp);
  2708. diff_t = difftime(utc, t);
  2709. if(diff_t <= 0)
  2710. {
  2711. DEBUG_INFO("reserve expired.\n");
  2712. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  2713. }
  2714. }//END OF Check if Reserve is expired
  2715. //==========================================
  2716. // csu trigger FirmwareStatusNotificationReq
  2717. //==========================================
  2718. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  2719. {
  2720. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  2721. }
  2722. //==========================================
  2723. // csu trigger CancelReservationConf
  2724. //==========================================
  2725. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  2726. {
  2727. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  2728. }
  2729. //==========================================
  2730. // csu trigger ChangeAvailabilityConf
  2731. //==========================================
  2732. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  2733. {
  2734. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  2735. }
  2736. //==========================================
  2737. // csu trigger UnlockConnectorConf
  2738. //==========================================
  2739. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  2740. {
  2741. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  2742. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  2743. }
  2744. //==========================================
  2745. // csu trigger ReserveNowConf
  2746. //==========================================
  2747. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  2748. {
  2749. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  2750. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  2751. }
  2752. }
  2753. }
  2754. //==========================================
  2755. // send request routine
  2756. //==========================================
  2757. int sendAuthorizeRequest(int gun_index)
  2758. {
  2759. mtrace();
  2760. int result = FAIL;
  2761. char message[100]={0};
  2762. char guid[37];
  2763. char tempdata[65]={0};
  2764. DEBUG_INFO("sendAuthorizeRequest...\n");
  2765. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  2766. //Local Authorize
  2767. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  2768. {
  2769. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  2770. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2771. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  2772. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  2773. result = PASS;
  2774. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2775. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2776. authorizeRetryTimes = 0;
  2777. return result;
  2778. }
  2779. 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))||
  2780. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  2781. {
  2782. // Query from cache
  2783. DEBUG_INFO("Authorize from cache.\n");
  2784. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2785. // Query from list
  2786. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  2787. {
  2788. DEBUG_INFO("Authorize from list.\n");
  2789. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2790. }
  2791. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  2792. {
  2793. if(strcmp(idTagQuery.idTagstr,"") == 0)
  2794. {
  2795. DEBUG_INFO("off-line Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  2796. }
  2797. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  2798. {
  2799. DEBUG_INFO("off-line Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  2800. }
  2801. DEBUG_INFO("off-line Local Authorization Fail !!!!\n");
  2802. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2803. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2804. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  2805. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  2806. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2807. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2808. authorizeRetryTimes = 0;
  2809. return result;
  2810. }
  2811. else
  2812. {
  2813. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  2814. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  2815. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2816. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  2817. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  2818. else
  2819. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  2820. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  2821. result = PASS;
  2822. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2823. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2824. authorizeRetryTimes = 0;
  2825. return result;
  2826. }
  2827. }
  2828. //initialize struct Authorize
  2829. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  2830. //get data from shared memory
  2831. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2832. random_uuid(guid);
  2833. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  2834. LWS_Send(message);
  2835. sprintf(tempdata, "Authorize,%d", gun_index);
  2836. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2837. {
  2838. result = PASS;
  2839. DEBUG_INFO("Authorize mapItem pass\n");
  2840. }
  2841. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2842. return result;
  2843. }
  2844. int sendBootNotificationRequest(void)
  2845. {
  2846. mtrace();
  2847. int result = FAIL;
  2848. char message[500]={0}, payload[700]={0};
  2849. char guid[37]={0};
  2850. char tempdata[65]={0};
  2851. // Fill BootNotification fields
  2852. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  2853. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  2854. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  2855. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2856. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  2857. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  2858. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  2859. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  2860. ShmOCPP16Data->ChargeBoxId
  2861. ,ShmSysConfigAndInfo->SysConfig.ModelName
  2862. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  2863. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  2864. ,ShmOCPP16Data->BootNotification.CpFwVersion
  2865. ,ShmOCPP16Data->BootNotification.CpIccid
  2866. ,ShmOCPP16Data->BootNotification.CpImsi);
  2867. random_uuid(guid);
  2868. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  2869. LWS_Send(message);
  2870. sprintf(tempdata, "BootNotification,0");
  2871. 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*/)
  2872. {
  2873. result = PASS;
  2874. }
  2875. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  2876. strcpy(queuedata,message);
  2877. return result;
  2878. }
  2879. int sendDataTransferRequest(int gun_index)
  2880. {
  2881. mtrace();
  2882. char message[1000]={0};
  2883. char guid[37]={0};
  2884. char tempdata[65]={0};
  2885. int result = FAIL;
  2886. random_uuid(guid);
  2887. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  2888. MESSAGE_TYPE_CALL,
  2889. guid,
  2890. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  2891. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  2892. ShmOCPP16Data->DataTransfer[gun_index].Data);
  2893. LWS_Send(message);
  2894. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  2895. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2896. {
  2897. result = PASS;
  2898. DEBUG_INFO("DataTransfer mapItem pass\n");
  2899. }
  2900. return result;
  2901. }
  2902. int sendDiagnosticsStatusNotificationRequest(char *status)
  2903. {
  2904. mtrace();
  2905. int result = FAIL;
  2906. char message[110]={0};
  2907. char guid[37]={0};
  2908. char tempdata[65]={0};
  2909. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  2910. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  2911. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  2912. random_uuid(guid);
  2913. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  2914. LWS_SendNow(message);
  2915. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  2916. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2917. {
  2918. result = PASS;
  2919. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  2920. }
  2921. //#ifdef SystemLogMessage
  2922. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  2923. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2924. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  2925. //#endif
  2926. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  2927. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  2928. //record status
  2929. if(strcmp(status,"Idle")==0)
  2930. {
  2931. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  2932. }
  2933. else if(strcmp(status,"Uploaded")==0)
  2934. {
  2935. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  2936. }
  2937. else if(strcmp(status,"UploadFailed")==0)
  2938. {
  2939. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  2940. }
  2941. else if(strcmp(status,"Uploading")==0)
  2942. {
  2943. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  2944. }
  2945. return result;
  2946. }
  2947. int sendFirmwareStatusNotificationRequest(char *status)
  2948. {
  2949. mtrace();
  2950. int result = FAIL;
  2951. char message[110]={0};
  2952. char guid[37]={0};
  2953. char tempdata[65]={0};
  2954. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  2955. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  2956. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  2957. random_uuid(guid);
  2958. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  2959. LWS_SendNow(message);
  2960. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  2961. 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*/)
  2962. {
  2963. result = PASS;
  2964. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  2965. }
  2966. //#ifdef SystemLogMessage
  2967. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  2968. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2969. //#endif
  2970. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  2971. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  2972. //record status
  2973. if(strcmp(status,"Downloaded")==0)
  2974. {
  2975. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  2976. }
  2977. else if(strcmp(status,"DownloadFailed")==0)
  2978. {
  2979. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  2980. }
  2981. else if(strcmp(status,"Downloading")==0)
  2982. {
  2983. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  2984. }
  2985. else if(strcmp(status,"Idle")==0)
  2986. {
  2987. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  2988. }
  2989. else if(strcmp(status,"InstallationFailed")==0)
  2990. {
  2991. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  2992. }
  2993. else if(strcmp(status,"Installing")==0)
  2994. {
  2995. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  2996. }
  2997. else if(strcmp(status,"Installed")==0)
  2998. {
  2999. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  3000. }
  3001. return result;
  3002. }
  3003. int sendHeartbeatRequest(int gun_index)
  3004. {
  3005. mtrace();
  3006. int result = FAIL;
  3007. char message[80]={0};
  3008. char guid[37]={0};
  3009. char tempdata[65]={0};
  3010. random_uuid(guid);
  3011. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  3012. , MESSAGE_TYPE_CALL
  3013. , guid );
  3014. LWS_Send(message);
  3015. sprintf(tempdata, "Heartbeat,%d", 0);
  3016. 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*/)
  3017. {
  3018. result = PASS;
  3019. }
  3020. return result;
  3021. }
  3022. int sendStartTransactionRequest(int gun_index)
  3023. {
  3024. mtrace();
  3025. int result = FAIL;
  3026. char message[250]={0};
  3027. char guid[37]={0};
  3028. struct timeval tmnow;
  3029. struct tm *tm;
  3030. char buf[28];//, usec_buf[6];
  3031. char tempdata[65]={0};
  3032. int tempIndex = 0;
  3033. DEBUG_INFO("sendStartTransactionRequest...\n");
  3034. gettimeofday(&tmnow, NULL);
  3035. time_t t;
  3036. t = time(NULL);
  3037. /*UTC time and date*/
  3038. tm = gmtime(&t);
  3039. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3040. #if 0 // remove temporally
  3041. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3042. strcat(buf,".");
  3043. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3044. strcat(buf,usec_buf);
  3045. #endif
  3046. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  3047. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  3048. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3049. // clear StartTransaction Response
  3050. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  3051. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  3052. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  3053. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  3054. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3055. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3056. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3057. {
  3058. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3059. {
  3060. tempIndex = ((gun_index==2) ? 1: 0);
  3061. }
  3062. else
  3063. {
  3064. tempIndex = gun_index;
  3065. }
  3066. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3067. {
  3068. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3069. {
  3070. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3071. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  3072. }
  3073. }
  3074. }
  3075. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3076. {
  3077. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3078. {
  3079. tempIndex = ((gun_index==2) ? 1: 0);
  3080. }
  3081. else
  3082. {
  3083. tempIndex = gun_index;
  3084. }
  3085. for (int index = 0; index < CCS_QUANTITY; index++)
  3086. {
  3087. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3088. {
  3089. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3090. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  3091. }
  3092. }
  3093. }
  3094. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3095. {
  3096. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3097. {
  3098. tempIndex = ((gun_index==2) ? 1: 0);
  3099. }
  3100. else
  3101. {
  3102. tempIndex = gun_index;
  3103. }
  3104. for (int index = 0; index < GB_QUANTITY; index++)
  3105. {
  3106. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3107. {
  3108. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3109. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  3110. }
  3111. }
  3112. }
  3113. else if(gunType[gun_index] == GUN_TYPE_DO)
  3114. {
  3115. tempIndex = gun_index;
  3116. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3117. {
  3118. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3119. {
  3120. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3121. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  3122. }
  3123. }
  3124. }
  3125. else
  3126. {
  3127. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3128. {
  3129. tempIndex = 2;
  3130. }
  3131. else
  3132. {
  3133. tempIndex = gun_index;
  3134. }
  3135. for (int index = 0; index < AC_QUANTITY; index++)
  3136. {
  3137. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3138. {
  3139. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3140. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  3141. }
  3142. }
  3143. }
  3144. random_uuid(guid);
  3145. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  3146. {
  3147. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  3148. , gun_index +1
  3149. , MESSAGE_TYPE_CALL
  3150. , guid
  3151. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3152. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3153. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3154. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3155. }
  3156. else
  3157. {
  3158. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  3159. , gun_index +1
  3160. , MESSAGE_TYPE_CALL
  3161. , guid
  3162. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3163. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3164. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3165. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  3166. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3167. }
  3168. #if 1
  3169. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  3170. 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*/)
  3171. {
  3172. result = PASS;
  3173. }
  3174. #endif
  3175. strcpy(queuedata, message);
  3176. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3177. return result;
  3178. }
  3179. int sendStatusNotificationRequest(int gun_index)
  3180. {
  3181. mtrace();
  3182. int result = FAIL;
  3183. char message[600]={0};
  3184. char guid[37];
  3185. int currentStatus = 0;
  3186. struct timeval tmnow;
  3187. struct tm *tm;
  3188. char buf[28];//, usec_buf[6];
  3189. char tempdata[65]={0};
  3190. int tempIndex = 0;
  3191. gettimeofday(&tmnow, NULL);
  3192. time_t t;
  3193. t = time(NULL);
  3194. /*UTC time and date*/
  3195. tm = gmtime(&t);
  3196. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3197. #if 0 // remove temporally
  3198. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3199. strcat(buf,".");
  3200. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3201. strcat(buf,usec_buf);
  3202. #endif
  3203. printf("%s",buf);
  3204. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  3205. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  3206. // it's option
  3207. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  3208. /*
  3209. enum _SYSTEM_STATUS
  3210. {
  3211. S_BOOTING = 0,
  3212. S_IDLE, = 1
  3213. S_AUTHORIZING, =2
  3214. S_REASSIGN_CHECK, =3
  3215. S_REASSIGN, =4
  3216. S_PRECHARGE, =5
  3217. S_PREPARING_FOR_EV, =6
  3218. S_PREPARING_FOR_EVSE, =7
  3219. S_CHARGING, =8
  3220. S_TERMINATING, =9
  3221. S_COMPLETE, =10
  3222. S_ALARM, =11
  3223. S_FAULT =12
  3224. }
  3225. */
  3226. //check Transaction active
  3227. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3228. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3229. {
  3230. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3231. {
  3232. tempIndex = ((gun_index==2) ? 1: 0);
  3233. }
  3234. else
  3235. {
  3236. tempIndex = gun_index;
  3237. }
  3238. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3239. {
  3240. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  3241. {
  3242. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  3243. {
  3244. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3245. {
  3246. currentStatus = Preparing; //OCPP Status: Preparing
  3247. }
  3248. else
  3249. {
  3250. currentStatus = Available; //OCPP Status: Available
  3251. }
  3252. }
  3253. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3254. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3255. ) //S_PRECHARGE
  3256. {
  3257. currentStatus = Preparing; //OCPP Status: Preparing
  3258. }
  3259. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3260. {
  3261. currentStatus = Charging; //OCPP Status: Charging
  3262. }
  3263. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3264. {
  3265. currentStatus = Finishing; //OCPP Status: Finishing
  3266. }
  3267. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3268. {
  3269. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3270. }
  3271. 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
  3272. {
  3273. currentStatus = Unavailable; //OCPP Status: Unavailable
  3274. }
  3275. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3276. {
  3277. currentStatus = Faulted; //OCPP Status: Faulted
  3278. }
  3279. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3280. {
  3281. currentStatus = Reserved; //OCPP Status: Reserved
  3282. }
  3283. } //end of the same index
  3284. }//end of for CHAdeMO_QUANTITY
  3285. }
  3286. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3287. {
  3288. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3289. {
  3290. tempIndex = ((gun_index==2) ? 1: 0);
  3291. }
  3292. else
  3293. {
  3294. tempIndex = gun_index;
  3295. }
  3296. for (int index = 0; index < CCS_QUANTITY; index++)
  3297. {
  3298. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3299. {
  3300. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3301. {
  3302. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3303. {
  3304. currentStatus = Preparing; //OCPP Status: Preparing
  3305. }
  3306. else
  3307. {
  3308. currentStatus = Available; //OCPP Status: Available
  3309. }
  3310. }
  3311. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3312. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3313. ) //S_PRECHARGE
  3314. {
  3315. currentStatus = Preparing; //OCPP Status: Preparing
  3316. }
  3317. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3318. {
  3319. currentStatus = Charging; //OCPP Status: Charging
  3320. }
  3321. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3322. {
  3323. currentStatus = Finishing; //OCPP Status: Finishing
  3324. }
  3325. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3326. {
  3327. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3328. }
  3329. 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
  3330. {
  3331. currentStatus = Unavailable; //OCPP Status : Unavailable
  3332. }
  3333. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3334. {
  3335. currentStatus = Faulted; //OCPP Status: Faulted
  3336. }
  3337. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3338. {
  3339. currentStatus = Reserved; //OCPP Status: Reserved
  3340. }
  3341. } //end of the same index
  3342. } // end of for CCS_QUANTITY
  3343. }
  3344. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3345. {
  3346. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3347. {
  3348. tempIndex = ((gun_index==2) ? 1: 0);
  3349. }
  3350. else
  3351. {
  3352. tempIndex = gun_index;
  3353. }
  3354. for (int index = 0; index < GB_QUANTITY; index++)
  3355. {
  3356. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3357. {
  3358. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3359. {
  3360. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3361. {
  3362. currentStatus = Preparing; //OCPP Status: Preparing
  3363. }
  3364. else
  3365. {
  3366. currentStatus = Available; //OCPP Status: Available
  3367. }
  3368. }
  3369. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3370. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3371. ) //S_PRECHARGE
  3372. {
  3373. currentStatus = Preparing; //OCPP Status: Preparing
  3374. }
  3375. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3376. {
  3377. currentStatus = Charging; //OCPP Status: Charging
  3378. }
  3379. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3380. {
  3381. currentStatus = Finishing; //OCPP Status: Finishing
  3382. }
  3383. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3384. {
  3385. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3386. }
  3387. 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
  3388. {
  3389. currentStatus = Unavailable; //OCPP Status: Unavailable
  3390. }
  3391. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3392. {
  3393. currentStatus = Faulted; //OCPP Status: Faulted
  3394. }
  3395. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3396. {
  3397. currentStatus = Reserved; //OCPP Status: Reserved
  3398. }
  3399. } //end of the same index
  3400. } // end of for GB_QUANTITY
  3401. }
  3402. else if(gunType[gun_index] == GUN_TYPE_DO)
  3403. {
  3404. tempIndex = gun_index;
  3405. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3406. {
  3407. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3408. {
  3409. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3410. {
  3411. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3412. {
  3413. currentStatus = Preparing; //OCPP Status: Preparing
  3414. }
  3415. else
  3416. {
  3417. currentStatus = Available; //OCPP Status: Available
  3418. }
  3419. }
  3420. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3421. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3422. ) //S_PRECHARGE
  3423. {
  3424. currentStatus = Preparing; //OCPP Status: Preparing
  3425. }
  3426. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3427. {
  3428. currentStatus = Charging; //OCPP Status: Charging
  3429. }
  3430. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3431. {
  3432. currentStatus = Finishing; //OCPP Status: Finishing
  3433. }
  3434. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3435. {
  3436. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3437. }
  3438. 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
  3439. {
  3440. currentStatus = Unavailable; //OCPP Status: Unavailable
  3441. }
  3442. 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
  3443. {
  3444. currentStatus = Faulted; //OCPP Status: Faulted
  3445. }
  3446. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3447. {
  3448. currentStatus = Reserved; //OCPP Status: Reserved
  3449. }
  3450. } //end of the same index
  3451. }
  3452. }
  3453. else
  3454. {
  3455. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3456. {
  3457. tempIndex = 2;
  3458. }
  3459. else
  3460. {
  3461. tempIndex = gun_index;
  3462. }
  3463. for (int index = 0; index < AC_QUANTITY; index++)
  3464. {
  3465. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3466. {
  3467. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3468. {
  3469. 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))
  3470. {
  3471. currentStatus = Preparing; //OCPP Status: Preparing
  3472. }
  3473. else
  3474. {
  3475. currentStatus = Available; //OCPP Status: Available
  3476. }
  3477. }
  3478. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  3479. {
  3480. currentStatus = Preparing; //OCPP Status: Preparing
  3481. }
  3482. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3483. {
  3484. currentStatus = Charging; //OCPP Status: Charging
  3485. }
  3486. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3487. {
  3488. currentStatus = Finishing; //OCPP Status: Finishing
  3489. }
  3490. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3491. {
  3492. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3493. }
  3494. 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
  3495. {
  3496. currentStatus = Unavailable; //OCPP Status: Unavailable
  3497. }
  3498. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3499. {
  3500. currentStatus = Faulted; //OCPP Status: Faulted
  3501. }
  3502. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3503. {
  3504. currentStatus = Reserved; //OCPP Status: Reserved
  3505. }
  3506. }//end of the same index
  3507. }//end of for AC_QUANTITY
  3508. }
  3509. //it's option
  3510. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3511. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3512. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3513. random_uuid(guid);
  3514. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3515. , MESSAGE_TYPE_CALL
  3516. , guid
  3517. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3518. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3519. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3520. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3521. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3522. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3523. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3524. if((server_sign == TRUE))
  3525. {
  3526. LWS_Send(message);
  3527. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3528. 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*/)
  3529. {
  3530. //DEBUG_ERROR("statusNotification mapitem pass");
  3531. result = PASS;
  3532. }
  3533. }
  3534. else
  3535. {
  3536. result = PASS;
  3537. }
  3538. return result;
  3539. }
  3540. int sendStopTransactionRequest(int gun_index)
  3541. {
  3542. mtrace();
  3543. int result = FAIL;
  3544. //char message[1500]={0};
  3545. char guid[37]={0};
  3546. char tempdata[65]={0};
  3547. int tempIndex = 0;
  3548. char TempStopTransaction[256];
  3549. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  3550. //int idx_sample=0;
  3551. DEBUG_INFO("sendStopTransactionRequest \n");
  3552. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3553. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  3554. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  3555. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3556. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3557. {
  3558. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3559. {
  3560. tempIndex = ((gun_index==2) ? 1: 0);
  3561. }
  3562. else
  3563. {
  3564. tempIndex = gun_index;
  3565. }
  3566. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3567. {
  3568. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3569. {
  3570. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3571. }
  3572. }// END OF CHAdeMO_QUANTITY
  3573. }
  3574. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3575. {
  3576. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3577. {
  3578. tempIndex = ((gun_index==2) ? 1: 0);
  3579. }
  3580. else
  3581. {
  3582. tempIndex = gun_index;
  3583. }
  3584. for (int index = 0; index < CCS_QUANTITY; index++)
  3585. {
  3586. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3587. {
  3588. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3589. }
  3590. }// END OF CCS_QUANTITY
  3591. }
  3592. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3593. {
  3594. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3595. {
  3596. tempIndex = ((gun_index==2) ? 1: 0);
  3597. }
  3598. else
  3599. {
  3600. tempIndex = gun_index;
  3601. }
  3602. for (int index = 0; index < GB_QUANTITY; index++)
  3603. {
  3604. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3605. {
  3606. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3607. }
  3608. }// END OF GB_QUANTITY
  3609. }
  3610. else if(gunType[gun_index] == GUN_TYPE_DO)
  3611. {
  3612. tempIndex = gun_index;
  3613. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3614. {
  3615. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3616. {
  3617. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3618. }
  3619. }// END OF GB_QUANTITY
  3620. }
  3621. else
  3622. {
  3623. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3624. {
  3625. tempIndex = 2;
  3626. }
  3627. else
  3628. {
  3629. tempIndex = gun_index;
  3630. }
  3631. for (int index = 0; index < AC_QUANTITY; index++)
  3632. {
  3633. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3634. {
  3635. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3636. }
  3637. }// END OF AC_QUANTITY
  3638. }
  3639. //====================================== Stop Transaction Time =====================================================
  3640. struct timeval tmnow;
  3641. struct tm *tm;
  3642. char buf[28];//, usec_buf[6];
  3643. gettimeofday(&tmnow, NULL);
  3644. time_t t;
  3645. t = time(NULL);
  3646. /*UTC time and date*/
  3647. tm = gmtime(&t);
  3648. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3649. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  3650. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  3651. random_uuid(guid);
  3652. /***********************************transactionData******************************************************/
  3653. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  3654. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  3655. //=================================
  3656. // Transaction_Begin
  3657. //=================================
  3658. //============================================ Energy.Active.Import.Interval ================================
  3659. //idx_sample=0;
  3660. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  3661. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  3662. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  3663. 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*/]);
  3664. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3665. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  3666. {
  3667. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  3668. }
  3669. else
  3670. {
  3671. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  3672. }
  3673. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  3674. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3675. //=================================
  3676. // Transaction_End
  3677. //=================================
  3678. // ================================= Current.Import L1 ===============================================
  3679. //idx_sample=1;
  3680. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  3681. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3682. {
  3683. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3684. {
  3685. tempIndex = ((gun_index==2) ? 1: 0);
  3686. }
  3687. else
  3688. {
  3689. tempIndex = gun_index;
  3690. }
  3691. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3692. {
  3693. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3694. {
  3695. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3696. }
  3697. }// End of for CHAdeMO_QUANTITY
  3698. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3699. }
  3700. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3701. {
  3702. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3703. {
  3704. tempIndex = ((gun_index==2) ? 1: 0);
  3705. }
  3706. else
  3707. {
  3708. tempIndex = gun_index;
  3709. }
  3710. for (int index = 0; index < CCS_QUANTITY; index++)
  3711. {
  3712. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3713. {
  3714. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3715. }
  3716. }// End of for CCS_QUANTITY
  3717. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3718. }
  3719. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3720. {
  3721. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3722. {
  3723. tempIndex = ((gun_index==2) ? 1: 0);
  3724. }
  3725. else
  3726. {
  3727. tempIndex = gun_index;
  3728. }
  3729. for (int index = 0; index < GB_QUANTITY; index++)
  3730. {
  3731. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3732. {
  3733. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3734. }
  3735. }// End of for GB_QUANTITY
  3736. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3737. }
  3738. else if(gunType[gun_index] == GUN_TYPE_DO)
  3739. {
  3740. tempIndex = gun_index;
  3741. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3742. {
  3743. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3744. {
  3745. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3746. }
  3747. }
  3748. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3749. }
  3750. else
  3751. {
  3752. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3753. {
  3754. tempIndex = 2;
  3755. }
  3756. else
  3757. {
  3758. tempIndex = gun_index;
  3759. }
  3760. for (int index = 0; index < AC_QUANTITY; index++)
  3761. {
  3762. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3763. {
  3764. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  3765. }
  3766. }// End of for AC_QUANTITY
  3767. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  3768. }
  3769. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3770. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  3771. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  3772. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  3773. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3774. // ================================= Energy.Active.Import.Interval ==============================================
  3775. //idx_sample=2;
  3776. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3777. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3778. {
  3779. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3780. {
  3781. tempIndex = ((gun_index==2) ? 1: 0);
  3782. }
  3783. else
  3784. {
  3785. tempIndex = gun_index;
  3786. }
  3787. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3788. {
  3789. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3790. {
  3791. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3792. }
  3793. }// END OF CHAdeMO_QUANTITY
  3794. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3795. }
  3796. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3797. {
  3798. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3799. {
  3800. tempIndex = ((gun_index==2) ? 1: 0);
  3801. }
  3802. else
  3803. {
  3804. tempIndex = gun_index;
  3805. }
  3806. for (int index = 0; index < CCS_QUANTITY; index++)
  3807. {
  3808. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3809. {
  3810. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3811. }
  3812. }// END OF CCS_QUANTITY
  3813. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3814. }
  3815. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3816. {
  3817. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3818. {
  3819. tempIndex = ((gun_index==2) ? 1: 0);
  3820. }
  3821. else
  3822. {
  3823. tempIndex = gun_index;
  3824. }
  3825. for (int index = 0; index < GB_QUANTITY; index++)
  3826. {
  3827. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3828. {
  3829. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3830. }
  3831. }// END OF GB_QUANTITY
  3832. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3833. }
  3834. else if(gunType[gun_index] == GUN_TYPE_DO)
  3835. {
  3836. tempIndex = gun_index;
  3837. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3838. {
  3839. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3840. {
  3841. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3842. }
  3843. }
  3844. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3845. }
  3846. else
  3847. {
  3848. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3849. {
  3850. tempIndex = 2;
  3851. }
  3852. else
  3853. {
  3854. tempIndex = gun_index;
  3855. }
  3856. for (int index = 0; index < AC_QUANTITY; index++)
  3857. {
  3858. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3859. {
  3860. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3861. }
  3862. }// END OF AC_QUANTITY
  3863. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  3864. }
  3865. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3866. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  3867. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  3868. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  3869. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3870. //=================================== Power.Active.Import ==================================================
  3871. //idx_sample=3;
  3872. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3873. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3874. {
  3875. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3876. {
  3877. tempIndex = ((gun_index==2) ? 1: 0);
  3878. }
  3879. else
  3880. {
  3881. tempIndex = gun_index;
  3882. }
  3883. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3884. {
  3885. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3886. {
  3887. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3888. }
  3889. } // End for CHAdeMO_QUANTITY
  3890. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3891. }
  3892. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3893. {
  3894. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3895. {
  3896. tempIndex = ((gun_index==2) ? 1: 0);
  3897. }
  3898. else
  3899. {
  3900. tempIndex = gun_index;
  3901. }
  3902. for (int index = 0; index < CCS_QUANTITY; index++)
  3903. {
  3904. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3905. {
  3906. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3907. }
  3908. } // END for CCS_QUANTITY
  3909. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3910. }
  3911. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3912. {
  3913. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3914. {
  3915. tempIndex = ((gun_index==2) ? 1: 0);
  3916. }
  3917. else
  3918. {
  3919. tempIndex = gun_index;
  3920. }
  3921. for (int index = 0; index < GB_QUANTITY; index++)
  3922. {
  3923. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3924. {
  3925. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3926. }
  3927. }// END for GB_QUANTITY
  3928. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3929. }
  3930. else if(gunType[gun_index] == GUN_TYPE_DO)
  3931. {
  3932. tempIndex = gun_index;
  3933. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3934. {
  3935. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3936. {
  3937. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3938. }
  3939. }
  3940. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3941. }
  3942. else
  3943. {
  3944. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3945. {
  3946. tempIndex = 2;
  3947. }
  3948. else
  3949. {
  3950. tempIndex = gun_index;
  3951. }
  3952. for (int index = 0; index < AC_QUANTITY; index++)
  3953. {
  3954. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3955. {
  3956. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3957. }
  3958. } // END for AC_QUANTITY
  3959. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  3960. }
  3961. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3962. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  3963. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  3964. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  3965. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  3966. //============================ Voltage L1 ====================================
  3967. //idx_sample=4;
  3968. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3969. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3970. {
  3971. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3972. {
  3973. tempIndex = ((gun_index==2) ? 1: 0);
  3974. }
  3975. else
  3976. {
  3977. tempIndex = gun_index;
  3978. }
  3979. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3980. {
  3981. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3982. {
  3983. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3984. }
  3985. } // END OF FOR CHAdeMO_QUANTITY
  3986. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3987. }
  3988. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3989. {
  3990. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3991. {
  3992. tempIndex = ((gun_index==2) ? 1: 0);
  3993. }
  3994. else
  3995. {
  3996. tempIndex = gun_index;
  3997. }
  3998. for (int index = 0; index < CCS_QUANTITY; index++)
  3999. {
  4000. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4001. {
  4002. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4003. }
  4004. } // END OF FOR CCS_QUANTITY
  4005. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4006. }
  4007. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4008. {
  4009. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4010. {
  4011. tempIndex = ((gun_index==2) ? 1: 0);
  4012. }
  4013. else
  4014. {
  4015. tempIndex = gun_index;
  4016. }
  4017. for (int index = 0; index < GB_QUANTITY; index++)
  4018. {
  4019. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4020. {
  4021. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4022. }
  4023. } // END OF FOR GB_QUANTITY
  4024. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4025. }
  4026. else if(gunType[gun_index] == GUN_TYPE_DO)
  4027. {
  4028. tempIndex = gun_index;
  4029. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4030. {
  4031. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4032. {
  4033. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4034. }
  4035. }
  4036. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4037. }
  4038. else
  4039. {
  4040. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4041. {
  4042. tempIndex = 2;
  4043. }
  4044. else
  4045. {
  4046. tempIndex = gun_index;
  4047. }
  4048. for (int index = 0; index < AC_QUANTITY; index++)
  4049. {
  4050. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4051. {
  4052. 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
  4053. }
  4054. } // END OF FOR AC_QUANTITY
  4055. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  4056. }
  4057. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4058. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  4059. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  4060. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  4061. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4062. //====================== End SoC ================================
  4063. //idx_sample=5;
  4064. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4065. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  4066. {
  4067. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4068. {
  4069. tempIndex = ((gun_index==2) ? 1: 0);
  4070. }
  4071. else
  4072. {
  4073. tempIndex = gun_index;
  4074. }
  4075. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4076. {
  4077. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4078. {
  4079. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4080. {
  4081. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  4082. }
  4083. }
  4084. }
  4085. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4086. {
  4087. for (int index = 0; index < CCS_QUANTITY; index++)
  4088. {
  4089. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4090. {
  4091. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  4092. }
  4093. }
  4094. }
  4095. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4096. {
  4097. for (int index = 0; index < GB_QUANTITY; index++)
  4098. {
  4099. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4100. {
  4101. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  4102. }
  4103. }
  4104. }
  4105. else if(gunType[gun_index] == GUN_TYPE_DO)
  4106. {
  4107. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4108. {
  4109. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4110. {
  4111. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  4112. }
  4113. }
  4114. }
  4115. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4116. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  4117. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4118. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  4119. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  4120. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4121. } // END FOR DC CASE
  4122. // ================================= Current.Import L2 ===============================================
  4123. //idx_sample=6;
  4124. // AC 3 phse L2 current
  4125. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4126. {
  4127. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4128. {
  4129. tempIndex = 2;
  4130. }
  4131. else
  4132. {
  4133. tempIndex = gun_index;
  4134. }
  4135. for (int index = 0; index < AC_QUANTITY; index++)
  4136. {
  4137. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4138. {
  4139. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  4140. }
  4141. }// End of for AC_QUANTITY
  4142. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  4143. }
  4144. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4145. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  4146. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  4147. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  4148. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4149. // ================================= Current.Import L3 ===============================================
  4150. //idx_sample=7;
  4151. // AC 3 phse L3 current
  4152. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4153. {
  4154. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4155. {
  4156. tempIndex = 2;
  4157. }
  4158. else
  4159. {
  4160. tempIndex = gun_index;
  4161. }
  4162. for (int index = 0; index < AC_QUANTITY; index++)
  4163. {
  4164. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4165. {
  4166. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  4167. }
  4168. }// End of for AC_QUANTITY
  4169. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  4170. }
  4171. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4172. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  4173. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  4174. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  4175. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4176. //============================ Voltage L2 ====================================
  4177. //idx_sample=8;
  4178. // AC 3 phse L2 voltage
  4179. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4180. {
  4181. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4182. {
  4183. tempIndex = 2;
  4184. }
  4185. else
  4186. {
  4187. tempIndex = gun_index;
  4188. }
  4189. for (int index = 0; index < AC_QUANTITY; index++)
  4190. {
  4191. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4192. {
  4193. 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
  4194. }
  4195. } // END OF FOR AC_QUANTITY
  4196. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  4197. }
  4198. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4199. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  4200. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  4201. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  4202. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4203. //============================ Voltage L3 ====================================
  4204. //idx_sample=8;
  4205. // AC 3 phse L3 voltage
  4206. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4207. {
  4208. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4209. {
  4210. tempIndex = 2;
  4211. }
  4212. else
  4213. {
  4214. tempIndex = gun_index;
  4215. }
  4216. for (int index = 0; index < AC_QUANTITY; index++)
  4217. {
  4218. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4219. {
  4220. 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
  4221. }
  4222. } // END OF FOR AC_QUANTITY
  4223. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  4224. }
  4225. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4226. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  4227. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  4228. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  4229. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4230. //====================== Start SoC ================================
  4231. //idx_sample=10;
  4232. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4233. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  4234. {
  4235. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4236. {
  4237. tempIndex = ((gun_index==2) ? 1: 0);
  4238. }
  4239. else
  4240. {
  4241. tempIndex = gun_index;
  4242. }
  4243. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4244. {
  4245. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4246. {
  4247. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4248. {
  4249. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  4250. }
  4251. }
  4252. }
  4253. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4254. {
  4255. for (int index = 0; index < CCS_QUANTITY; index++)
  4256. {
  4257. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4258. {
  4259. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  4260. }
  4261. }
  4262. }
  4263. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4264. {
  4265. for (int index = 0; index < GB_QUANTITY; index++)
  4266. {
  4267. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4268. {
  4269. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  4270. }
  4271. }
  4272. }
  4273. else if(gunType[gun_index] == GUN_TYPE_DO)
  4274. {
  4275. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4276. {
  4277. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4278. {
  4279. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  4280. }
  4281. }
  4282. }
  4283. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4284. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  4285. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4286. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  4287. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  4288. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4289. } // END FOR DC CASE
  4290. //================================================ Message create ====================================================
  4291. json_object *StopTransaction = json_object_new_object();
  4292. json_object *transactionDatas = json_object_new_array();
  4293. json_object *sampledValues = json_object_new_array();
  4294. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  4295. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  4296. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  4297. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  4298. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  4299. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  4300. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  4301. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  4302. {
  4303. json_object *transactionData = json_object_new_object();
  4304. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  4305. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  4306. {
  4307. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  4308. {
  4309. json_object *sampledValue = json_object_new_object();
  4310. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  4311. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  4312. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  4313. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  4314. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  4315. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  4316. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  4317. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  4318. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  4319. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  4320. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  4321. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  4322. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  4323. json_object_array_add(sampledValues, sampledValue);
  4324. }
  4325. }
  4326. json_object_object_add(transactionData, "sampledValue", sampledValues);
  4327. json_object_array_add(transactionDatas, transactionData);
  4328. }
  4329. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  4330. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  4331. ,MESSAGE_TYPE_CALL
  4332. ,guid
  4333. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  4334. json_object_put(StopTransaction);
  4335. #if 1 // for TempStopTransaction
  4336. //Delete TempStopTransaction
  4337. if((access(TempStopTransaction,F_OK))!=-1)
  4338. {
  4339. remove(TempStopTransaction); // remove file "TempStopTransaction"
  4340. }
  4341. #endif
  4342. #if 1
  4343. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4344. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4345. {
  4346. result = PASS;
  4347. //DEBUG_INFO("StopTransaction mapitem pass\n");
  4348. }
  4349. #endif
  4350. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4351. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4352. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  4353. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  4354. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4355. {
  4356. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  4357. }
  4358. //for test
  4359. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4360. return result;
  4361. }
  4362. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  4363. {
  4364. mtrace();
  4365. int result = FAIL;
  4366. char guid[37]={0};
  4367. char tempdata[65]={0};
  4368. int tempIndex = 0;
  4369. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4370. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4371. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  4372. //set value
  4373. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4374. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (((strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging") != NULL) || (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "SuspendedEV") != NULL) || (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "SuspendedEVSE") != NULL) )?
  4375. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  4376. -1);
  4377. random_uuid(guid);
  4378. //UTC Date time
  4379. struct timeval tmnow;
  4380. struct tm *tm;
  4381. char buf[28];//, usec_buf[6];
  4382. gettimeofday(&tmnow, NULL);
  4383. time_t t;
  4384. t = time(NULL);
  4385. /*UTC time and date*/
  4386. tm = gmtime(&t);
  4387. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4388. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4389. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4390. //idx_sample=0;
  4391. //********************************(1)Current.Import L1************************************************/
  4392. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4393. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4394. {
  4395. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4396. {
  4397. tempIndex = ((gun_index==2) ? 1: 0);
  4398. }
  4399. else
  4400. {
  4401. tempIndex = gun_index;
  4402. }
  4403. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4404. {
  4405. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4406. {
  4407. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4408. }
  4409. }
  4410. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4411. }
  4412. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4413. {
  4414. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4415. {
  4416. tempIndex = ((gun_index==2) ? 1: 0);
  4417. }
  4418. else
  4419. {
  4420. tempIndex = gun_index;
  4421. }
  4422. for (int index = 0; index < CCS_QUANTITY; index++)
  4423. {
  4424. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4425. {
  4426. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4427. }
  4428. }
  4429. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4430. }
  4431. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4432. {
  4433. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4434. {
  4435. tempIndex = ((gun_index==2) ? 1: 0);
  4436. }
  4437. else
  4438. {
  4439. tempIndex = gun_index;
  4440. }
  4441. for (int index = 0; index < GB_QUANTITY; index++)
  4442. {
  4443. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4444. {
  4445. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4446. }
  4447. }
  4448. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4449. }
  4450. else if(gunType[gun_index] == GUN_TYPE_DO)
  4451. {
  4452. tempIndex = gun_index;
  4453. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4454. {
  4455. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4456. {
  4457. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  4458. }
  4459. }
  4460. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4461. }
  4462. else
  4463. {
  4464. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4465. {
  4466. tempIndex = 2;
  4467. }
  4468. else
  4469. {
  4470. tempIndex = gun_index;
  4471. }
  4472. for (int index = 0; index < AC_QUANTITY; index++)
  4473. {
  4474. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4475. {
  4476. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4477. }
  4478. }
  4479. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4480. }
  4481. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4482. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4483. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4484. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4485. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4486. //idx_sample=1;
  4487. //********************************(2)Energy.Active.Import.Register ************************************************/
  4488. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4489. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4490. {
  4491. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4492. {
  4493. tempIndex = ((gun_index==2) ? 1: 0);
  4494. }
  4495. else
  4496. {
  4497. tempIndex = gun_index;
  4498. }
  4499. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4500. {
  4501. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4502. {
  4503. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4504. }
  4505. }
  4506. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4507. }
  4508. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4509. {
  4510. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4511. {
  4512. tempIndex = ((gun_index==2) ? 1: 0);
  4513. }
  4514. else
  4515. {
  4516. tempIndex = gun_index;
  4517. }
  4518. for (int index = 0; index < CCS_QUANTITY; index++)
  4519. {
  4520. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4521. {
  4522. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4523. }
  4524. }
  4525. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4526. }
  4527. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4528. {
  4529. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4530. {
  4531. tempIndex = ((gun_index==2) ? 1: 0);
  4532. }
  4533. else
  4534. {
  4535. tempIndex = gun_index;
  4536. }
  4537. for (int index = 0; index < GB_QUANTITY; index++)
  4538. {
  4539. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4540. {
  4541. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4542. }
  4543. }
  4544. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4545. }
  4546. else if(gunType[gun_index] == GUN_TYPE_DO)
  4547. {
  4548. tempIndex = gun_index;
  4549. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4550. {
  4551. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4552. {
  4553. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  4554. }
  4555. }
  4556. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4557. }
  4558. else
  4559. {
  4560. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4561. {
  4562. tempIndex = 2;
  4563. }
  4564. else
  4565. {
  4566. tempIndex = gun_index;
  4567. }
  4568. for (int index = 0; index < AC_QUANTITY; index++)
  4569. {
  4570. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4571. {
  4572. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  4573. }
  4574. }
  4575. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4576. }
  4577. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  4578. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  4579. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  4580. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  4581. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4582. //idx_sample=2;
  4583. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  4584. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4585. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4586. {
  4587. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4588. {
  4589. tempIndex = ((gun_index==2) ? 1: 0);
  4590. }
  4591. else
  4592. {
  4593. tempIndex = gun_index;
  4594. }
  4595. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4596. {
  4597. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4598. {
  4599. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  4600. }
  4601. } // END OF FOR CHAdeMO_QUANTITY
  4602. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4603. }
  4604. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4605. {
  4606. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4607. {
  4608. tempIndex = ((gun_index==2) ? 1: 0);
  4609. }
  4610. else
  4611. {
  4612. tempIndex = gun_index;
  4613. }
  4614. for (int index = 0; index < CCS_QUANTITY; index++)
  4615. {
  4616. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4617. {
  4618. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  4619. }
  4620. } // END OF CCS_QUANTITY
  4621. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4622. }
  4623. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4624. {
  4625. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4626. {
  4627. tempIndex = ((gun_index==2) ? 1: 0);
  4628. }
  4629. else
  4630. {
  4631. tempIndex = gun_index;
  4632. }
  4633. for (int index = 0; index < GB_QUANTITY; index++)
  4634. {
  4635. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4636. {
  4637. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  4638. }
  4639. } // END OF GB_QUANTITY
  4640. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4641. }
  4642. else if(gunType[gun_index] == GUN_TYPE_DO)
  4643. {
  4644. tempIndex = gun_index;
  4645. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4646. {
  4647. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4648. {
  4649. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  4650. }
  4651. }
  4652. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4653. }
  4654. else
  4655. {
  4656. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4657. {
  4658. tempIndex = 2;
  4659. }
  4660. else
  4661. {
  4662. tempIndex = gun_index;
  4663. }
  4664. for (int index = 0; index < AC_QUANTITY; index++)
  4665. {
  4666. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4667. {
  4668. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  4669. }
  4670. }
  4671. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  4672. }
  4673. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  4674. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  4675. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  4676. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  4677. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4678. //idx_sample=3;
  4679. //********************************(4)Power.Active.Import************************************************/
  4680. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4681. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4682. {
  4683. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4684. {
  4685. tempIndex = ((gun_index==2) ? 1: 0);
  4686. }
  4687. else
  4688. {
  4689. tempIndex = gun_index;
  4690. }
  4691. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4692. {
  4693. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4694. {
  4695. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  4696. }
  4697. } // END OF FOR
  4698. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4699. }
  4700. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4701. {
  4702. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4703. {
  4704. tempIndex = ((gun_index==2) ? 1: 0);
  4705. }
  4706. else
  4707. {
  4708. tempIndex = gun_index;
  4709. }
  4710. for (int index = 0; index < CCS_QUANTITY; index++)
  4711. {
  4712. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4713. {
  4714. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  4715. }
  4716. }
  4717. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4718. }
  4719. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4720. {
  4721. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4722. {
  4723. tempIndex = ((gun_index==2) ? 1: 0);
  4724. }
  4725. else
  4726. {
  4727. tempIndex = gun_index;
  4728. }
  4729. for (int index = 0; index < GB_QUANTITY; index++)
  4730. {
  4731. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4732. {
  4733. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4734. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  4735. }
  4736. }
  4737. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4738. }
  4739. else if(gunType[gun_index] == GUN_TYPE_DO)
  4740. {
  4741. tempIndex = gun_index;
  4742. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4743. {
  4744. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4745. {
  4746. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4747. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  4748. }
  4749. }
  4750. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4751. }
  4752. else
  4753. {
  4754. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4755. {
  4756. tempIndex = 2;
  4757. }
  4758. else
  4759. {
  4760. tempIndex = gun_index;
  4761. }
  4762. for (int index = 0; index < AC_QUANTITY; index++)
  4763. {
  4764. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4765. {
  4766. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  4767. }
  4768. }
  4769. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  4770. }
  4771. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  4772. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  4773. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  4774. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  4775. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  4776. //idx_sample=4;
  4777. //***********************************************(5)VOLTAGE L1******************************************************/
  4778. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4779. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4780. {
  4781. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4782. {
  4783. tempIndex = ((gun_index==2) ? 1: 0);
  4784. }
  4785. else
  4786. {
  4787. tempIndex = gun_index;
  4788. }
  4789. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4790. {
  4791. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4792. {
  4793. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  4794. }
  4795. }
  4796. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4797. }
  4798. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4799. {
  4800. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4801. {
  4802. tempIndex = ((gun_index==2) ? 1: 0);
  4803. }
  4804. else
  4805. {
  4806. tempIndex = gun_index;
  4807. }
  4808. for (int index = 0; index < CCS_QUANTITY; index++)
  4809. {
  4810. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4811. {
  4812. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  4813. }
  4814. }
  4815. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4816. }
  4817. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4818. {
  4819. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4820. {
  4821. tempIndex = ((gun_index==2) ? 1: 0);
  4822. }
  4823. else
  4824. {
  4825. tempIndex = gun_index;
  4826. }
  4827. for (int index = 0; index < GB_QUANTITY; index++)
  4828. {
  4829. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4830. {
  4831. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  4832. }
  4833. }
  4834. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4835. }
  4836. else if(gunType[gun_index] == GUN_TYPE_DO)
  4837. {
  4838. tempIndex = gun_index;
  4839. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4840. {
  4841. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4842. {
  4843. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  4844. }
  4845. }
  4846. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4847. }
  4848. else
  4849. {
  4850. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4851. {
  4852. tempIndex = 2;
  4853. }
  4854. else
  4855. {
  4856. tempIndex = gun_index;
  4857. }
  4858. for (int index = 0; index < AC_QUANTITY; index++)
  4859. {
  4860. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4861. {
  4862. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  4863. }
  4864. }
  4865. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  4866. }
  4867. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  4868. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  4869. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  4870. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  4871. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4872. //***********************************************(6)SOC******************************************************/
  4873. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  4874. {
  4875. //idx_sample=5;
  4876. //sampledValue = NULL;
  4877. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4878. {
  4879. tempIndex = ((gun_index==2) ? 1: 0);
  4880. }
  4881. else
  4882. {
  4883. tempIndex = gun_index;
  4884. }
  4885. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4886. {
  4887. //tempIndex = ((gun_index==2) ? 1: 0);
  4888. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4889. {
  4890. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4891. {
  4892. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  4893. }
  4894. }
  4895. }
  4896. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4897. {
  4898. //tempIndex = ((gun_index==2) ? 1: 0);
  4899. for (int index = 0; index < CCS_QUANTITY; index++)
  4900. {
  4901. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4902. {
  4903. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  4904. }
  4905. }
  4906. }
  4907. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4908. {
  4909. //tempIndex = ((gun_index==2) ? 1: 0);
  4910. for (int index = 0; index < GB_QUANTITY; index++)
  4911. {
  4912. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4913. {
  4914. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  4915. }
  4916. }
  4917. }
  4918. else if(gunType[gun_index] == GUN_TYPE_DO)
  4919. {
  4920. //tempIndex = ((gun_index==2) ? 1: 0);
  4921. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4922. {
  4923. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4924. {
  4925. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  4926. }
  4927. }
  4928. }
  4929. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  4930. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  4931. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  4932. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  4933. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  4934. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  4935. }
  4936. //********************************(7)Current.Import L2************************************************/
  4937. // Only for AC 3 phase
  4938. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4939. {
  4940. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4941. {
  4942. tempIndex = 2;
  4943. }
  4944. else
  4945. {
  4946. tempIndex = gun_index;
  4947. }
  4948. for (int index = 0; index < AC_QUANTITY; index++)
  4949. {
  4950. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4951. {
  4952. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  4953. }
  4954. }
  4955. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  4956. }
  4957. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  4958. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  4959. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  4960. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  4961. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4962. //********************************(8)Current.Import L3************************************************/
  4963. // Only for AC 3 phase
  4964. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4965. {
  4966. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4967. {
  4968. tempIndex = 2;
  4969. }
  4970. else
  4971. {
  4972. tempIndex = gun_index;
  4973. }
  4974. for (int index = 0; index < AC_QUANTITY; index++)
  4975. {
  4976. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4977. {
  4978. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  4979. }
  4980. }
  4981. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  4982. }
  4983. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  4984. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  4985. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  4986. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  4987. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4988. //***********************************************(9)VOLTAGE L2******************************************************/
  4989. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4990. {
  4991. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4992. {
  4993. tempIndex = 2;
  4994. }
  4995. else
  4996. {
  4997. tempIndex = gun_index;
  4998. }
  4999. for (int index = 0; index < AC_QUANTITY; index++)
  5000. {
  5001. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5002. {
  5003. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  5004. }
  5005. }
  5006. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  5007. }
  5008. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  5009. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  5010. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  5011. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  5012. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5013. //***********************************************(10)VOLTAGE L3******************************************************/
  5014. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5015. {
  5016. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5017. {
  5018. tempIndex = 2;
  5019. }
  5020. else
  5021. {
  5022. tempIndex = gun_index;
  5023. }
  5024. for (int index = 0; index < AC_QUANTITY; index++)
  5025. {
  5026. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5027. {
  5028. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  5029. }
  5030. }
  5031. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  5032. }
  5033. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  5034. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  5035. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  5036. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  5037. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5038. // Message create ====================================================================================================
  5039. if(TRUE)
  5040. {
  5041. json_object *MeterValueReq = json_object_new_object();
  5042. json_object *MeterValues = json_object_new_array();
  5043. json_object *sampledValues = json_object_new_array();
  5044. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  5045. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  5046. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  5047. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  5048. {
  5049. json_object *MeterValue = json_object_new_object();
  5050. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  5051. {
  5052. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  5053. {
  5054. json_object *sampledValue = json_object_new_object();
  5055. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  5056. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  5057. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  5058. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  5059. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  5060. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  5061. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  5062. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  5063. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  5064. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  5065. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  5066. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  5067. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  5068. json_object_array_add(sampledValues, sampledValue);
  5069. }
  5070. }
  5071. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  5072. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  5073. json_object_array_add(MeterValues, MeterValue);
  5074. }
  5075. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  5076. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  5077. ,gun_index + 1
  5078. ,MESSAGE_TYPE_CALL
  5079. ,guid
  5080. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  5081. json_object_put(MeterValueReq);
  5082. }
  5083. // Put request guid to hash map
  5084. sprintf(tempdata, "MeterValues,%d", (gun_index));
  5085. 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*/)
  5086. {
  5087. result = PASS;
  5088. //DEBUG_INFO("MeterValues mapitem pass\n");
  5089. }
  5090. if((dataType != ReadingContext_Trigger) &&
  5091. (dataType != ReadingContext_Sample_Clock) &&
  5092. (ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1))
  5093. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  5094. else
  5095. {
  5096. if(FirstHeartBeat)
  5097. LWS_Send(queuedata +2);
  5098. }
  5099. return result;
  5100. }
  5101. //==========================================
  5102. // send confirm routine
  5103. //==========================================
  5104. int sendCancelReservationConfirmation(char *uuid,char *payload)
  5105. {
  5106. mtrace();
  5107. int result = FAIL;
  5108. char message[100]={0};
  5109. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  5110. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5111. LWS_Send(message);
  5112. result = TRUE;
  5113. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  5114. return result;
  5115. }
  5116. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  5117. {
  5118. mtrace();
  5119. int result = FAIL;
  5120. char message[100]={0};
  5121. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  5122. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5123. LWS_Send(message);
  5124. result = TRUE;
  5125. return result;
  5126. }
  5127. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  5128. {
  5129. mtrace();
  5130. int result = FAIL;
  5131. char message[100]={0};
  5132. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  5133. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5134. LWS_Send(message);
  5135. result = TRUE;
  5136. return result;
  5137. }
  5138. int sendClearCacheConfirmation(char *uuid,char *payload)
  5139. {
  5140. mtrace();
  5141. int result = FAIL;
  5142. char message[500]={0};
  5143. DEBUG_INFO("sendClearCacheConfirmation...\n");
  5144. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5145. LWS_Send(message);
  5146. return result;
  5147. }
  5148. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  5149. {
  5150. mtrace();
  5151. int result = FAIL;
  5152. char message[500]={0};
  5153. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  5154. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5155. LWS_Send(message);
  5156. return result;
  5157. }
  5158. int sendDataTransferConfirmation(char *uuid,char *payload)
  5159. {
  5160. mtrace();
  5161. char statusStr[20]={0};
  5162. char dataStr[10]={0};
  5163. char sstr[20]={0};
  5164. int c = 0;
  5165. char *loc;
  5166. int result = FAIL;
  5167. DEBUG_INFO("sendDataTransferConfirmation...\n");
  5168. /**********************status**************************/
  5169. loc = strstr(payload, "status");
  5170. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5171. c = 0;
  5172. while (loc[3+strlen("status")+c] != '\"')
  5173. {
  5174. sstr[c] = loc[3+strlen("status")+c];
  5175. c++;
  5176. }
  5177. sstr[c] = '\0';
  5178. strcpy(statusStr, sstr);
  5179. /**********************data**************************/
  5180. loc = strstr(payload, "data");
  5181. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5182. c = 0;
  5183. while (loc[3+strlen("data")+c] != '\"')
  5184. {
  5185. sstr[c] = loc[3+strlen("data")+c];
  5186. c++;
  5187. }
  5188. sstr[c] = '\0';
  5189. strcpy(dataStr, sstr);
  5190. return result;
  5191. }
  5192. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  5193. {
  5194. mtrace();
  5195. int result = FAIL;
  5196. char message[1000]={0};
  5197. int CompositeScheduleIndex = 0;
  5198. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  5199. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  5200. if(nPeriod == 0)
  5201. {
  5202. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  5203. {
  5204. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  5205. ,MESSAGE_TYPE_CALLRESULT
  5206. ,uuid
  5207. ,payload
  5208. ,connectorIdInt);
  5209. }
  5210. else
  5211. {
  5212. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  5213. ,MESSAGE_TYPE_CALLRESULT
  5214. ,uuid
  5215. ,payload
  5216. ,connectorIdInt
  5217. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5218. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5219. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5220. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  5221. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  5222. }
  5223. }
  5224. else
  5225. {
  5226. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  5227. ,MESSAGE_TYPE_CALLRESULT
  5228. ,uuid
  5229. ,payload
  5230. ,connectorIdInt
  5231. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5232. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5233. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5234. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  5235. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  5236. {
  5237. if (idx_sample == 0)
  5238. {
  5239. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5240. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5241. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5242. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5243. }
  5244. else
  5245. {
  5246. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5247. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5248. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5249. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5250. }
  5251. }
  5252. sprintf(message + strlen(message), "]}}]");
  5253. }
  5254. LWS_Send(message);
  5255. result = TRUE;
  5256. return result;
  5257. }
  5258. int sendGetConfigurationConfirmation(char *uuid)
  5259. {
  5260. mtrace();
  5261. int result = FAIL;
  5262. int MaxKeySupported = 0;
  5263. int sentConfigurationNumber= 0;
  5264. int sentunConfigurationNumber= 0;
  5265. char message[4000]={0};
  5266. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  5267. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  5268. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  5269. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  5270. ,MESSAGE_TYPE_CALLRESULT
  5271. ,uuid );
  5272. //configuration key
  5273. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  5274. {
  5275. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  5276. {
  5277. if (sentConfigurationNumber == 0)
  5278. {
  5279. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5280. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5281. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5282. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5283. }
  5284. else
  5285. {
  5286. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5287. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5288. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5289. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5290. }
  5291. sentConfigurationNumber = sentConfigurationNumber + 1;
  5292. }
  5293. }
  5294. sprintf(message + strlen(message), "]");
  5295. if(UnknownKeynum != 0)
  5296. {
  5297. sprintf(message + strlen(message), ",\"unknownKey\":[");
  5298. //unkown key
  5299. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  5300. {
  5301. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  5302. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  5303. if(sentunConfigurationNumber == 0)
  5304. {
  5305. sprintf(message + strlen(message), "\"%s\""
  5306. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5307. }
  5308. else
  5309. {
  5310. sprintf(message + strlen(message), ",\"%s\""
  5311. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5312. }
  5313. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  5314. }
  5315. sprintf(message + strlen(message), "]");
  5316. }
  5317. sprintf(message + strlen(message), "}]");
  5318. LWS_Send(message);
  5319. return result;
  5320. }
  5321. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  5322. {
  5323. mtrace();
  5324. int result = FAIL;
  5325. char message[400]={0};
  5326. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  5327. if(strcmp(payload,"")==0)
  5328. {
  5329. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5330. }
  5331. else
  5332. {
  5333. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5334. }
  5335. LWS_Send(message);
  5336. result = TRUE;
  5337. return result;
  5338. }
  5339. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  5340. {
  5341. mtrace();
  5342. int result = FAIL;
  5343. char message[80]={0};
  5344. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  5345. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  5346. LWS_Send(message);
  5347. result = TRUE;
  5348. return result;
  5349. }
  5350. int sendRemoteStartConfirmation(char *uuid,char *payload)
  5351. {
  5352. mtrace();
  5353. int result = FAIL;
  5354. char message[80]={0};
  5355. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  5356. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5357. LWS_Send(message);
  5358. result = TRUE;
  5359. return result;
  5360. }
  5361. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5362. {
  5363. mtrace();
  5364. int result = FAIL;
  5365. char message[80]={0};
  5366. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5367. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5368. LWS_Send(message);
  5369. result = TRUE;
  5370. return result;
  5371. }
  5372. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5373. {
  5374. mtrace();
  5375. int result = FAIL;
  5376. char message[80]={0};
  5377. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5378. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  5379. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5380. LWS_Send(message);
  5381. result = TRUE;
  5382. return result;
  5383. }
  5384. int sendResetConfirmation(char *uuid,char *payload)
  5385. {
  5386. mtrace();
  5387. int result = FAIL;
  5388. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  5389. char message[80]={0};
  5390. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  5391. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5392. LWS_Send(message);
  5393. result = TRUE;
  5394. return result;
  5395. }
  5396. int sendSendLocalListConfirmation(char *uuid,char *payload)
  5397. {
  5398. mtrace();
  5399. int result = FAIL;
  5400. char message[500]={0};
  5401. // [ 3, "1571284266109", { "status": "Accepted" } ]
  5402. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5403. LWS_Send(message);
  5404. result = TRUE;
  5405. return result;
  5406. }
  5407. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  5408. {
  5409. mtrace();
  5410. int result = FAIL;
  5411. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  5412. char message[80]={0};
  5413. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  5414. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5415. LWS_Send(message);
  5416. result = TRUE;
  5417. return result;
  5418. }
  5419. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  5420. {
  5421. mtrace();
  5422. int result = FAIL;
  5423. char message[80]={0};
  5424. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  5425. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5426. LWS_Send(message);
  5427. result = TRUE;
  5428. return result;
  5429. }
  5430. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  5431. {
  5432. mtrace();
  5433. int result = FAIL;
  5434. char message[80]={0};
  5435. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5436. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  5437. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5438. LWS_Send(message);
  5439. result = TRUE;
  5440. return result;
  5441. }
  5442. int sendUpdateFirmwareConfirmation(char *uuid)
  5443. {
  5444. mtrace();
  5445. int result = FAIL;
  5446. char message[60]={0};
  5447. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5448. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  5449. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5450. LWS_Send(message);
  5451. result = TRUE;
  5452. return result;
  5453. }
  5454. //==========================================
  5455. // send CallError routine
  5456. //==========================================
  5457. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  5458. {
  5459. mtrace();
  5460. char message[220]={0};
  5461. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  5462. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  5463. LWS_Send(message);
  5464. }
  5465. //==========================================
  5466. // Handle server request routine Start
  5467. //==========================================
  5468. int handleCancelReservationRequest(char *uuid, char *payload)
  5469. {
  5470. mtrace();
  5471. int result = FAIL;
  5472. int gunNO = 0;
  5473. int reservationIdInt = -1;
  5474. char comfirmstr[20];
  5475. DEBUG_INFO("handleCancelReservationRequest...\n");
  5476. json_object *CancelReservation;
  5477. CancelReservation = json_tokener_parse(payload);
  5478. if(!is_error(CancelReservation))
  5479. {
  5480. // Required data
  5481. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  5482. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  5483. }
  5484. json_object_put(CancelReservation);
  5485. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  5486. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5487. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  5488. if(reservationIdInt != -1)
  5489. {
  5490. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  5491. //check Transaction active
  5492. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5493. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5494. {
  5495. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  5496. {
  5497. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5498. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5499. if(gunType[2] == GUN_TYPE_CHAdeMO)
  5500. {
  5501. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  5502. }
  5503. else
  5504. {
  5505. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  5506. }
  5507. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5508. goto end;
  5509. }
  5510. }
  5511. for (int index = 0; index < CCS_QUANTITY; index++)
  5512. {
  5513. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  5514. {
  5515. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5516. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5517. if(gunType[2] == GUN_TYPE_CCS)
  5518. {
  5519. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  5520. }
  5521. else
  5522. {
  5523. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  5524. }
  5525. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5526. goto end;
  5527. }
  5528. }
  5529. for (int index = 0; index < GB_QUANTITY; index++)
  5530. {
  5531. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  5532. {
  5533. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5534. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5535. if(gunType[2] == GUN_TYPE_GBT)
  5536. {
  5537. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  5538. }
  5539. else
  5540. {
  5541. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  5542. }
  5543. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5544. goto end;
  5545. }
  5546. }
  5547. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5548. {
  5549. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  5550. {
  5551. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5552. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5553. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  5554. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5555. goto end;
  5556. }
  5557. }
  5558. for (int index = 0; index < AC_QUANTITY; index++)
  5559. {
  5560. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  5561. {
  5562. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5563. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5564. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5565. {
  5566. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  5567. }
  5568. else
  5569. {
  5570. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  5571. }
  5572. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5573. goto end;
  5574. }
  5575. }
  5576. }
  5577. //The reservationId does NOT match the reservationId
  5578. sendCancelReservationConfirmation(uuid, comfirmstr);
  5579. end:
  5580. // Fill in ocpp packet uuid
  5581. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  5582. return result;
  5583. }
  5584. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  5585. {
  5586. mtrace();
  5587. int result = FAIL;
  5588. int gunIndex = 0;
  5589. char typeStr[16]={0};
  5590. char comfirmstr[20];
  5591. int specificId = FALSE;
  5592. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  5593. json_object *ChangeAvailability;
  5594. ChangeAvailability = json_tokener_parse(payload);
  5595. if(!is_error(ChangeAvailability))
  5596. {
  5597. // Required data
  5598. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  5599. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  5600. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  5601. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  5602. }
  5603. json_object_put(ChangeAvailability);
  5604. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5605. {
  5606. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  5607. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  5608. }
  5609. else if(gunIndex == 0)
  5610. {
  5611. for(int i=0; i < gunTotalNumber; i++)
  5612. {
  5613. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  5614. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  5615. }
  5616. }
  5617. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5618. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5619. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  5620. {
  5621. specificId = TRUE;
  5622. }
  5623. if(specificId == FALSE)
  5624. goto end;
  5625. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  5626. {
  5627. //----------------------gunIndex is 0 ------------------------------------------------//
  5628. if(gunIndex == 0)
  5629. {
  5630. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5631. {
  5632. for(int i=0; i < gunTotalNumber; i++)
  5633. {
  5634. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5635. {
  5636. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  5637. {
  5638. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5639. {
  5640. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5641. goto end;
  5642. }
  5643. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5644. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5645. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5646. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5647. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5648. {
  5649. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5650. goto end;
  5651. }
  5652. }
  5653. }//END FOR CHAdeMO_QUANTITY
  5654. for (int index = 0; index < CCS_QUANTITY; index++)
  5655. {
  5656. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  5657. {
  5658. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  5659. {
  5660. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5661. goto end;
  5662. }
  5663. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5664. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5665. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5666. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5667. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5668. {
  5669. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5670. goto end;
  5671. }
  5672. }
  5673. }//END FOR CCS_QUANTITY
  5674. for (int index = 0; index < GB_QUANTITY; index++)
  5675. {
  5676. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  5677. {
  5678. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5679. {
  5680. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5681. goto end;
  5682. }
  5683. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5684. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5685. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5686. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5687. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5688. {
  5689. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5690. goto end;
  5691. }
  5692. }
  5693. }// END FOR GB_QUANTITY
  5694. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5695. {
  5696. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  5697. {
  5698. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5699. {
  5700. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5701. goto end;
  5702. }
  5703. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  5704. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  5705. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  5706. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  5707. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5708. {
  5709. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5710. goto end;
  5711. }
  5712. }
  5713. }// END FOR GENERAL_GUN_QUANTITY
  5714. for (int index = 0; index < AC_QUANTITY; index++)
  5715. {
  5716. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  5717. {
  5718. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5719. {
  5720. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5721. goto end;
  5722. }
  5723. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5724. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5725. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5726. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5727. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5728. {
  5729. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5730. goto end;
  5731. }
  5732. }
  5733. }//END FOR AC_QUANTITY
  5734. }// END FOR gunTotalNumber
  5735. }
  5736. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5737. {
  5738. for(int i=0; i < gunTotalNumber; i++)
  5739. {
  5740. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5741. {
  5742. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5743. goto end;
  5744. }
  5745. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5746. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  5747. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  5748. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  5749. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5750. {
  5751. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5752. goto end;
  5753. }
  5754. }
  5755. }
  5756. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5757. goto end;
  5758. }
  5759. //----------------------gunIndex is not 0 ------------------------------------------------//
  5760. //check Transaction active
  5761. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5762. {
  5763. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  5764. {
  5765. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  5766. {
  5767. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5768. goto end;
  5769. }
  5770. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5771. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5772. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5773. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5774. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5775. {
  5776. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5777. goto end;
  5778. }
  5779. else
  5780. {
  5781. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  5782. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5783. goto end;
  5784. }
  5785. }
  5786. }//END FOR CHAdeMO_QUANTITY
  5787. for (int index = 0; index < CCS_QUANTITY; index++)
  5788. {
  5789. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  5790. {
  5791. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  5792. {
  5793. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5794. goto end;
  5795. }
  5796. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5797. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5798. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5799. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5800. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5801. {
  5802. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5803. goto end;
  5804. }
  5805. else
  5806. {
  5807. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  5808. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5809. goto end;
  5810. }
  5811. }
  5812. }//END FOR CCS_QUANTITY
  5813. for (int index = 0; index < GB_QUANTITY; index++)
  5814. {
  5815. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  5816. {
  5817. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5818. {
  5819. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5820. goto end;
  5821. }
  5822. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5823. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5824. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5825. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5826. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5827. {
  5828. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5829. goto end;
  5830. }
  5831. else
  5832. {
  5833. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  5834. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5835. goto end;
  5836. }
  5837. }
  5838. }// END FOR GB_QUANTITY
  5839. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5840. {
  5841. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  5842. {
  5843. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5844. {
  5845. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5846. goto end;
  5847. }
  5848. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  5849. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  5850. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  5851. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  5852. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5853. {
  5854. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5855. goto end;
  5856. }
  5857. else
  5858. {
  5859. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  5860. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5861. goto end;
  5862. }
  5863. }
  5864. }// END FOR GENERAL_GUN_QUANTITY
  5865. for (int index = 0; index < AC_QUANTITY; index++)
  5866. {
  5867. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  5868. {
  5869. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5870. {
  5871. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5872. goto end;
  5873. }
  5874. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5875. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5876. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5877. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5878. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5879. {
  5880. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5881. goto end;
  5882. }
  5883. else
  5884. {
  5885. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  5886. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5887. goto end;
  5888. }
  5889. }
  5890. }//END FOR AC_QUANTITY
  5891. }//END FOR AvailabilityTypeStr[Inoperative]
  5892. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  5893. {
  5894. //----------------------gunIndex is 0 ------------------------------------------------//
  5895. if(gunIndex == 0)
  5896. {
  5897. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5898. {
  5899. for(int i=0; i < gunTotalNumber; i++)
  5900. {
  5901. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5902. {
  5903. if ((gunType[i] == GUN_TYPE_CHAdeMO )&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO)) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5904. {
  5905. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5906. goto end;
  5907. }
  5908. }//END FOR CHAdeMO_QUANTITY
  5909. for (int index = 0; index < CCS_QUANTITY; index++)
  5910. {
  5911. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT//(((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5912. {
  5913. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5914. goto end;
  5915. }
  5916. }//END FOR CCS_QUANTITY
  5917. for (int index = 0; index < GB_QUANTITY; index++)
  5918. {
  5919. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G')))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5920. {
  5921. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5922. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5923. goto end;
  5924. }
  5925. }// END FOR GB_QUANTITY
  5926. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5927. {
  5928. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'O')))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5929. {
  5930. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5931. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5932. goto end;
  5933. }
  5934. }// END FOR GENERAL_GUN_QUANTITY
  5935. for (int index = 0; index < AC_QUANTITY; index++)
  5936. {
  5937. if ((gunType[i] == GUN_TYPE_AC) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT // (((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5938. {
  5939. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5940. goto end;
  5941. }
  5942. }//END FOR CHAdeMO_QUANTITY
  5943. }// END FOR gunTotalNumber
  5944. }
  5945. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5946. {
  5947. for(int i=0; i < gunTotalNumber; i++)
  5948. {
  5949. for (int index = 0; index < AC_QUANTITY; index++)
  5950. {
  5951. if ((gunType[i] == GUN_TYPE_AC) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT // (((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5952. {
  5953. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5954. goto end;
  5955. }
  5956. }//END FOR CHAdeMO_QUANTITY
  5957. } // END FOR gunTotalNumber
  5958. }
  5959. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5960. goto end;
  5961. }
  5962. //----------------------gunIndex is not 0 ------------------------------------------------//
  5963. //check Transaction active
  5964. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5965. {
  5966. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5967. {
  5968. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5969. goto end;
  5970. }
  5971. }//END FOR CHAdeMO_QUANTITY
  5972. for (int index = 0; index < CCS_QUANTITY; index++)
  5973. {
  5974. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5975. {
  5976. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5977. goto end;
  5978. }
  5979. }//END FOR CCS_QUANTITY
  5980. for (int index = 0; index < GB_QUANTITY; index++)
  5981. {
  5982. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5983. {
  5984. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5985. goto end;
  5986. }
  5987. }// END FOR GB_QUANTITY
  5988. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5989. {
  5990. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5991. {
  5992. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5993. goto end;
  5994. }
  5995. }// END FOR GENERAL_GUN_QUANTITY
  5996. for (int index = 0; index < AC_QUANTITY; index++)
  5997. {
  5998. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5999. {
  6000. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6001. goto end;
  6002. }
  6003. }//END FOR AC_QUANTITY
  6004. }//END FOR AvailabilityTypeStr[Operative]
  6005. end:
  6006. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6007. {
  6008. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  6009. }
  6010. else
  6011. {
  6012. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  6013. }
  6014. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6015. {
  6016. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6017. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6018. }
  6019. else if(gunIndex == 0)
  6020. {
  6021. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6022. {
  6023. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  6024. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  6025. }
  6026. }
  6027. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  6028. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6029. return result;
  6030. }
  6031. int handleChangeConfigurationRequest(char *uuid, char *payload)
  6032. {
  6033. mtrace();
  6034. int result = FAIL;
  6035. char keystr[40]={0};
  6036. char valuestr[100]={0};
  6037. char comfirmstr[20]={0};
  6038. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  6039. json_object *ChangeConfiguration;
  6040. ChangeConfiguration = json_tokener_parse(payload);
  6041. if(!is_error(ChangeConfiguration))
  6042. {
  6043. // Required data
  6044. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  6045. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  6046. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  6047. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  6048. }
  6049. json_object_put(ChangeConfiguration);
  6050. if((uuid==NULL) || (payload ==NULL) )
  6051. {
  6052. DEBUG_ERROR("Payload is null\n");
  6053. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6054. }
  6055. else
  6056. {
  6057. int status = setKeyValue(keystr, valuestr);
  6058. switch(status)
  6059. {
  6060. case ConfigurationStatus_Accepted:
  6061. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  6062. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  6063. StoreConfigurationTable();
  6064. break;
  6065. case RebootRequired:
  6066. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  6067. StoreConfigurationTable();
  6068. break;
  6069. case NotSupported:
  6070. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  6071. break;
  6072. case ConfigurationStatus_Rejected:
  6073. default:
  6074. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6075. break;
  6076. }
  6077. }
  6078. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  6079. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  6080. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6081. {
  6082. ChageWebSocketPingInterval(atoi(valuestr));
  6083. }
  6084. if((strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6085. {
  6086. SetOcppConnStatus(FALSE);
  6087. }
  6088. return result;
  6089. }
  6090. int handleClearCacheRequest(char *uuid, char *payload)
  6091. {
  6092. mtrace();
  6093. int result = FAIL;
  6094. char comfirmstr[20];
  6095. char rmFileCmd[100]={0};
  6096. struct stat stats;
  6097. DEBUG_INFO("handleClearCacheRequest...\n");
  6098. stat("/Storage/OCPP", &stats);
  6099. // Check for directory existence
  6100. if (S_ISDIR(stats.st_mode) == 1)
  6101. {}
  6102. else
  6103. {
  6104. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  6105. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  6106. system(rmFileCmd);
  6107. }
  6108. if(OCPP_cleanLocalCache())
  6109. {
  6110. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  6111. }
  6112. else
  6113. {
  6114. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  6115. }
  6116. sendClearCacheConfirmation(uuid, comfirmstr);
  6117. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6118. return result;
  6119. }
  6120. int handleClearChargingProfileRequest(char *uuid, char *payload)
  6121. {
  6122. mtrace();
  6123. int result = FAIL;
  6124. int resultRename;
  6125. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  6126. char chargingProfilePurposeStr[26]={0};
  6127. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  6128. char tempchargingProfilePurposeStr[26]={0};
  6129. char str[100]={0};
  6130. char fname[200]={0};
  6131. char comfirmstr[20]={0};
  6132. char word[1600]={0};
  6133. int clearflag = FALSE;
  6134. int chargingProfileIdIsNULL = FALSE;
  6135. int connectorIsNULL = FALSE;
  6136. int chargingProfilePurposeIsNULL = FALSE;
  6137. int stackLevelIsNULL = FALSE;
  6138. //int GotoEnd = FALSE;
  6139. FILE *fptr1, *fptr2;
  6140. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  6141. int n_chargingProfile=0;
  6142. int isEmptyFile = FALSE;
  6143. char sLineWord[1600]={0};
  6144. char chargingProfiles[10][100]={0};
  6145. int ChargeProfileCount = 0;
  6146. int ch;
  6147. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  6148. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  6149. json_object *ClearChargingProfile;
  6150. ClearChargingProfile = json_tokener_parse(payload);
  6151. if(!is_error(ClearChargingProfile))
  6152. {
  6153. // Optional data
  6154. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  6155. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  6156. else
  6157. chargingProfileIdIsNULL = TRUE;
  6158. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  6159. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  6160. else
  6161. connectorIsNULL = TRUE;
  6162. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  6163. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  6164. else
  6165. chargingProfilePurposeIsNULL = TRUE;
  6166. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  6167. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  6168. else
  6169. stackLevelIsNULL = TRUE;
  6170. }
  6171. json_object_put(ClearChargingProfile);
  6172. if(connectorIsNULL == FALSE)
  6173. {
  6174. switch(connectorIdInt)
  6175. {
  6176. case 0:
  6177. if(chargingProfilePurposeIsNULL == TRUE)
  6178. {
  6179. int l = 0;
  6180. strcpy(fname, ChargePointMaxProfile_JSON);
  6181. if((access(fname,F_OK))!=-1)
  6182. {
  6183. strcpy(chargingProfiles[l], fname);
  6184. l = l + 1;
  6185. }
  6186. strcpy(fname, TxDefaultProfile_0_JSON);
  6187. if((access(fname,F_OK))!=-1)
  6188. {
  6189. strcpy(chargingProfiles[l], fname);
  6190. l = l + 1;
  6191. }
  6192. ChargeProfileCount = l;
  6193. }
  6194. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  6195. {
  6196. strcpy(fname, ChargePointMaxProfile_JSON);
  6197. if((access(fname,F_OK))!=-1)
  6198. {
  6199. strcpy(chargingProfiles[0], fname);
  6200. ChargeProfileCount = 1;
  6201. }
  6202. }
  6203. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6204. {
  6205. strcpy(fname, TxDefaultProfile_0_JSON);
  6206. if((access(fname,F_OK))!=-1)
  6207. {
  6208. strcpy(chargingProfiles[0], fname);
  6209. ChargeProfileCount = 1;
  6210. }
  6211. }
  6212. break;
  6213. default:
  6214. if(chargingProfilePurposeIsNULL == TRUE)
  6215. {
  6216. int m = 0;
  6217. memset(fname, 0, ARRAY_SIZE(fname));
  6218. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6219. if((access(fname,F_OK))!=-1)
  6220. {
  6221. strcpy(chargingProfiles[m], fname);
  6222. m = m + 1;
  6223. }
  6224. memset(fname, 0, ARRAY_SIZE(fname));
  6225. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6226. if((access(fname,F_OK))!=-1)
  6227. {
  6228. strcpy(chargingProfiles[m], fname);
  6229. m = m + 1;
  6230. }
  6231. ChargeProfileCount = m;
  6232. }
  6233. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6234. {
  6235. //strcpy(fname, TxDefaultProfile_1_JSON);
  6236. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6237. if((access(fname,F_OK))!=-1)
  6238. {
  6239. strcpy(chargingProfiles[0], fname);
  6240. ChargeProfileCount = 1;
  6241. }
  6242. }
  6243. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  6244. {
  6245. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6246. if((access(fname,F_OK))!=-1)
  6247. {
  6248. strcpy(chargingProfiles[0], fname);
  6249. ChargeProfileCount = 1;
  6250. }
  6251. //strcpy(fname, TxProfile_1_JSON);
  6252. }
  6253. //strcpy(fname, ChargePointMaxProfile_JSON );
  6254. break;
  6255. }
  6256. }
  6257. else // Check all Charging Profiles
  6258. {
  6259. int i = 0;
  6260. char fnametemp[200]={0};
  6261. ChargeProfileCount = 0;
  6262. //Check ChargePointMaxProfile.json exit
  6263. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  6264. {
  6265. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  6266. i = i + 1;
  6267. }
  6268. //Check TxDefaultProfile_0.json exit
  6269. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  6270. {
  6271. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  6272. i = i + 1;
  6273. }
  6274. //Check TxDefaultProfile_%d.json
  6275. for(int j=1; j <= gunTotalNumber; j++)
  6276. {
  6277. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6278. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  6279. if((access(fnametemp,F_OK))!=-1)
  6280. {
  6281. strcpy(chargingProfiles[i], fnametemp);
  6282. i = i + 1;
  6283. }
  6284. }
  6285. //Check TxProfile_%d.json
  6286. for(int j=1; j <= gunTotalNumber; j++)
  6287. {
  6288. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6289. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  6290. if((access(fnametemp,F_OK))!=-1)
  6291. {
  6292. strcpy(chargingProfiles[i], fnametemp);
  6293. i = i + 1;
  6294. }
  6295. }
  6296. ChargeProfileCount = i;
  6297. }// End connectorIsNULL is TRUE
  6298. if(ChargeProfileCount == 0)
  6299. {
  6300. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6301. goto end;
  6302. }
  6303. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  6304. {
  6305. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6306. goto end;
  6307. }
  6308. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  6309. {
  6310. memset(str, 0, ARRAY_SIZE(str));
  6311. // clear temp file
  6312. sprintf(str,"rm -f %s",temp);
  6313. system(str);
  6314. for(int k=0; k < ChargeProfileCount; k++)
  6315. {
  6316. memset(str, 0, ARRAY_SIZE(str));
  6317. //clear file in C
  6318. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6319. system(str);
  6320. }
  6321. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6322. goto end;
  6323. }
  6324. else if(connectorIsNULL == TRUE)
  6325. {
  6326. for(int k=0; k < ChargeProfileCount; k++)
  6327. {
  6328. fptr1 = fopen(chargingProfiles[k], "r");
  6329. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  6330. //Check Charging Profile Count
  6331. while(fscanf(fptr1, "%s", word) != EOF)
  6332. {
  6333. //DEBUG_INFO("word=%s\n",word);
  6334. if(strstr(word, "chargingProfileId")!= NULL)
  6335. {
  6336. //DEBUG_INFO("test chargingProfileId \n");
  6337. n_chargingProfile = n_chargingProfile + 1;
  6338. //DEBUG_INFO("chargingProfileId Found\n");
  6339. }
  6340. }
  6341. rewind(fptr1);
  6342. //search Charging Profile Element
  6343. //int i= 0;
  6344. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6345. {
  6346. json_object *tmpProfilee;
  6347. tmpProfilee = json_tokener_parse(sLineWord);
  6348. if(!is_error(tmpProfilee))
  6349. {
  6350. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  6351. {
  6352. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  6353. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  6354. }
  6355. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  6356. {
  6357. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  6358. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  6359. }
  6360. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  6361. {
  6362. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  6363. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  6364. }
  6365. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  6366. {
  6367. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  6368. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  6369. }
  6370. }
  6371. json_object_put(tmpProfilee);
  6372. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6373. {
  6374. //------- not write to fptr2-------//
  6375. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6376. //clearflag = TRUE;
  6377. }
  6378. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  6379. {
  6380. //------- not write to fptr2-------//
  6381. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6382. }
  6383. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6384. {
  6385. //------- not write to fptr2-------//
  6386. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6387. }
  6388. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  6389. {
  6390. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6391. }
  6392. else
  6393. {
  6394. fprintf(fptr2, sLineWord);//writing data into file
  6395. }
  6396. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6397. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6398. if(clearflag == TRUE)
  6399. {
  6400. fclose(fptr1);
  6401. fclose(fptr2);
  6402. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6403. system(str);
  6404. // clear temp file
  6405. sprintf(str,"rm -f %s",temp);
  6406. system(str);
  6407. }
  6408. else
  6409. {
  6410. fclose(fptr1);
  6411. fclose(fptr2);
  6412. memset(str, 0, ARRAY_SIZE(str));
  6413. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6414. system(str);
  6415. resultRename = rename(temp, chargingProfiles[k]);
  6416. if(resultRename == 0)
  6417. {
  6418. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  6419. }
  6420. else
  6421. {
  6422. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  6423. }
  6424. if(comfirmstr[0]== 0)
  6425. {
  6426. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6427. }
  6428. //Check chargingProfile is empty file
  6429. /*------ Read the file ----------------*/
  6430. fptr1=fopen(chargingProfiles[k],"r");
  6431. ch=fgetc(fptr1);
  6432. rewind(fptr1);
  6433. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6434. if(ch!=EOF)
  6435. {
  6436. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6437. {
  6438. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6439. if(sLineWord[0]=='\0')
  6440. {
  6441. isEmptyFile = TRUE;
  6442. break;
  6443. }
  6444. else
  6445. {
  6446. isEmptyFile = FALSE;
  6447. break;
  6448. }
  6449. }
  6450. }
  6451. else
  6452. isEmptyFile = TRUE;
  6453. fclose(fptr1);
  6454. if(isEmptyFile == TRUE)
  6455. {
  6456. memset(str, 0, ARRAY_SIZE(str));
  6457. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6458. system(str);
  6459. }
  6460. }
  6461. }// End of while(int k=0; k < ChargePointCount; k++)
  6462. }
  6463. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  6464. {
  6465. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  6466. for(int k=0; k < ChargeProfileCount; k++)
  6467. {
  6468. fptr1 = fopen(chargingProfiles[k], "r");
  6469. fptr2 = fopen(temp, "w+");
  6470. //Check Charging Profile Count
  6471. while(fscanf(fptr1, "%s", word) != EOF)
  6472. {
  6473. //DEBUG_INFO("word=%s\n",word);
  6474. if(strstr(word, "chargingProfileId")!= NULL)
  6475. {
  6476. n_chargingProfile = n_chargingProfile + 1;
  6477. }
  6478. }
  6479. rewind(fptr1);
  6480. //search Charging Profile Element
  6481. //int i= 0;
  6482. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6483. {
  6484. json_object *tmpProfilee;
  6485. tmpProfilee = json_tokener_parse(sLineWord);
  6486. if(!is_error(tmpProfilee))
  6487. {
  6488. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  6489. {
  6490. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  6491. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  6492. }
  6493. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  6494. {
  6495. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  6496. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  6497. }
  6498. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  6499. {
  6500. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  6501. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  6502. }
  6503. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  6504. {
  6505. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  6506. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  6507. }
  6508. }
  6509. json_object_put(tmpProfilee);
  6510. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6511. {
  6512. //------- not write to fptr2-------//
  6513. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6514. //clearflag = TRUE;
  6515. }
  6516. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6517. {
  6518. //------- not write to fptr2-------//
  6519. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6520. }
  6521. else if(stackLevelIsNULL == TRUE)
  6522. {
  6523. //Clear Whole File
  6524. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6525. clearflag = TRUE;
  6526. break;
  6527. }
  6528. else
  6529. {
  6530. fprintf(fptr2, sLineWord);//writing data into file
  6531. }
  6532. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6533. }
  6534. if(clearflag == TRUE)
  6535. {
  6536. fclose(fptr1);
  6537. fclose(fptr2);
  6538. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6539. system(str);
  6540. // clear temp file
  6541. sprintf(str,"rm -f %s",temp);
  6542. system(str);
  6543. }
  6544. else
  6545. {
  6546. fclose(fptr1);
  6547. fclose(fptr2);
  6548. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6549. system(str);
  6550. resultRename = rename(temp, chargingProfiles[k]);
  6551. if(resultRename == 0)
  6552. {
  6553. DEBUG_INFO("File ChargingProfile renamed successfully");
  6554. }
  6555. else
  6556. {
  6557. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6558. }
  6559. if(comfirmstr[0]== 0)
  6560. {
  6561. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6562. }
  6563. //Check chargingProfile is empty file
  6564. /*------ Read the file ----------------*/
  6565. fptr1=fopen(chargingProfiles[k],"r");
  6566. ch=fgetc(fptr1);
  6567. rewind(fptr1);
  6568. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6569. if(ch!=EOF)
  6570. {
  6571. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6572. {
  6573. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6574. if(sLineWord[0]=='\0')
  6575. {
  6576. isEmptyFile = TRUE;
  6577. break;
  6578. }
  6579. else
  6580. {
  6581. isEmptyFile = FALSE;
  6582. break;
  6583. }
  6584. }
  6585. }
  6586. else
  6587. isEmptyFile = TRUE;
  6588. fclose(fptr1);
  6589. if(isEmptyFile == TRUE)
  6590. {
  6591. memset(str, 0, ARRAY_SIZE(str));
  6592. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6593. system(str);
  6594. }
  6595. /*------- End of reading ---------------*/
  6596. }
  6597. } // while(int k=0; k < ChargeProfileCount; k++)
  6598. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  6599. end:
  6600. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  6601. {
  6602. if(connectorIdInt == 0)
  6603. {
  6604. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  6605. {
  6606. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  6607. }
  6608. }
  6609. else
  6610. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  6611. }
  6612. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  6613. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6614. return result;
  6615. }
  6616. void createFirmwareVersionByDataTransfer(void)
  6617. {
  6618. json_object *FirmwareDataTransfer = json_object_new_object();
  6619. // AC & DC model
  6620. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  6621. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  6622. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  6623. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  6624. // DC model
  6625. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O')
  6626. {
  6627. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  6628. {
  6629. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  6630. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  6631. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  6632. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  6633. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  6634. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  6635. }
  6636. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  6637. ((gunType[1] != GUN_TYPE_UNKNOWN) || (gunType[2] != GUN_TYPE_UNKNOWN) || (gunType[3] != GUN_TYPE_UNKNOWN)))
  6638. {
  6639. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  6640. }
  6641. }
  6642. else
  6643. {
  6644. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  6645. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  6646. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  6647. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  6648. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  6649. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  6650. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  6651. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  6652. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  6653. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  6654. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  6655. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  6656. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  6657. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  6658. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  6659. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  6660. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  6661. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  6662. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  6663. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  6664. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  6665. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  6666. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  6667. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  6668. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  6669. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  6670. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  6671. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  6672. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  6673. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  6674. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  6675. }
  6676. // 4G model
  6677. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  6678. {
  6679. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  6680. }
  6681. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  6682. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  6683. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  6684. json_object_put(FirmwareDataTransfer);
  6685. }
  6686. int handleDataTransferRequest(char *uuid, char *payload)
  6687. {
  6688. mtrace();
  6689. json_object *response = json_object_new_object();
  6690. int result = FAIL;
  6691. char tempvendorId[255]={0};
  6692. char tempmessageId[50]={0};
  6693. char tempdata[512]={0};
  6694. char message[2048]={0};
  6695. DEBUG_INFO("handleDataTransferRequest...\n");
  6696. if((uuid != NULL) && (payload != NULL))
  6697. {
  6698. json_object *DataTransfer;
  6699. DataTransfer = json_tokener_parse(payload);
  6700. if(!is_error(DataTransfer))
  6701. {
  6702. // Required data
  6703. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  6704. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  6705. // Optional data
  6706. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  6707. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  6708. if(json_object_object_get(DataTransfer, "data") != NULL)
  6709. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  6710. result = PASS;
  6711. }
  6712. json_object_put(DataTransfer);
  6713. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  6714. {
  6715. // Send all moudle firmware version on EVSE
  6716. createFirmwareVersionByDataTransfer();
  6717. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6718. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  6719. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6720. json_object_put(response);
  6721. }
  6722. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  6723. {
  6724. system("/usr/bin/run_tmate_restart.sh &");
  6725. }
  6726. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  6727. {
  6728. json_object *data;
  6729. data = json_tokener_parse(tempdata);
  6730. if(!is_error(data))
  6731. {
  6732. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  6733. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  6734. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  6735. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  6736. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  6737. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  6738. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  6739. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  6740. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  6741. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  6742. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6743. }
  6744. else
  6745. {
  6746. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6747. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6748. }
  6749. json_object_put(data);
  6750. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6751. json_object_put(response);
  6752. }
  6753. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  6754. {
  6755. json_object *data;
  6756. data = json_tokener_parse(tempdata);
  6757. if(!is_error(data))
  6758. {
  6759. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  6760. if(json_object_object_get(data, "idToken") != NULL)
  6761. {
  6762. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  6763. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  6764. }
  6765. if(json_object_object_get(data, "price") != NULL)
  6766. {
  6767. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  6768. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  6769. }
  6770. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6771. }
  6772. else
  6773. {
  6774. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6775. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6776. }
  6777. json_object_put(data);
  6778. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6779. json_object_put(response);
  6780. }
  6781. else if(strstr(tempmessageId, "RunningCost") != NULL)
  6782. {
  6783. json_object *data;
  6784. data = json_tokener_parse(tempdata);
  6785. if(!is_error(data))
  6786. {
  6787. if(json_object_object_get(data, "txId") != NULL)
  6788. {
  6789. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  6790. for(int idx = 0;idx<gunTotalNumber;idx++)
  6791. {
  6792. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  6793. {
  6794. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  6795. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  6796. if(json_object_object_get(data, "description") != NULL)
  6797. {
  6798. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  6799. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  6800. }
  6801. }
  6802. }
  6803. }
  6804. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6805. }
  6806. else
  6807. {
  6808. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6809. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6810. }
  6811. json_object_put(data);
  6812. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6813. json_object_put(response);
  6814. }
  6815. else if(strstr(tempmessageId, "FinalCost") != NULL)
  6816. {
  6817. json_object *data;
  6818. data = json_tokener_parse(tempdata);
  6819. if(!is_error(data))
  6820. {
  6821. if(json_object_object_get(data, "txId") != NULL)
  6822. {
  6823. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  6824. for(int idx = 0;idx<gunTotalNumber;idx++)
  6825. {
  6826. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  6827. {
  6828. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  6829. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  6830. if(json_object_object_get(data, "description") != NULL)
  6831. {
  6832. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  6833. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  6834. }
  6835. }
  6836. }
  6837. }
  6838. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6839. }
  6840. else
  6841. {
  6842. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6843. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6844. }
  6845. json_object_put(data);
  6846. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6847. json_object_put(response);
  6848. }
  6849. else
  6850. {
  6851. // Can not find valid message id
  6852. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  6853. }
  6854. }
  6855. else
  6856. {
  6857. // Payload is null
  6858. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  6859. }
  6860. LWS_Send(message);
  6861. return result;
  6862. }
  6863. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  6864. {
  6865. mtrace();
  6866. int result = FAIL;
  6867. int connectorIdInt, durationInt;
  6868. char chargingRateUnitStr[4]={0};
  6869. char comfirmstr[20];
  6870. int confirmPeriods = 0;
  6871. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  6872. json_object *GetCompositeSchedule;
  6873. GetCompositeSchedule = json_tokener_parse(payload);
  6874. if(!is_error(GetCompositeSchedule))
  6875. {
  6876. // Required data
  6877. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  6878. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  6879. else
  6880. connectorIdInt = -1;
  6881. if(json_object_object_get(GetCompositeSchedule, "duration"))
  6882. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  6883. else
  6884. durationInt = 86400;
  6885. // Optional data
  6886. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  6887. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  6888. }
  6889. json_object_put(GetCompositeSchedule);
  6890. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  6891. if((connectorIdInt == 0) ||
  6892. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  6893. {
  6894. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  6895. struct StructChargingProfile tmpProfile[1];
  6896. if(strstr(chargingRateUnitStr, "W") != NULL)
  6897. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  6898. else
  6899. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  6900. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6901. {
  6902. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6903. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6904. }
  6905. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  6906. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  6907. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  6908. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6909. {
  6910. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6911. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6912. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  6913. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0))
  6914. {
  6915. confirmPeriods = idx;
  6916. break;
  6917. }
  6918. }
  6919. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6920. }
  6921. else
  6922. {
  6923. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  6924. }
  6925. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  6926. return result;
  6927. }
  6928. int handleGetConfigurationRequest(char *uuid, char *payload)
  6929. {
  6930. mtrace();
  6931. int result = FAIL;
  6932. int MaxKeySupported = 0;
  6933. int n_keys = 0;
  6934. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  6935. DEBUG_INFO("handleGetConfigurationRequest...\n");
  6936. json_object *GetConfiguration;
  6937. GetConfiguration = json_tokener_parse(payload);
  6938. if(!is_error(GetConfiguration))
  6939. {
  6940. // Optional data
  6941. if(json_object_object_get(GetConfiguration, "key") != NULL)
  6942. {
  6943. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  6944. {
  6945. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  6946. n_keys = idx + 1;
  6947. }
  6948. }
  6949. }
  6950. json_object_put(GetConfiguration);
  6951. UnknownKeynum = 0;
  6952. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  6953. MaxKeySupported = GetConfigurationMaxKeysNUM;
  6954. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  6955. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  6956. if(n_keys != 0)
  6957. {
  6958. for(int i=0;i<n_keys;i++)
  6959. {
  6960. getKeyValue(requestKey[i]);
  6961. }
  6962. }
  6963. else
  6964. {
  6965. DEBUG_INFO("There is no key in Message, get all configuration\n");
  6966. getKeyValue("");
  6967. }
  6968. processUnkownKey();
  6969. sendGetConfigurationConfirmation(uuid);
  6970. return result;
  6971. }
  6972. static char fnamePlusPath[100]={0};
  6973. static char fnamePWithNoPath[60]={0};
  6974. void checkUploadLog(void)
  6975. {
  6976. FILE *fp;
  6977. /* Open the command for reading. */
  6978. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  6979. if (fp == NULL) {
  6980. printf("Failed to run command\n" );
  6981. exit(1);
  6982. }
  6983. int ftppathlen = 0;
  6984. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  6985. int i = 0;
  6986. /* Read the output a line at a time - output it. */
  6987. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  6988. if(i==0)
  6989. {
  6990. ftppathlen = strlen(fnamePlusPath);
  6991. printf("%s\n", fnamePlusPath);
  6992. fnamePlusPath[ftppathlen]='\0';
  6993. break;
  6994. }
  6995. i= i+1;
  6996. }
  6997. /* close */
  6998. pclose(fp);
  6999. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  7000. {
  7001. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  7002. {
  7003. fnamePlusPath[k]='\0';
  7004. }
  7005. }
  7006. i=1;
  7007. //char fname[60]={0};
  7008. while(i < ftppathlen)
  7009. {
  7010. int len=ftppathlen-i;
  7011. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  7012. {
  7013. printf("compare '/' all right\n");
  7014. break;
  7015. }
  7016. i=i+1;
  7017. }
  7018. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  7019. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  7020. fnamePWithNoPath[i+1] = '\0';
  7021. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  7022. {
  7023. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  7024. {
  7025. fnamePWithNoPath[j]='\0';
  7026. }
  7027. }
  7028. FILE* fp1 = fopen(fnamePlusPath, "r");
  7029. if (fp1)
  7030. {
  7031. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  7032. // file exists
  7033. fclose(fp1);
  7034. }
  7035. else
  7036. {
  7037. // file doesn't exist
  7038. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  7039. }
  7040. }
  7041. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  7042. {
  7043. mtrace();
  7044. int result = FAIL;
  7045. time_t CurrentTime;
  7046. struct tm *tm;
  7047. pthread_t th_Status;
  7048. CurrentTime = time(NULL);
  7049. tm = localtime(&CurrentTime);
  7050. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  7051. 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);
  7052. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  7053. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  7054. return result;
  7055. }
  7056. void* GetDiagnosticsProcess(void* data)
  7057. {
  7058. pthread_detach(pthread_self());
  7059. mtrace();
  7060. int retriesInt=0, retryIntervalInt=0;
  7061. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  7062. 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};
  7063. int port=0;
  7064. int isSuccess = FALSE;
  7065. char ftpbuf[200]={0};
  7066. char cmdBuf[2048];
  7067. struct tm *tmNow;
  7068. time_t CurrentTime;
  7069. struct tm tmStart;
  7070. struct tm tmStop;
  7071. CurrentTime = time(NULL);
  7072. tmNow=localtime(&CurrentTime);
  7073. uint16_t targetYear, targetMonth;
  7074. json_object *GetDiagnostics;
  7075. DEBUG_INFO("GetDiagnosticsProcess...\n");
  7076. GetDiagnostics = json_tokener_parse(data);
  7077. if(!is_error(GetDiagnostics))
  7078. {
  7079. // Required data
  7080. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  7081. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  7082. // Optional data
  7083. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  7084. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  7085. else
  7086. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  7087. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  7088. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  7089. else
  7090. retryIntervalInt = 30;
  7091. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  7092. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  7093. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  7094. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  7095. }
  7096. json_object_put(GetDiagnostics);
  7097. // Pack log to compress file
  7098. if((sscanf((char*)startTimestr, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  7099. (sscanf((char*)stopTimestr, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  7100. {
  7101. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/log.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  7102. targetYear = tmStart.tm_year;
  7103. targetMonth = tmStart.tm_mon;
  7104. do
  7105. {
  7106. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7107. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7108. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7109. if(targetMonth+1>=13)
  7110. {
  7111. targetYear += 1;
  7112. targetMonth = 1;
  7113. }
  7114. else
  7115. {
  7116. targetMonth += 1;
  7117. }
  7118. }while((targetYear < (tmNow->tm_year+1900)) ||
  7119. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  7120. sprintf(cmdBuf, "%s \t /Storage/ChargeLog/*.db", cmdBuf);
  7121. sprintf(cmdBuf, "%s \t /Storage/OCPP/*.db", cmdBuf);
  7122. sprintf(cmdBuf, "%s \t /Storage/EventLog/*.db", cmdBuf);
  7123. sprintf(cmdBuf, "%s \t /Storage/CCS*.zip", cmdBuf);
  7124. system(cmdBuf);
  7125. }
  7126. else
  7127. {
  7128. system("exec /root/logPackTools 'log' 6");
  7129. }
  7130. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  7131. system(cmdBuf);
  7132. checkUploadLog();
  7133. //****************location*******************/
  7134. if(strcmp(locationstr,"")==0)
  7135. {
  7136. DEBUG_INFO("location is <Empty>!\n");
  7137. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7138. goto end;
  7139. }
  7140. memset(protocol, 0, ARRAY_SIZE(protocol));
  7141. memset(user, 0, ARRAY_SIZE(user) );
  7142. memset(password, 0, ARRAY_SIZE(password));
  7143. memset(host, 0, ARRAY_SIZE(host));
  7144. memset(path, 0, ARRAY_SIZE(path));
  7145. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  7146. memset(host1, 0, ARRAY_SIZE(host1));
  7147. memset(path1, 0, ARRAY_SIZE(path1));
  7148. /*location: ftp://user:password@host:port/path*/
  7149. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  7150. if((access(fnamePlusPath,F_OK))!=-1)
  7151. {
  7152. DEBUG_INFO("fnamePlusPath exist.\n");
  7153. }
  7154. else
  7155. {
  7156. DEBUG_INFO("fnamePlusPath not exist!\n");
  7157. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7158. goto end;
  7159. }
  7160. if(strchr(locationstr,'@')==NULL)
  7161. {
  7162. sscanf(locationstr,
  7163. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  7164. protocol, host, &port, path);
  7165. strcpy(user,"anonymous");
  7166. strcpy(password,"");
  7167. }
  7168. else
  7169. {
  7170. //DEBUG_INFO("pch=%s\n", pch);
  7171. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  7172. protocol, user, password, host, &port, path);
  7173. }
  7174. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  7175. {
  7176. DEBUG_INFO("protocol is not ftp/http ! \n");
  7177. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7178. goto end;
  7179. }
  7180. if(strncmp(locationstr,"http", 4) == 0)
  7181. {
  7182. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  7183. sprintf(ftppath,"/%s", path);
  7184. do
  7185. {
  7186. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  7187. sleep(3);
  7188. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  7189. if(!isSuccess)
  7190. {
  7191. DEBUG_INFO("Diagnostics fail.\n");
  7192. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7193. sleep(retryIntervalInt);
  7194. }
  7195. else
  7196. {
  7197. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  7198. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  7199. }
  7200. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  7201. }
  7202. else
  7203. {
  7204. sscanf(host,"%[^/]%s",host1, path1);
  7205. sprintf(ftppath,"%s", path1);
  7206. int ftppathlen=strlen(ftppath);
  7207. int i=1;
  7208. char filenametemp[50];
  7209. while(i < ftppathlen)
  7210. {
  7211. int len=ftppathlen-i;
  7212. if(ftppath[len]== 47) // '/' ascll code: 47
  7213. {
  7214. DEBUG_INFO("find '/' all right\n");
  7215. break;
  7216. }
  7217. i=i+1;
  7218. }
  7219. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  7220. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  7221. filenametemp[i+1] = 0;
  7222. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  7223. if(port == 0)
  7224. port = 21;
  7225. do
  7226. {
  7227. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  7228. sleep(3);
  7229. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  7230. if(!isSuccess)
  7231. {
  7232. DEBUG_INFO("Diagnostics fail.\n");
  7233. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7234. sleep(retryIntervalInt);
  7235. }
  7236. else
  7237. {
  7238. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  7239. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  7240. }
  7241. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  7242. }
  7243. end:
  7244. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  7245. system("rm -f /mnt/*");
  7246. pthread_exit(NULL);
  7247. }
  7248. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  7249. {
  7250. mtrace();
  7251. int result = FAIL;
  7252. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  7253. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  7254. {
  7255. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  7256. localversion = -1;
  7257. }
  7258. else
  7259. {
  7260. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  7261. OCPP_getListVerion();
  7262. }
  7263. //from db.OCPP_getListVerion
  7264. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  7265. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  7266. sendGetLocalListVersionConfirmation(uuid,"");
  7267. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  7268. return result;
  7269. }
  7270. int handleRemoteStartRequest(char *uuid, char *payload)
  7271. {
  7272. mtrace();
  7273. int result = FAIL;
  7274. int connectorIdInt=0;
  7275. int tempIndex = 0;
  7276. int connectorIdIsNULL, chargingProfileIsNULL;
  7277. char comfirmstr[20]={0};
  7278. char cmdBuf[512];
  7279. json_object *RemoteStartTransaction;
  7280. FILE *fp;
  7281. DEBUG_INFO("handleRemoteStartRequest ...\n");
  7282. if(server_pending == TRUE)
  7283. {
  7284. return 0;
  7285. }
  7286. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  7287. RemoteStartTransaction = json_tokener_parse(payload);
  7288. if(!is_error(RemoteStartTransaction))
  7289. {
  7290. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  7291. {
  7292. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  7293. if(connectorIdInt <= gunTotalNumber)
  7294. {
  7295. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  7296. // Required data
  7297. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  7298. // Optional data
  7299. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  7300. {
  7301. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  7302. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  7303. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  7304. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  7305. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  7306. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  7307. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  7308. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  7309. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  7310. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  7311. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  7312. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  7313. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  7314. {
  7315. 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")));
  7316. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  7317. 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"));
  7318. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  7319. 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"));
  7320. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  7321. 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")));
  7322. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  7323. {
  7324. 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++)
  7325. {
  7326. 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"));
  7327. 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"));
  7328. 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)
  7329. 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"));
  7330. }
  7331. }
  7332. }
  7333. }
  7334. else
  7335. chargingProfileIsNULL = TRUE;
  7336. }
  7337. }
  7338. else
  7339. connectorIdIsNULL = TRUE;
  7340. }
  7341. else
  7342. connectorIdIsNULL = TRUE;
  7343. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  7344. {
  7345. DEBUG_WARN("Connector id is NULL\n.");
  7346. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7347. goto end;
  7348. }
  7349. /*
  7350. enum _SYSTEM_STATUS
  7351. {
  7352. S_BOOTING = 0,
  7353. S_IDLE, = 1
  7354. S_AUTHORIZING, = 2
  7355. S_REASSIGN_CHECK, = 3
  7356. S_REASSIGN, = 4
  7357. S_PRECHARGE, = 5
  7358. S_PREPARING_FOR_EV, = 6
  7359. S_PREPARING_FOR_EVSE, = 7
  7360. S_CHARGING, = 8
  7361. S_TERMINATING, = 9
  7362. S_COMPLETE, = 10
  7363. S_ALARM, = 11
  7364. S_FAULT = 12
  7365. }
  7366. */
  7367. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  7368. {
  7369. //check Transaction active
  7370. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  7371. {
  7372. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7373. {
  7374. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7375. }
  7376. else
  7377. {
  7378. tempIndex = connectorIdInt -1;
  7379. }
  7380. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7381. {
  7382. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  7383. {
  7384. 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))
  7385. {
  7386. //Reserved
  7387. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7388. }
  7389. 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))
  7390. {
  7391. //Reserved
  7392. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7393. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7394. goto end;
  7395. }
  7396. else
  7397. {
  7398. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7399. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  7400. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  7401. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  7402. {
  7403. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  7404. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7405. goto end;
  7406. }
  7407. }//END FOR ELSE
  7408. }
  7409. }// END FOR CHAdeMO_QUANTITY
  7410. }
  7411. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  7412. {
  7413. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7414. {
  7415. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7416. }
  7417. else
  7418. {
  7419. tempIndex = connectorIdInt -1;
  7420. }
  7421. for (int index = 0; index < CCS_QUANTITY; index++)
  7422. {
  7423. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7424. {
  7425. 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))
  7426. {
  7427. //Reserved
  7428. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7429. }
  7430. 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))
  7431. {
  7432. //Reserved
  7433. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7434. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7435. goto end;
  7436. }
  7437. else
  7438. {
  7439. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7440. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7441. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7442. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7443. {
  7444. DEBUG_WARN("CCS connector not allow start\n.");
  7445. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7446. goto end;
  7447. }
  7448. }// END FOR ELSE
  7449. }
  7450. }// END FOR CCS_QUANTITY
  7451. }
  7452. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  7453. {
  7454. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7455. {
  7456. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7457. }
  7458. else
  7459. {
  7460. tempIndex = connectorIdInt -1;
  7461. }
  7462. for (int index = 0; index < GB_QUANTITY; index++)
  7463. {
  7464. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  7465. {
  7466. 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))
  7467. {
  7468. //Reserved
  7469. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7470. }
  7471. 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))
  7472. {
  7473. //Reserved
  7474. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7475. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7476. goto end;
  7477. }
  7478. else
  7479. {
  7480. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7481. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7482. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7483. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7484. {
  7485. DEBUG_WARN("GB connector not allow start\n.");
  7486. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7487. goto end;
  7488. }
  7489. }// END FOR ELSE
  7490. }
  7491. } // END FOR GB_QUANTITY
  7492. }
  7493. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  7494. {
  7495. tempIndex = connectorIdInt -1;
  7496. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7497. {
  7498. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  7499. {
  7500. 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))
  7501. {
  7502. //Reserved
  7503. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7504. }
  7505. 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))
  7506. {
  7507. //Reserved
  7508. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7509. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7510. goto end;
  7511. }
  7512. else
  7513. {
  7514. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7515. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7516. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7517. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7518. {
  7519. DEBUG_WARN("GB connector not allow start\n.");
  7520. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7521. goto end;
  7522. }
  7523. }// END FOR ELSE
  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 = connectorIdInt -1;
  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].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  7542. {
  7543. //Reserved
  7544. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7545. }
  7546. 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))
  7547. {
  7548. //Reserved
  7549. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7550. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7551. goto end;
  7552. }
  7553. else
  7554. {
  7555. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7556. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7557. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7558. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7559. {
  7560. DEBUG_WARN("AC connector not allow start\n.");
  7561. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7562. goto end;
  7563. }
  7564. }//END FOR ELSE
  7565. }
  7566. }// END FOR AC_QUANTITY
  7567. }
  7568. if(chargingProfileIsNULL == FALSE)
  7569. {
  7570. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7571. {
  7572. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7573. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7574. //memset idTag
  7575. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7576. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7577. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7578. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7579. // Save profile to file
  7580. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7581. system(cmdBuf);
  7582. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7583. fp = fopen(cmdBuf, "w");
  7584. 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));
  7585. fclose(fp);
  7586. }
  7587. else
  7588. {
  7589. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  7590. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7591. }
  7592. }
  7593. else
  7594. {
  7595. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7596. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7597. //memset idTag
  7598. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7599. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7600. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7601. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7602. }
  7603. }
  7604. else
  7605. {
  7606. DEBUG_WARN("Connector id over\n.");
  7607. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7608. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7609. }
  7610. end:
  7611. json_object_put(RemoteStartTransaction);
  7612. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  7613. {
  7614. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  7615. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7616. }
  7617. //OCPP send RemoteStartConfirmation by first.
  7618. sendRemoteStartConfirmation(uuid, comfirmstr);
  7619. return result;
  7620. }
  7621. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  7622. {
  7623. mtrace();
  7624. int result = FAIL;
  7625. int match = FALSE;
  7626. int GunNO = 0;
  7627. int tempIndex = 0;
  7628. int transactionIdInt=0;
  7629. int transactionIdIsNULL= TRUE;
  7630. char comfirmstr[20];
  7631. json_object *RemoteStopTransaction;
  7632. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  7633. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  7634. if(server_pending == TRUE)
  7635. {
  7636. return 0;
  7637. }
  7638. RemoteStopTransaction = json_tokener_parse(payload);
  7639. if(!is_error(RemoteStopTransaction))
  7640. {
  7641. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  7642. {
  7643. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  7644. transactionIdIsNULL = FALSE;
  7645. }
  7646. }
  7647. json_object_put(RemoteStopTransaction);
  7648. if(transactionIdIsNULL == FALSE)
  7649. {
  7650. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  7651. {
  7652. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  7653. {
  7654. //check Transaction active
  7655. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7656. {
  7657. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7658. {
  7659. tempIndex = ((gun_index==2) ? 1: 0);
  7660. }
  7661. else
  7662. {
  7663. tempIndex = gun_index;
  7664. }
  7665. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7666. {
  7667. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7668. {
  7669. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7670. {
  7671. match = TRUE;
  7672. GunNO = gun_index;
  7673. }
  7674. }
  7675. }// END FOR CHAdeMO_QUANTITY
  7676. }
  7677. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7678. {
  7679. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7680. {
  7681. tempIndex = ((gun_index==2) ? 1: 0);
  7682. }
  7683. else
  7684. {
  7685. tempIndex = gun_index;
  7686. }
  7687. for (int index = 0; index < CCS_QUANTITY; index++)
  7688. {
  7689. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7690. {
  7691. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7692. {
  7693. match = TRUE;
  7694. GunNO = gun_index;
  7695. }
  7696. }
  7697. }// END FOR CCS_QUANTITY
  7698. }
  7699. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7700. {
  7701. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7702. {
  7703. tempIndex = ((gun_index==2) ? 1: 0);
  7704. }
  7705. else
  7706. {
  7707. tempIndex = gun_index;
  7708. }
  7709. for (int index = 0; index < GB_QUANTITY; index++)
  7710. {
  7711. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7712. {
  7713. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7714. {
  7715. match = TRUE;
  7716. GunNO = gun_index;
  7717. }
  7718. }
  7719. }// END FOR GB_QUANTITY
  7720. }
  7721. else if(gunType[gun_index] == GUN_TYPE_DO)
  7722. {
  7723. tempIndex = gun_index;
  7724. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7725. {
  7726. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7727. {
  7728. 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
  7729. {
  7730. match = TRUE;
  7731. GunNO = gun_index;
  7732. }
  7733. }
  7734. }// END FOR GB_QUANTITY
  7735. }
  7736. else
  7737. {
  7738. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7739. {
  7740. tempIndex = 2;
  7741. }
  7742. else
  7743. {
  7744. tempIndex = gun_index;
  7745. }
  7746. for (int index = 0; index < AC_QUANTITY; index++)
  7747. {
  7748. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7749. {
  7750. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7751. {
  7752. match = TRUE;
  7753. GunNO = gun_index;
  7754. }
  7755. }
  7756. }// END FOR CHAdeMO_QUANTITY
  7757. } // END FOR AC ELSE
  7758. }// CHECK IF ResponseTransactionId == transactionIdInt
  7759. }//END FOR
  7760. if( match == TRUE)
  7761. {
  7762. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  7763. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7764. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  7765. }
  7766. else
  7767. {
  7768. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7769. }
  7770. }
  7771. else
  7772. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7773. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  7774. return result;
  7775. }
  7776. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  7777. {
  7778. mtrace();
  7779. int result = FAIL;
  7780. int connectorIdInt=0, reservationIdInt=0;
  7781. int tempIndex = 0;
  7782. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  7783. char comfirmstr[20]={0};
  7784. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  7785. int c = 0;
  7786. char *loc;
  7787. //char *ptr;
  7788. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  7789. strcpy(sstrtemp, stringtrimspace(payload));
  7790. //***(1)connectorId ****/
  7791. c=0;
  7792. loc = strstr(sstrtemp, "connectorId");
  7793. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7794. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  7795. {
  7796. sstr[c] = loc[strlen("connectorId")+2+c];
  7797. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7798. c++;
  7799. }
  7800. sstr[c] = '\0';
  7801. connectorIdInt = atoi(sstr);
  7802. //***(2)expiryDate ****/
  7803. loc = strstr(sstrtemp, "expiryDate");
  7804. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7805. c = 0;
  7806. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  7807. {
  7808. sstr[c] = loc[3+strlen("expiryDate")+c];
  7809. c++;
  7810. }
  7811. sstr[c] = '\0';
  7812. strcpy(expiryDatestr, sstr);
  7813. //***(3)idTag ****/
  7814. loc = strstr(sstrtemp, "idTag");
  7815. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7816. c = 0;
  7817. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  7818. {
  7819. sstr[c] = loc[3+strlen("idTag")+c];
  7820. c++;
  7821. }
  7822. sstr[c] = '\0';
  7823. strcpy(idTagstr, sstr);
  7824. //***(4)parentIdTag ****/
  7825. loc = strstr(sstrtemp, "parentIdTag");
  7826. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7827. c = 0;
  7828. if(loc == NULL)
  7829. {
  7830. strcpy(parentIdTagstr, "");
  7831. }
  7832. else
  7833. {
  7834. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  7835. {
  7836. sstr[c] = loc[3+strlen("parentIdTag")+c];
  7837. c++;
  7838. }
  7839. sstr[c] = '\0';
  7840. strcpy(parentIdTagstr, sstr);
  7841. }
  7842. //***(5)reservationId ****/
  7843. c=0;
  7844. loc = strstr(sstrtemp, "reservationId");
  7845. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7846. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  7847. {
  7848. sstr[c] = loc[strlen("reservationId")+2+c];
  7849. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7850. c++;
  7851. }
  7852. sstr[c] = '\0';
  7853. reservationIdInt = atoi(sstr);
  7854. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7855. /*
  7856. enum SYSTEM_STATUS
  7857. {
  7858. SYS_MODE_BOOTING = 0,
  7859. SYS_MODE_IDLE = 1,
  7860. SYS_MODE_AUTHORIZING = 2,
  7861. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  7862. SYS_MODE_REASSIGN = 4,
  7863. SYS_MODE_PREPARING = 5,
  7864. SYS_MODE_PREPARE_FOR_EV = 6,
  7865. SYS_MODE_PREPARE_FOR_EVSE = 7,
  7866. SYS_MODE_CHARGING = 8,
  7867. SYS_MODE_TERMINATING = 9,
  7868. SYS_MODE_COMPLETE = 10,
  7869. SYS_MODE_ALARM = 11,
  7870. SYS_MODE_FAULT = 12,
  7871. SYS_MODE_RESERVATION = 13,
  7872. SYS_MODE_BOOKING = 14,
  7873. SYS_MODE_MAINTAIN = 15,
  7874. SYS_MODE_DEBUG = 16,
  7875. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  7876. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  7877. SYS_MODE_UPDATE = 19
  7878. };
  7879. */
  7880. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  7881. {
  7882. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7883. goto end;
  7884. }
  7885. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  7886. {
  7887. //check Transaction active
  7888. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  7889. {
  7890. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7891. {
  7892. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7893. }
  7894. else
  7895. {
  7896. tempIndex = connectorIdInt -1;
  7897. }
  7898. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7899. {
  7900. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7901. {
  7902. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7903. {
  7904. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7905. {
  7906. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7907. {
  7908. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7909. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7910. }
  7911. 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'))
  7912. {
  7913. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7914. }
  7915. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7916. {
  7917. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7918. }
  7919. else
  7920. {
  7921. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7922. }
  7923. }
  7924. 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
  7925. {
  7926. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7927. }
  7928. }
  7929. else
  7930. {
  7931. //replace reservation
  7932. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7933. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7934. }
  7935. }
  7936. } // END FOR CHAdeMO_QUANTITY
  7937. }
  7938. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  7939. {
  7940. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7941. {
  7942. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7943. }
  7944. else
  7945. {
  7946. tempIndex = connectorIdInt -1;
  7947. }
  7948. for (int index = 0; index < CCS_QUANTITY; index++)
  7949. {
  7950. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7951. {
  7952. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7953. {
  7954. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7955. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7956. {
  7957. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7958. {
  7959. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7960. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7961. }
  7962. 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'))
  7963. {
  7964. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7965. }
  7966. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  7967. {
  7968. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7969. }
  7970. else
  7971. {
  7972. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7973. }
  7974. }
  7975. 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
  7976. {
  7977. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7978. }
  7979. }
  7980. else
  7981. {
  7982. //replace reservation
  7983. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7984. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7985. }
  7986. }
  7987. } // END FOR CCS_QUANTITY
  7988. }
  7989. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  7990. {
  7991. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7992. {
  7993. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7994. }
  7995. else
  7996. {
  7997. tempIndex = connectorIdInt -1;
  7998. }
  7999. for (int index = 0; index < GB_QUANTITY; index++)
  8000. {
  8001. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8002. {
  8003. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8004. {
  8005. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8006. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  8007. {
  8008. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8009. {
  8010. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8011. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8012. }
  8013. 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'))
  8014. {
  8015. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8016. }
  8017. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8018. {
  8019. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8020. }
  8021. else
  8022. {
  8023. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8024. }
  8025. }
  8026. 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
  8027. {
  8028. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8029. }
  8030. }
  8031. else
  8032. {
  8033. //replace reservation
  8034. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8035. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8036. }
  8037. }
  8038. }// END FOR GB_QUANTITY
  8039. }
  8040. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8041. {
  8042. tempIndex = connectorIdInt -1;
  8043. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8044. {
  8045. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8046. {
  8047. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  8048. {
  8049. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8050. 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
  8051. {
  8052. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8053. {
  8054. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8055. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8056. }
  8057. 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'))
  8058. {
  8059. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8060. }
  8061. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8062. {
  8063. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8064. }
  8065. else
  8066. {
  8067. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8068. }
  8069. }
  8070. 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
  8071. {
  8072. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8073. }
  8074. }
  8075. else
  8076. {
  8077. //replace reservation
  8078. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8079. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8080. }
  8081. }
  8082. }// END FOR GB_QUANTITY
  8083. }
  8084. else
  8085. {
  8086. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8087. {
  8088. tempIndex = 2;
  8089. }
  8090. else
  8091. {
  8092. tempIndex = (connectorIdInt -1);
  8093. }
  8094. for (int index = 0; index < AC_QUANTITY; index++)
  8095. {
  8096. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8097. {
  8098. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  8099. {
  8100. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  8101. {
  8102. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8103. {
  8104. 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))
  8105. {
  8106. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8107. }
  8108. else
  8109. {
  8110. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8111. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8112. }
  8113. }
  8114. 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'))
  8115. {
  8116. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8117. }
  8118. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8119. {
  8120. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8121. }
  8122. else
  8123. {
  8124. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8125. }
  8126. }
  8127. 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
  8128. {
  8129. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8130. }
  8131. }
  8132. else
  8133. {
  8134. //replace reservation
  8135. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8136. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8137. }
  8138. }
  8139. } // END FOR AC_QUANTITY
  8140. }
  8141. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8142. }
  8143. else if(connectorIdInt == 0)
  8144. {
  8145. //check Transaction active
  8146. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8147. {
  8148. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  8149. {
  8150. 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'))
  8151. {
  8152. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8153. goto end;
  8154. }
  8155. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8156. {
  8157. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8158. goto end;
  8159. }
  8160. 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
  8161. {
  8162. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8163. goto end;
  8164. }
  8165. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8166. {
  8167. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8168. goto end;
  8169. }
  8170. }
  8171. }// END FOR CHAdeMO_QUANTITY
  8172. for (int index = 0; index < CCS_QUANTITY; index++)
  8173. {
  8174. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8175. {
  8176. 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'))
  8177. {
  8178. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8179. goto end;
  8180. }
  8181. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  8182. {
  8183. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8184. goto end;
  8185. }
  8186. 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
  8187. {
  8188. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8189. goto end;
  8190. }
  8191. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8192. {
  8193. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8194. goto end;
  8195. }
  8196. }
  8197. } // END FOR CCS_QUANTITY
  8198. for (int index = 0; index < GB_QUANTITY; index++)
  8199. {
  8200. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8201. {
  8202. 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'))
  8203. {
  8204. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8205. goto end;
  8206. }
  8207. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8208. {
  8209. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8210. goto end;
  8211. }
  8212. 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
  8213. {
  8214. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8215. goto end;
  8216. }
  8217. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8218. {
  8219. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8220. goto end;
  8221. }
  8222. }
  8223. } // END FOR GB_QUANTITY
  8224. for (int index = 0; index < AC_QUANTITY; index++)
  8225. {
  8226. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  8227. {
  8228. 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'))
  8229. {
  8230. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8231. goto end;
  8232. }
  8233. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8234. {
  8235. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8236. goto end;
  8237. }
  8238. 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
  8239. {
  8240. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8241. goto end;
  8242. }
  8243. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8244. {
  8245. 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))
  8246. {
  8247. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8248. goto end;
  8249. }
  8250. }
  8251. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8252. {
  8253. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8254. goto end;
  8255. }
  8256. }
  8257. }// END FOR AC_QUANTITY
  8258. //The connectorId is 0
  8259. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  8260. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8261. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  8262. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  8263. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  8264. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  8265. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  8266. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  8267. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  8268. result = TRUE;
  8269. return result;
  8270. }
  8271. else
  8272. {
  8273. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8274. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8275. }
  8276. if(strcmp(comfirmstr,"Accepted") == 0)
  8277. {
  8278. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  8279. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  8280. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  8281. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  8282. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  8283. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  8284. result = TRUE;
  8285. return result;
  8286. }
  8287. end:
  8288. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  8289. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  8290. return result;
  8291. }
  8292. int handleResetRequest(char *uuid, char *payload)
  8293. {
  8294. mtrace();
  8295. int result = FAIL;
  8296. char sstr[10]={0},sstrtemp[30]={ 0 };
  8297. char typestr[10]={0};
  8298. char comfirmstr[20]={0};
  8299. int c = 0;
  8300. char *loc;
  8301. DEBUG_INFO("handleResetRequest...\n");
  8302. strcpy(sstrtemp, stringtrimspace(payload));
  8303. loc = strstr(sstrtemp, "type");
  8304. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8305. c = 0;
  8306. while (loc[3+strlen("type")+c] != '\"')
  8307. {
  8308. sstr[c] = loc[3+strlen("type")+c];
  8309. c++;
  8310. }
  8311. sstr[c] = '\0';
  8312. strcpy(typestr,sstr);
  8313. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  8314. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  8315. {
  8316. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  8317. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  8318. result = TRUE;
  8319. return result;
  8320. }
  8321. else
  8322. {
  8323. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  8324. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  8325. goto errorend;
  8326. }
  8327. errorend:
  8328. sendResetConfirmation(uuid, comfirmstr);
  8329. return result;
  8330. }
  8331. int handleSendLocalListRequest(char *uuid, char *payload)
  8332. {
  8333. mtrace();
  8334. int result = FAIL;
  8335. int listVersionInt;
  8336. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  8337. char listsearch[]="listVersion";
  8338. char updateTypesearch[]="updateType";
  8339. char localAuthorizationListsearch[]="localAuthorizationList";
  8340. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  8341. char CardList[500][160]={0};
  8342. char updateTypestr[15]={0};
  8343. char idTagstr[20]={0};
  8344. char parentIdTag[20]={0};
  8345. char expiryDate[30]={0};
  8346. char idTagstatus[16]={0};
  8347. int c = 0;
  8348. int i = 0;
  8349. char *delim1 = "}";
  8350. char * pch;
  8351. char *loc;
  8352. //char *ptr;
  8353. char comfirmstr[20];
  8354. //int n_localAuthorizations = 0;
  8355. int checkState_Faulted = FALSE;
  8356. DEBUG_INFO("handleSendLocalListRequest...\n");
  8357. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  8358. {
  8359. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8360. goto end;
  8361. }
  8362. //check Charge Point state
  8363. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8364. {
  8365. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8366. {
  8367. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8368. }
  8369. }
  8370. for (int index = 0; index < CCS_QUANTITY; index++)
  8371. {
  8372. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8373. {
  8374. checkState_Faulted = TRUE; //OCPP Status
  8375. }
  8376. }
  8377. for (int index = 0; index < GB_QUANTITY; index++)
  8378. {
  8379. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8380. {
  8381. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8382. }
  8383. }
  8384. //check Charge Point state
  8385. for (int index = 0; index < AC_QUANTITY; index++)
  8386. {
  8387. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8388. {
  8389. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8390. }
  8391. }
  8392. if(checkState_Faulted == TRUE)
  8393. {
  8394. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8395. goto end;
  8396. }
  8397. //Filter payload space
  8398. strcpy(sstrtemp, stringtrimspace(payload));
  8399. //listVersion
  8400. c = 0;
  8401. loc = strstr(sstrtemp, listsearch);
  8402. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  8403. {
  8404. sstr[c] = loc[strlen("listVersion")+2+c];
  8405. c++;
  8406. }
  8407. sstr[c] = '\0';
  8408. listVersionInt = atoi(sstr);
  8409. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8410. //updateType
  8411. loc = strstr(sstrtemp, updateTypesearch);
  8412. c = 0;
  8413. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  8414. {
  8415. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  8416. c++;
  8417. }
  8418. sstr[c] = '\0';
  8419. strcpy(updateTypestr, sstr);
  8420. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  8421. //localAuthorizationList
  8422. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8423. loc = strstr(sstrtemp, localAuthorizationListsearch);
  8424. if(loc != NULL) // localAuthorizationList is not NULL
  8425. {
  8426. //Check UpdateType
  8427. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8428. {
  8429. //Local list full update
  8430. printf("Local list full update.\n");
  8431. OCPP_getListVerion();
  8432. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8433. {
  8434. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8435. goto end;
  8436. }
  8437. OCPP_cleanLocalList();
  8438. }
  8439. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8440. {
  8441. //Local list different update
  8442. printf("Local list different update.\n");
  8443. OCPP_getListVerion();
  8444. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8445. {
  8446. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  8447. goto end;
  8448. }
  8449. }
  8450. else
  8451. {
  8452. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8453. goto end;
  8454. }
  8455. c = 0;
  8456. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  8457. {
  8458. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  8459. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8460. c++;
  8461. }
  8462. sstr[c] = '\0';
  8463. //DEBUG_INFO("sstr=%s\n", sstr);
  8464. //parsing strings to words
  8465. i = 0;
  8466. pch = strtok(sstr,delim1);
  8467. while (pch != NULL)
  8468. {
  8469. strcpy(CardList[i], pch);
  8470. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  8471. pch = strtok (NULL, delim1);
  8472. i = i + 1;
  8473. }
  8474. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  8475. //local Authorizations List Numbers
  8476. //n_localAuthorizations = i;
  8477. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8478. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  8479. c= 0;
  8480. while(c < i) // i is CardList Number
  8481. {
  8482. //Search "IdToken"
  8483. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8484. loc = strstr(CardList[c], "idTag");
  8485. int j = 0;
  8486. while (loc[3+strlen("idTag")+j] != '\"')
  8487. {
  8488. sstr[j] = loc[3+strlen("idTag")+j];
  8489. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8490. j++;
  8491. }
  8492. sstr[j] = '\0';
  8493. strcpy(idTagstr, sstr);
  8494. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  8495. //Search "expiryDate"
  8496. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8497. loc = strstr(CardList[c], "expiryDate");
  8498. j = 0;
  8499. if(loc != NULL)
  8500. {
  8501. while (loc[3+strlen("expiryDate")+j] != '\"')
  8502. {
  8503. sstr[j] = loc[3+strlen("expiryDate")+j];
  8504. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8505. j++;
  8506. }
  8507. sstr[j] = '\0';
  8508. strcpy(expiryDate, sstr);
  8509. }
  8510. else
  8511. {
  8512. strcpy(expiryDate, "");
  8513. }
  8514. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  8515. //Search "parentIdTag"
  8516. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8517. loc = strstr(CardList[c], "parentIdTag");
  8518. j = 0;
  8519. if(loc != NULL)
  8520. {
  8521. while (loc[3+strlen("parentIdTag")+j] != '\"')
  8522. {
  8523. sstr[j] = loc[3+strlen("parentIdTag")+j];
  8524. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8525. j++;
  8526. }
  8527. sstr[j] = '\0';
  8528. strcpy(parentIdTag, sstr);
  8529. }
  8530. else
  8531. {
  8532. strcpy(parentIdTag, "");
  8533. }
  8534. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  8535. //Search "status"
  8536. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8537. loc = strstr(CardList[c], "status");
  8538. j = 0;
  8539. while (loc[3+strlen("status")+j] != '\"')
  8540. {
  8541. sstr[j] = loc[3+strlen("status")+j];
  8542. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8543. j++;
  8544. }
  8545. sstr[j] = '\0';
  8546. strcpy(idTagstatus, sstr);
  8547. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  8548. OCPP_getIdTagFromLocalList(idTagstr);
  8549. //OCPP_getIdTagFromLocalList("test"); For Test
  8550. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  8551. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  8552. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8553. {
  8554. //Local list full update
  8555. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8556. // update list
  8557. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8558. //DEBUG_INFO("Local list full update. 1\n");
  8559. //OCPP_get_TableAuthlocalAllData();
  8560. //DEBUG_INFO("Local list full update. 2\n");
  8561. }
  8562. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8563. {
  8564. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8565. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  8566. }
  8567. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  8568. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  8569. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  8570. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  8571. c++;
  8572. }
  8573. }
  8574. else
  8575. {
  8576. //Check UpdateType
  8577. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8578. {
  8579. //Local list full update
  8580. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  8581. OCPP_cleanLocalList();
  8582. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8583. goto end;
  8584. }
  8585. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8586. {
  8587. //Local list different update
  8588. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  8589. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8590. goto end;
  8591. }
  8592. }
  8593. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8594. end:
  8595. sendSendLocalListConfirmation(uuid, comfirmstr);
  8596. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  8597. return result;
  8598. }
  8599. #define MAX 200
  8600. int handleSetChargingProfileRequest(char *uuid, char *payload)
  8601. {
  8602. mtrace();
  8603. int result = FAIL;
  8604. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  8605. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  8606. char chargingProfilePurposeStr[30]={0};
  8607. char chargingProfileKindStr[16]={0};
  8608. char recurrencyKindStr[10]={0};
  8609. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  8610. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  8611. int chargingSchedulePeriodCount = 0;
  8612. char comfirmstr[20]={0};
  8613. int meet= FALSE;
  8614. FILE *fptr1;
  8615. char filename[MAX]={0};
  8616. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  8617. char rmFileCmd[50]={0};
  8618. char tempchargingProfilePurposeStr[30]={0};
  8619. char word[1600]={0};
  8620. int n_chargingProfile = 0;
  8621. json_object *SetChargingProfile;
  8622. DEBUG_INFO("handleSetChargingProfileRequest\n");
  8623. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  8624. SetChargingProfile = json_tokener_parse(payload);
  8625. if(!is_error(SetChargingProfile))
  8626. {
  8627. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  8628. {
  8629. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  8630. if(connectorIdInt == 0)
  8631. {
  8632. memset(&ShmOCPP16Data->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  8633. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  8634. }
  8635. else
  8636. {
  8637. memset(&ShmOCPP16Data->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  8638. ShmOCPP16Data->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  8639. }
  8640. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  8641. }
  8642. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  8643. {
  8644. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  8645. {
  8646. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  8647. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8648. {
  8649. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8650. }
  8651. else
  8652. {
  8653. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8654. }
  8655. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  8656. }
  8657. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  8658. {
  8659. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  8660. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8661. {
  8662. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  8663. }
  8664. else
  8665. {
  8666. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  8667. }
  8668. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  8669. }
  8670. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8671. {
  8672. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  8673. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8674. {
  8675. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8676. }
  8677. else
  8678. {
  8679. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8680. }
  8681. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  8682. }
  8683. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  8684. {
  8685. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  8686. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8687. {
  8688. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8689. }
  8690. else
  8691. {
  8692. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8693. }
  8694. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  8695. }
  8696. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  8697. {
  8698. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  8699. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8700. {
  8701. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  8702. }
  8703. else
  8704. {
  8705. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  8706. }
  8707. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  8708. }
  8709. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  8710. {
  8711. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  8712. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8713. {
  8714. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8715. }
  8716. else
  8717. {
  8718. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8719. }
  8720. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  8721. }
  8722. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  8723. {
  8724. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  8725. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8726. {
  8727. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  8728. }
  8729. else
  8730. {
  8731. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  8732. }
  8733. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  8734. }
  8735. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  8736. {
  8737. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  8738. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8739. {
  8740. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  8741. }
  8742. else
  8743. {
  8744. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  8745. }
  8746. //DEBUG_INFO("validToStr: %s\n", validToStr);
  8747. }
  8748. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  8749. {
  8750. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  8751. {
  8752. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  8753. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8754. {
  8755. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8756. }
  8757. else
  8758. {
  8759. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8760. }
  8761. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  8762. }
  8763. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  8764. {
  8765. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  8766. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8767. {
  8768. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8769. }
  8770. else
  8771. {
  8772. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8773. }
  8774. //DEBUG_INFO("durationInt: %d\n", durationInt);
  8775. }
  8776. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  8777. {
  8778. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  8779. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8780. {
  8781. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8782. }
  8783. else
  8784. {
  8785. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8786. }
  8787. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  8788. }
  8789. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  8790. {
  8791. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  8792. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8793. {
  8794. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8795. }
  8796. else
  8797. {
  8798. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8799. }
  8800. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  8801. }
  8802. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  8803. {
  8804. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  8805. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  8806. if(chargingSchedulePeriodCount <= 10)
  8807. {
  8808. 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++)
  8809. {
  8810. 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)
  8811. {
  8812. 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"));
  8813. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8814. {
  8815. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  8816. }
  8817. else
  8818. {
  8819. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  8820. }
  8821. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  8822. }
  8823. 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)
  8824. {
  8825. 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"));
  8826. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8827. {
  8828. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  8829. }
  8830. else
  8831. {
  8832. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  8833. }
  8834. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  8835. }
  8836. 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)
  8837. {
  8838. 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"));
  8839. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8840. {
  8841. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  8842. }
  8843. else
  8844. {
  8845. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  8846. }
  8847. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  8848. }
  8849. }
  8850. }
  8851. }
  8852. }
  8853. }
  8854. }
  8855. json_object_put(SetChargingProfile);
  8856. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8857. {
  8858. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8859. goto end;
  8860. }
  8861. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8862. {
  8863. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8864. if(connectorIdInt != 0)
  8865. {
  8866. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8867. goto end;
  8868. }
  8869. strcpy(filename, ChargePointMaxProfile_JSON );
  8870. fptr1 = fopen(filename, "r");
  8871. if (!fptr1)
  8872. {
  8873. //file not exist
  8874. DEBUG_INFO("Unable to open the input file!!\n");
  8875. fptr1 = fopen(filename, "w+");
  8876. }
  8877. else
  8878. {
  8879. //Check Charging Profile Count
  8880. while(fscanf(fptr1, "%s", word) != EOF)
  8881. {
  8882. //DEBUG_INFO("word=%s\n",word);
  8883. if(strstr(word, "chargingProfileId")!= NULL)
  8884. {
  8885. //DEBUG_INFO("test chargingProfileId \n");
  8886. n_chargingProfile = n_chargingProfile + 1;
  8887. //DEBUG_INFO("chargingProfileId Found\n");
  8888. }
  8889. }
  8890. }
  8891. fclose(fptr1);
  8892. }
  8893. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8894. {
  8895. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8896. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8897. {
  8898. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8899. goto end;
  8900. }
  8901. memset(filename, 0, ARRAY_SIZE(filename));
  8902. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8903. fptr1 = fopen(filename, "r");
  8904. if (!fptr1)
  8905. {
  8906. //file not exist
  8907. //DEBUG_INFO("Unable to open the input file!!\n");
  8908. fptr1 = fopen(filename, "w+");
  8909. }
  8910. else
  8911. {
  8912. //Check Charging Profile Count
  8913. while(fscanf(fptr1, "%s", word) != EOF)
  8914. {
  8915. //DEBUG_INFO("word=%s\n",word);
  8916. if(strstr(word, "chargingProfileId")!= NULL)
  8917. {
  8918. //DEBUG_INFO("test chargingProfileId \n");
  8919. n_chargingProfile = n_chargingProfile + 1;
  8920. //DEBUG_INFO("chargingProfileId Found\n");
  8921. }
  8922. }
  8923. }
  8924. fclose(fptr1);
  8925. }
  8926. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8927. {
  8928. //printf("set chargingProfile 1-4\n");
  8929. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8930. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  8931. if(connectorIdInt == 0)
  8932. {
  8933. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8934. goto end;
  8935. }
  8936. int tempIndex = 0;
  8937. //check Transaction active
  8938. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8939. {
  8940. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8941. {
  8942. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8943. }
  8944. else
  8945. {
  8946. tempIndex = connectorIdInt -1;
  8947. }
  8948. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8949. {
  8950. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8951. {
  8952. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8953. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  8954. {
  8955. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8956. {
  8957. meet = TRUE;
  8958. break;
  8959. }
  8960. }
  8961. }
  8962. }
  8963. }
  8964. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8965. {
  8966. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8967. {
  8968. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8969. }
  8970. else
  8971. {
  8972. tempIndex = connectorIdInt -1;
  8973. }
  8974. for (int index = 0; index < CCS_QUANTITY; index++)
  8975. {
  8976. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8977. {
  8978. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8979. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  8980. {
  8981. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8982. {
  8983. meet = TRUE;
  8984. break;
  8985. }
  8986. }
  8987. }
  8988. }
  8989. }
  8990. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8991. {
  8992. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8993. {
  8994. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8995. }
  8996. else
  8997. {
  8998. tempIndex = connectorIdInt -1;
  8999. }
  9000. for (int index = 0; index < GB_QUANTITY; index++)
  9001. {
  9002. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9003. {
  9004. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9005. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9006. {
  9007. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9008. {
  9009. meet = TRUE;
  9010. break;
  9011. }
  9012. }
  9013. }
  9014. }
  9015. }
  9016. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9017. {
  9018. tempIndex = connectorIdInt -1;
  9019. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9020. {
  9021. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9022. {
  9023. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  9024. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9025. {
  9026. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9027. {
  9028. meet = TRUE;
  9029. break;
  9030. }
  9031. }
  9032. }
  9033. }
  9034. }
  9035. else
  9036. {
  9037. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9038. {
  9039. tempIndex = 2;
  9040. }
  9041. else
  9042. {
  9043. tempIndex = (connectorIdInt -1);
  9044. }
  9045. for (int index = 0; index < AC_QUANTITY; index++)
  9046. {
  9047. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9048. {
  9049. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9050. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9051. {
  9052. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9053. {
  9054. meet = TRUE;
  9055. break;
  9056. }
  9057. }
  9058. }
  9059. }
  9060. }
  9061. //check Transaction active
  9062. if(meet == FALSE)
  9063. {
  9064. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9065. goto end;
  9066. }
  9067. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9068. {
  9069. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9070. goto end;
  9071. }
  9072. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9073. fptr1 = fopen(filename, "r");
  9074. if (!fptr1)
  9075. {
  9076. //file not exist
  9077. DEBUG_INFO("Unable to open the input file!!\n");
  9078. fptr1 = fopen(filename, "w+");
  9079. }
  9080. else
  9081. {
  9082. //Check Charging Profile Count
  9083. while(fscanf(fptr1, "%s", word) != EOF)
  9084. {
  9085. //DEBUG_INFO("word=%s\n",word);
  9086. if(strstr(word, "chargingProfileId")!= NULL)
  9087. {
  9088. //DEBUG_INFO("test chargingProfileId \n");
  9089. n_chargingProfile = n_chargingProfile + 1;
  9090. //DEBUG_INFO("chargingProfileId Found\n");
  9091. }
  9092. }
  9093. }
  9094. fclose(fptr1);
  9095. }
  9096. // Check ChargeProfileMaxStackLevel
  9097. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  9098. {
  9099. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9100. goto end;
  9101. }
  9102. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9103. {
  9104. int i = 0;
  9105. char fnametemp[200]={0};
  9106. n_chargingProfile = 0;
  9107. //Check ChargePointMaxProfile.json exit
  9108. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9109. {
  9110. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  9111. //Check Charging Profile Count
  9112. while(fscanf(fptr1, "%s", word) != EOF)
  9113. {
  9114. //DEBUG_INFO("word=%s\n",word);
  9115. if(strstr(word, "chargingProfileId")!= NULL)
  9116. {
  9117. //DEBUG_INFO("test chargingProfileId \n");
  9118. n_chargingProfile = n_chargingProfile + 1;
  9119. i = i + 1;
  9120. //DEBUG_INFO("chargingProfileId Found\n");
  9121. }
  9122. memset(word, 0, ARRAY_SIZE(word));
  9123. }
  9124. fclose(fptr1);
  9125. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  9126. }
  9127. //Check TxDefaultProfile_0.json exit
  9128. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9129. {
  9130. i = 0;
  9131. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  9132. //Check Charging Profile Count
  9133. while(fscanf(fptr1, "%s", word) != EOF)
  9134. {
  9135. //DEBUG_INFO("word=%s\n",word);
  9136. if(strstr(word, "chargingProfileId")!= NULL)
  9137. {
  9138. //DEBUG_INFO("test chargingProfileId \n");
  9139. n_chargingProfile = n_chargingProfile + 1;
  9140. i = i + 1;
  9141. //DEBUG_INFO("chargingProfileId Found\n");
  9142. }
  9143. memset(word, 0, ARRAY_SIZE(word));
  9144. }
  9145. fclose(fptr1);
  9146. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  9147. }
  9148. //Check TxDefaultProfile_%d.json
  9149. for(int j=1; j <= gunTotalNumber; j++)
  9150. {
  9151. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9152. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9153. if((access(fnametemp,F_OK))!=-1)
  9154. {
  9155. i = 0;
  9156. fptr1 = fopen(fnametemp, "r");
  9157. //Check Charging Profile Count
  9158. while(fscanf(fptr1, "%s", word) != EOF)
  9159. {
  9160. //DEBUG_INFO("word=%s\n",word);
  9161. if(strstr(word, "chargingProfileId")!= NULL)
  9162. {
  9163. //DEBUG_INFO("test chargingProfileId \n");
  9164. n_chargingProfile = n_chargingProfile + 1;
  9165. i = i + 1;
  9166. //DEBUG_INFO("chargingProfileId Found\n");
  9167. }
  9168. memset(word, 0, ARRAY_SIZE(word));
  9169. }
  9170. fclose(fptr1);
  9171. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9172. }
  9173. }
  9174. //Check TxProfile_%d.json
  9175. for(int j=1; j <= gunTotalNumber; j++)
  9176. {
  9177. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9178. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9179. if((access(fnametemp,F_OK))!=-1)
  9180. {
  9181. i = 0;
  9182. fptr1 = fopen(fnametemp, "r");
  9183. //Check Charging Profile Count
  9184. while(fscanf(fptr1, "%s", word) != EOF)
  9185. {
  9186. //DEBUG_INFO("word=%s\n",word);
  9187. if(strstr(word, "chargingProfileId")!= NULL)
  9188. {
  9189. //DEBUG_INFO("test chargingProfileId \n");
  9190. n_chargingProfile = n_chargingProfile + 1;
  9191. i = i + 1;
  9192. //DEBUG_INFO("chargingProfileId Found\n");
  9193. }
  9194. memset(word, 0, ARRAY_SIZE(word));
  9195. }
  9196. fclose(fptr1);
  9197. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9198. }
  9199. }
  9200. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  9201. {
  9202. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9203. goto end;
  9204. }
  9205. }
  9206. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9207. //**********************************Write to File********************************************************/
  9208. FILE *infile;
  9209. FILE *outfile;
  9210. infile = fopen (filename, "r");
  9211. outfile = fopen (tempfile, "w");
  9212. int d =0;
  9213. d = fgetc(infile);
  9214. rewind(infile);
  9215. if(d == EOF)
  9216. {
  9217. // Profile is empty
  9218. fprintf(outfile,"%s\n",payload);
  9219. fclose(infile);
  9220. fclose(outfile);
  9221. sprintf(rmFileCmd,"rm -f %s",filename);
  9222. system(rmFileCmd);
  9223. rename(tempfile, filename);
  9224. }
  9225. else
  9226. {
  9227. // Profile is not empty
  9228. char buf[2048]={0};
  9229. int ChargingProfileAdded = FALSE;
  9230. while (fgets(buf, sizeof(buf), infile) != NULL)
  9231. {
  9232. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9233. json_object *tmpChargingProfile;
  9234. tmpChargingProfile = json_tokener_parse(buf);
  9235. if(!is_error(SetChargingProfile))
  9236. {
  9237. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  9238. {
  9239. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  9240. }
  9241. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  9242. {
  9243. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  9244. {
  9245. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  9246. }
  9247. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  9248. {
  9249. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  9250. }
  9251. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9252. {
  9253. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  9254. }
  9255. }
  9256. }
  9257. json_object_put(tmpChargingProfile);
  9258. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  9259. {
  9260. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9261. {
  9262. //DEBUG_INFO("update set chargingProfile to file -0\n");
  9263. if(ChargingProfileAdded == FALSE)
  9264. {
  9265. fprintf(outfile,"%s\n",payload);
  9266. ChargingProfileAdded = TRUE;
  9267. }
  9268. }
  9269. else
  9270. {
  9271. if(tempstackLevelInt < stackLevelInt)
  9272. {
  9273. if(ChargingProfileAdded == FALSE)
  9274. {
  9275. fprintf(outfile,"%s\n",buf);
  9276. fprintf(outfile,"%s\n",payload);
  9277. ChargingProfileAdded = TRUE;
  9278. }
  9279. else
  9280. {
  9281. fprintf(outfile,"%s\n",buf);
  9282. }
  9283. }
  9284. else
  9285. {
  9286. if(ChargingProfileAdded == FALSE)
  9287. {
  9288. fprintf(outfile,"%s\n",buf);
  9289. fprintf(outfile,"%s\n",payload);
  9290. ChargingProfileAdded = TRUE;
  9291. }
  9292. else
  9293. {
  9294. fprintf(outfile,"%s\n",buf);
  9295. }
  9296. }
  9297. }
  9298. }
  9299. else
  9300. {
  9301. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9302. {
  9303. if(ChargingProfileAdded == FALSE)
  9304. {
  9305. fprintf(outfile,"%s\n",buf);
  9306. fprintf(outfile,"%s\n",payload);
  9307. ChargingProfileAdded = TRUE;
  9308. }
  9309. else
  9310. {
  9311. fprintf(outfile,"%s\n",buf);
  9312. }
  9313. }
  9314. else if(tempstackLevelInt < stackLevelInt)
  9315. {
  9316. if(ChargingProfileAdded == FALSE)
  9317. {
  9318. fprintf(outfile,"%s\n",buf);
  9319. fprintf(outfile,"%s\n",payload);
  9320. ChargingProfileAdded = TRUE;
  9321. }
  9322. else
  9323. {
  9324. fprintf(outfile,"%s\n",buf);
  9325. }
  9326. }
  9327. else
  9328. {
  9329. if(ChargingProfileAdded == FALSE)
  9330. {
  9331. fprintf(outfile,"%s\n",buf);
  9332. fprintf(outfile,"%s\n",payload);
  9333. ChargingProfileAdded = TRUE;
  9334. }
  9335. else
  9336. {
  9337. fprintf(outfile,"%s\n",buf);
  9338. }
  9339. }
  9340. }
  9341. } // end of while loop
  9342. fclose(infile);
  9343. fclose(outfile);
  9344. sprintf(rmFileCmd,"rm -f %s",filename);
  9345. system(rmFileCmd);
  9346. rename(tempfile, filename);
  9347. }
  9348. sleep(1);
  9349. result = TRUE;
  9350. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9351. end:
  9352. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  9353. {
  9354. if(connectorIdInt == 0)
  9355. {
  9356. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9357. {
  9358. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  9359. }
  9360. }
  9361. else
  9362. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  9363. }
  9364. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  9365. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9366. return result;
  9367. }
  9368. int handleTriggerMessageRequest(char *uuid, char *payload)
  9369. {
  9370. mtrace();
  9371. int result = FAIL;
  9372. int connectorIdIsNULL = FALSE;
  9373. int connectorIdInt =0;
  9374. char sstr[40]={0},sstrtemp[100]={ 0 };
  9375. char requestedMessagestr[40]={0};
  9376. char comfirmstr[20]={0};
  9377. int c = 0;
  9378. char *loc;
  9379. DEBUG_INFO("handleTriggerMessageRequest\n");
  9380. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  9381. strcpy(sstrtemp, stringtrimspace(payload));
  9382. c = 0;
  9383. loc = strstr(sstrtemp, "requestedMessage");
  9384. while (loc[3+strlen("requestedMessage")+c] != '\"')
  9385. {
  9386. sstr[c] = loc[3+strlen("requestedMessage")+c];
  9387. c++;
  9388. }
  9389. sstr[c] = '\0';
  9390. strcpy(requestedMessagestr, sstr);
  9391. c = 0;
  9392. loc = strstr(sstrtemp, "connectorId");
  9393. if(loc == NULL)
  9394. {
  9395. connectorIdIsNULL = TRUE;
  9396. }
  9397. else
  9398. {
  9399. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9400. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  9401. {
  9402. sstr[c] = loc[strlen("connectorId")+2+c];
  9403. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9404. c++;
  9405. }
  9406. sstr[c] = '\0';
  9407. connectorIdInt = atoi(sstr);
  9408. }
  9409. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  9410. {
  9411. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  9412. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  9413. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  9414. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  9415. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  9416. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  9417. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  9418. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  9419. {
  9420. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  9421. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9422. return TRUE;
  9423. }
  9424. else
  9425. {
  9426. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9427. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9428. }
  9429. }
  9430. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  9431. {
  9432. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  9433. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9434. return TRUE;
  9435. }
  9436. //==========================
  9437. // Trigger message
  9438. //==========================
  9439. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  9440. {
  9441. if((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) &&
  9442. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) &&
  9443. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) &&
  9444. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING) )
  9445. {
  9446. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  9447. }
  9448. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  9449. }
  9450. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  9451. {
  9452. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  9453. }
  9454. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  9455. {
  9456. //sendBootNotificationRequest();
  9457. server_sign = FALSE;
  9458. }
  9459. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  9460. {
  9461. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  9462. }
  9463. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  9464. {
  9465. if(connectorIdIsNULL == FALSE)
  9466. {
  9467. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9468. {
  9469. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  9470. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  9471. }
  9472. }
  9473. else
  9474. {
  9475. for(int idx=0;idx< gunTotalNumber;idx++)
  9476. {
  9477. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  9478. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  9479. }
  9480. }
  9481. }
  9482. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  9483. {
  9484. if(connectorIdIsNULL == FALSE)
  9485. {
  9486. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9487. {
  9488. cpinitateMsg.bits[connectorIdInt -1].StatusNotificationReq = 1;
  9489. }
  9490. }
  9491. else
  9492. {
  9493. for(int idx=0;idx< gunTotalNumber;idx++)
  9494. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  9495. }
  9496. }
  9497. return result;
  9498. }
  9499. int handleUnlockConnectorRequest(char *uuid, char *payload)
  9500. {
  9501. mtrace();
  9502. int result = FAIL;
  9503. int connectorIdInt =0;
  9504. char comfirmstr[20]={0};
  9505. int tempIndex = 0;
  9506. json_object *UnlockConnector;
  9507. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  9508. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  9509. UnlockConnector = json_tokener_parse(payload);
  9510. if(!is_error(UnlockConnector))
  9511. {
  9512. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  9513. {
  9514. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  9515. }
  9516. }
  9517. json_object_put(UnlockConnector);
  9518. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  9519. if(gunTotalNumber == 0)
  9520. {
  9521. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9522. goto end;
  9523. }
  9524. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  9525. {
  9526. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9527. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9528. goto end;
  9529. }
  9530. else
  9531. {
  9532. //check Transaction active
  9533. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  9534. {
  9535. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9536. {
  9537. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9538. }
  9539. else
  9540. {
  9541. tempIndex = connectorIdInt -1;
  9542. }
  9543. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9544. {
  9545. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9546. {
  9547. //stop Transaction
  9548. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9549. }
  9550. }
  9551. }
  9552. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  9553. {
  9554. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9555. {
  9556. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9557. }
  9558. else
  9559. {
  9560. tempIndex = connectorIdInt -1;
  9561. }
  9562. for (int index = 0; index < CCS_QUANTITY; index++)
  9563. {
  9564. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9565. {
  9566. //stop Transaction
  9567. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9568. }
  9569. }
  9570. }
  9571. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  9572. {
  9573. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9574. {
  9575. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9576. }
  9577. else
  9578. {
  9579. tempIndex = connectorIdInt -1;
  9580. }
  9581. for (int index = 0; index < GB_QUANTITY; index++)
  9582. {
  9583. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  9584. {
  9585. //stop Transaction
  9586. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9587. }
  9588. }
  9589. }
  9590. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  9591. {
  9592. tempIndex = connectorIdInt -1;
  9593. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9594. {
  9595. 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)))
  9596. {
  9597. //stop Transaction
  9598. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9599. }
  9600. }
  9601. }
  9602. else
  9603. {
  9604. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9605. {
  9606. tempIndex = 2;
  9607. }
  9608. else
  9609. {
  9610. tempIndex = connectorIdInt-1;
  9611. }
  9612. for (int index = 0; index < AC_QUANTITY; index++)
  9613. {
  9614. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9615. {
  9616. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9617. }
  9618. }
  9619. }
  9620. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  9621. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  9622. result = TRUE;
  9623. return result;
  9624. }
  9625. end:
  9626. //json_object_put(obj); --- remove temporally
  9627. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  9628. return result;
  9629. }
  9630. static char UpdateFirmwarepayloadData[300]={0};
  9631. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  9632. {
  9633. mtrace();
  9634. int result = FAIL;
  9635. pthread_t t;
  9636. sendUpdateFirmwareConfirmation(uuid);
  9637. memset(UpdateFirmwarepayloadData, 0, 300);
  9638. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  9639. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  9640. ////pthread_join(t, NULL); //
  9641. //pthread_detach(t);
  9642. //sendUpdateFirmwareConfirmation(uuid);
  9643. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  9644. return result;
  9645. }
  9646. void *UpdateFirmwareProcess(void *data)
  9647. {
  9648. pthread_detach(pthread_self());
  9649. mtrace();
  9650. int retriesInt =0, retryIntervalInt=0;
  9651. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  9652. int port=0;
  9653. char locationstr[160]={0}, retrieveDatestr[30]={0};
  9654. int isSuccess = 0;
  9655. char ftpbuf[200];
  9656. char temp[100];
  9657. char * pch;
  9658. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  9659. json_object *UpdateFirmware;
  9660. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  9661. if(!is_error(UpdateFirmware))
  9662. {
  9663. // Required data
  9664. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  9665. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  9666. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  9667. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  9668. // Optional data
  9669. if(json_object_object_get(UpdateFirmware, "retries"))
  9670. {
  9671. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  9672. }
  9673. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  9674. {
  9675. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  9676. }
  9677. }
  9678. json_object_put(UpdateFirmware);
  9679. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9680. memset(path, 0, ARRAY_SIZE(path));
  9681. system("rm -f /mnt/*");
  9682. if(strncmp(locationstr,"http", 4) == 0)
  9683. {
  9684. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9685. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  9686. // protocol, user, password, host, path);
  9687. sprintf(ftppath,"/%s", path);
  9688. DEBUG_INFO("locationstr: %s\n", locationstr);
  9689. DEBUG_INFO("protocol: %s\n",protocol);
  9690. DEBUG_INFO("host: %s\n",host);
  9691. DEBUG_INFO("path: %s\n",path);
  9692. DEBUG_INFO("ftppath: %s\n",ftppath);
  9693. int ftppathlen=strlen(ftppath);
  9694. int i=1;
  9695. char filenametemp[50];
  9696. while(i < ftppathlen)
  9697. {
  9698. int len=ftppathlen-i;
  9699. if(ftppath[len]== 47) // '/' ascll code: 47
  9700. {
  9701. DEBUG_INFO("compare '/' all right\n");
  9702. break;
  9703. }
  9704. i=i+1;
  9705. }
  9706. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9707. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9708. filenametemp[i+1] = 0;
  9709. do
  9710. {
  9711. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9712. sleep(3);
  9713. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9714. if(!isSuccess)
  9715. {
  9716. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9717. sleep(retryIntervalInt);
  9718. }
  9719. else
  9720. {
  9721. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9722. }
  9723. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  9724. }
  9725. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  9726. {
  9727. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9728. memset(temp, 0, ARRAY_SIZE(temp));
  9729. //DEBUG_INFO("locationstr=%s\n",locationstr);
  9730. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  9731. int ftppathlen=strlen(ftpbuf);
  9732. int i=1;
  9733. char filenametemp[50];
  9734. while(i < ftppathlen)
  9735. {
  9736. int len=ftppathlen-i;
  9737. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9738. {
  9739. DEBUG_INFO(" compare '/' all right\n");
  9740. break;
  9741. }
  9742. i=i+1;
  9743. }
  9744. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9745. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9746. filenametemp[i+1] = 0;
  9747. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9748. pch=strchr(temp,'@');
  9749. if(pch==NULL)
  9750. {
  9751. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9752. protocol, host, &port, path);
  9753. strcpy(user,"anonymous");
  9754. strcpy(password,"");
  9755. }
  9756. else
  9757. {
  9758. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9759. protocol, user, password, host, &port, path);
  9760. }
  9761. sscanf(host,"%[^/]%s",host1, path1);
  9762. sprintf(ftppath,"%s", path1);
  9763. //DEBUG_INFO("protocol =%s\n",protocol);
  9764. //DEBUG_INFO("user =%s\n",user);
  9765. //DEBUG_INFO("password =%s\n",password);
  9766. //DEBUG_INFO("host1 =%s\n",host1);
  9767. //DEBUG_INFO("port =%d\n",port);
  9768. //DEBUG_INFO("path1 =%s\n",path1);
  9769. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9770. //ftpFile(host, user, password, port, ftppath, fname);
  9771. //download firmware pthred
  9772. if(port == 0)
  9773. {
  9774. port = 21;
  9775. }
  9776. do
  9777. {
  9778. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9779. sleep(3);
  9780. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9781. if(!isSuccess)
  9782. {
  9783. //BulldogUtil.sleepMs(interval*1000);
  9784. DEBUG_INFO("Update firmware request and download file fail.\n");
  9785. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9786. sleep(retryIntervalInt);
  9787. }
  9788. else
  9789. {
  9790. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9791. }
  9792. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9793. }
  9794. else
  9795. {
  9796. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9797. }
  9798. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9799. pthread_exit(NULL);
  9800. }
  9801. //==========================================
  9802. // Handle server response routine
  9803. //==========================================
  9804. void handleAuthorizeResponse(char *payload, int gun_index)
  9805. {
  9806. mtrace();
  9807. char expiryDatestr[30]={0};
  9808. char parentIdTagstr[20]={0};
  9809. char statusstr[20]={0};
  9810. int expiryDateISNULL=FALSE;
  9811. int parentIdTagISNULL=FALSE;
  9812. DEBUG_INFO("handleAuthorizeResponse...\n");
  9813. json_object *Authorize;
  9814. Authorize = json_tokener_parse(payload);
  9815. if(!is_error(Authorize))
  9816. {
  9817. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  9818. {
  9819. // Required data
  9820. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  9821. // Optional data
  9822. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  9823. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  9824. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  9825. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  9826. }
  9827. }
  9828. json_object_put(Authorize);
  9829. if(expiryDateISNULL == FALSE)
  9830. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9831. if(parentIdTagISNULL == FALSE)
  9832. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9833. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9834. //Update idTag information to authorization cache if supproted
  9835. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9836. {
  9837. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  9838. }
  9839. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9840. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9841. authorizeRetryTimes = 0;
  9842. }
  9843. void handleBootNotificationResponse(char *payload, int gun_index)
  9844. {
  9845. mtrace();
  9846. char statusStr[12]={0};
  9847. char currentTimeStr[30]={0};
  9848. int intervalInt = 0;
  9849. struct tm tp;
  9850. char buf[28]={0};
  9851. char timebuf[50]={0};
  9852. DEBUG_INFO("handleBootNotificationResponse...\n");
  9853. json_object *BootNotification;
  9854. BootNotification = json_tokener_parse(payload);
  9855. if(!is_error(BootNotification))
  9856. {
  9857. // Required data
  9858. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  9859. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  9860. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  9861. }
  9862. json_object_put(BootNotification);
  9863. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9864. BootNotificationInterval = intervalInt;
  9865. HeartBeatWaitTime = intervalInt;
  9866. //write back to ShmOCPP16Data->BootNotification
  9867. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  9868. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9869. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  9870. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  9871. {
  9872. server_sign = TRUE;
  9873. server_pending =FALSE;
  9874. }
  9875. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  9876. {
  9877. server_pending = TRUE;
  9878. }
  9879. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9880. tp.tm_isdst = -1;
  9881. //time_t utc = mktime(&tp);
  9882. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9883. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9884. sprintf(timebuf,"date -s '%s'",buf);
  9885. system(timebuf);
  9886. srand(time(NULL));
  9887. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  9888. //==============================================
  9889. // RTC sync
  9890. //==============================================
  9891. system("/sbin/hwclock -w --systohc");
  9892. SetOcppConnStatus(TRUE);
  9893. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  9894. }
  9895. void handleDataTransferResponse(char *payload, int gun_index)
  9896. {
  9897. char sstr[160]={0};//sstr[200]={ 0 };
  9898. int c = 0;
  9899. char *loc;
  9900. DEBUG_INFO("handleDataTransferResponse ...\n");
  9901. loc = strstr(payload, "status");
  9902. printf("loc=%s\n",loc);
  9903. c = 0;
  9904. while (loc[3+strlen("status")+c] != '\"')
  9905. {
  9906. sstr[c] = loc[3+strlen("status")+c];
  9907. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9908. c++;
  9909. }
  9910. sstr[c] = '\0';
  9911. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  9912. }
  9913. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  9914. {
  9915. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  9916. //struct json_object *obj;
  9917. // obj = json_tokener_parse(payload);
  9918. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  9919. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  9920. //No fields are defined.
  9921. }
  9922. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  9923. {
  9924. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  9925. //struct json_object *obj;
  9926. // obj = json_tokener_parse(payload);
  9927. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  9928. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  9929. //No fields are defined.
  9930. }
  9931. void handleHeartbeatResponse(char *payload, int gun_index)
  9932. {
  9933. mtrace();
  9934. struct tm tp;
  9935. char buf[28]={0};
  9936. char timebuf[50]={0};
  9937. DEBUG_INFO("handleHeartbeatResponse...\n");
  9938. json_object *Heartbeat;
  9939. Heartbeat = json_tokener_parse(payload);
  9940. if(!is_error(Heartbeat))
  9941. {
  9942. // Required data
  9943. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  9944. }
  9945. json_object_put(Heartbeat);
  9946. if(FirstHeartBeat == 0)
  9947. {
  9948. FirstHeartBeat = 1;
  9949. DEBUG_INFO("FirstHeartBeat \n");
  9950. }
  9951. HeartBeatWithNOResponse = 0;
  9952. clientTime.Heartbeat=time((time_t*)NULL);
  9953. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9954. tp.tm_isdst = -1;
  9955. //time_t utc = mktime(&tp);
  9956. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9957. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9958. sprintf(timebuf,"date -s '%s'",buf);
  9959. system(timebuf);
  9960. //==============================================
  9961. // RTC sync
  9962. //==============================================
  9963. system("/sbin/hwclock -w --systohc");
  9964. }
  9965. void handleMeterValuesResponse(char *payload, int gun_index)
  9966. {
  9967. mtrace();
  9968. DEBUG_INFO("handleMeterValuesResponse...\n");
  9969. }
  9970. void handleStartTransactionResponse(char *payload, int gun_index)
  9971. {
  9972. mtrace();
  9973. //int transactionIdInt = 0;
  9974. FILE *outfile;
  9975. char data[100]={0};
  9976. DEBUG_INFO("handleStartTransactionResponse...\n");
  9977. json_object *StartTransaction;
  9978. StartTransaction = json_tokener_parse(payload);
  9979. if(!is_error(StartTransaction))
  9980. {
  9981. // Required data
  9982. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  9983. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  9984. // Optional data
  9985. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  9986. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  9987. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  9988. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  9989. }
  9990. json_object_put(StartTransaction);
  9991. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  9992. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  9993. //-----------Start : write to the Queue TransactionId file -----------------//
  9994. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  9995. {}
  9996. else
  9997. {
  9998. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  9999. if(log == NULL)
  10000. {
  10001. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  10002. return ;
  10003. }
  10004. else
  10005. {
  10006. fclose(log);
  10007. }
  10008. }
  10009. // open file for writing
  10010. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  10011. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  10012. {
  10013. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  10014. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  10015. fputs(data, outfile);
  10016. fclose (outfile);
  10017. }
  10018. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10019. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10020. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  10021. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  10022. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10023. }
  10024. void handleStatusNotificationResponse(char *payload, int gun_index)
  10025. {
  10026. mtrace();
  10027. DEBUG_INFO("handleStatusNotificationResponse...\n");
  10028. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  10029. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  10030. }
  10031. void handleStopTransactionnResponse(char *payload, int gun_index)
  10032. {
  10033. mtrace();
  10034. DEBUG_INFO("handleStopTransactionnResponse...\n");
  10035. json_object *StopTransaction;
  10036. StopTransaction = json_tokener_parse(payload);
  10037. if(!is_error(StopTransaction))
  10038. {
  10039. // Optional data
  10040. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  10041. {
  10042. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  10043. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  10044. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  10045. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  10046. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  10047. }
  10048. }
  10049. json_object_put(StopTransaction);
  10050. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  10051. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  10052. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10053. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10054. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  10055. }
  10056. //==========================================
  10057. // Handle Error routine
  10058. //==========================================
  10059. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  10060. {
  10061. mtrace();
  10062. #ifdef SystemLogMessage
  10063. DEBUG_INFO("errorCode: %s\n", errorCode);
  10064. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  10065. DEBUG_INFO("errorDetails: %s\n", payload);
  10066. #endif
  10067. }
  10068. //===============================================
  10069. // Common routine
  10070. //===============================================
  10071. int initialConfigurationTable(void)
  10072. {
  10073. //clock_t start_t, end_t, total_t;
  10074. FILE *fp;
  10075. FILE *outfile;
  10076. char str[512]={0};
  10077. char sstr[256]={0};
  10078. int c = 0;
  10079. char *loc;
  10080. DEBUG_INFO("initialConfigurationTable...\n");
  10081. //start_t = clock();
  10082. //printf("Starting of the program, start_t = %ld\n", start_t);
  10083. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  10084. // Check configuration file size is correct
  10085. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  10086. {
  10087. struct stat st;
  10088. stat("/Storage/OCPP/OCPPConfiguration", &st);
  10089. if(st.st_size < 3100)
  10090. {
  10091. system("rm -f /Storage/OCPP/OCPPConfiguration");
  10092. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  10093. }
  10094. }
  10095. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  10096. {
  10097. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10098. if(outfile == NULL)
  10099. {
  10100. DEBUG_INFO("Error opening file\n");
  10101. return FALSE;
  10102. }
  10103. /*Core Profile*/
  10104. //AllowOfflineTxForUnknownId
  10105. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10106. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10107. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  10108. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10109. //AuthorizationCacheEnabled
  10110. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10113. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10114. //AuthorizeRemoteTxRequests
  10115. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10116. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10117. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  10118. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10119. //BlinkRepeat
  10120. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10121. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10122. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10123. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10124. //ClockAlignedDataInterval
  10125. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10126. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10127. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10128. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10129. //ConnectionTimeOut
  10130. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10131. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10132. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10133. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10134. //GetConfigurationMaxKeys
  10135. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10136. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10137. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "44" );
  10138. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10139. // HeartbeatInterval
  10140. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10141. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10142. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  10143. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10144. // LightIntensity
  10145. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10146. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10148. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10149. // LocalAuthorizeOffline
  10150. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  10151. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10152. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10153. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10154. // LocalPreAuthorize
  10155. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10156. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10157. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10158. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10159. // MaxEnergyOnInvalidId
  10160. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10162. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10163. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10164. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10165. // MeterValuesAlignedData
  10166. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 0;
  10167. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10168. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10169. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10170. else
  10171. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10172. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10173. // MeterValuesAlignedDataMaxLength
  10174. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10175. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10176. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10177. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  10178. else
  10179. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10180. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10181. // MeterValuesSampledData
  10182. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 0;
  10183. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10184. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10185. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10186. else
  10187. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10188. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10189. // MeterValuesSampledDataMaxLength
  10190. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10191. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10192. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10193. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  10194. else
  10195. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10196. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10197. // MeterValueSampleInterval
  10198. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10199. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10200. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  10201. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10202. // MinimumStatusDuration
  10203. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10204. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10205. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  10206. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  10207. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10208. // NumberOfConnectors
  10209. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10210. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10211. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10212. {
  10213. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10214. }
  10215. else
  10216. {
  10217. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10218. }
  10219. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10220. // ResetRetries
  10221. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10222. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10223. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10224. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10225. // ConnectorPhaseRotation
  10226. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10227. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10228. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10229. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10230. // ConnectorPhaseRotationMaxLength
  10231. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10232. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10233. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10234. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10235. // StopTransactionOnEVSideDisconnect
  10236. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10237. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10238. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10239. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10240. // StopTransactionOnInvalidId
  10241. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  10242. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10243. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10244. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10245. // StopTxnAlignedData
  10246. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  10247. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10248. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10249. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10250. // StopTxnAlignedDataMaxLength
  10251. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10252. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10253. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10254. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10255. // StopTxnSampledData
  10256. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 0;
  10257. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10258. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10259. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10260. else
  10261. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10262. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10263. // StopTxnSampledDataMaxLength
  10264. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10265. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10266. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10267. {
  10268. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  10269. }
  10270. else
  10271. {
  10272. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  10273. }
  10274. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10275. // SupportedFeatureProfiles
  10276. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10277. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10278. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10279. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10280. // SupportedFeatureProfilesMaxLength
  10281. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10282. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10283. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10284. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10285. // TransactionMessageAttempts
  10286. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10287. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10288. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10289. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10290. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10291. // TransactionMessageRetryInterval
  10292. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10293. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10294. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10295. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10296. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10297. // UnlockConnectorOnEVSideDisconnect
  10298. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10299. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10300. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10301. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10302. // WebSocketPingInterval
  10303. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10304. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10305. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10306. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10307. // QueueOffLineStartTransactionMessage
  10308. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  10309. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10310. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10311. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10312. // AuthorizationKey
  10313. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  10314. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  10315. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "" );
  10316. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  10317. // SecurityProfile
  10318. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  10319. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  10320. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "0" );
  10321. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  10322. // DefaultPrice
  10323. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  10324. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  10325. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  10326. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  10327. // CustomDisplayCostAndPrice
  10328. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  10329. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  10330. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  10331. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  10332. // CustomIdleFeeAfterStop
  10333. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  10334. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  10335. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  10336. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  10337. //* Local Auth List Management Profile*/
  10338. #if 0
  10339. //For OCTT Test Case
  10340. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10341. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  10342. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10343. #endif
  10344. #if 1
  10345. //LocalAuthListEnabled
  10346. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10347. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10348. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10349. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10350. #endif
  10351. //LocalAuthListMaxLength
  10352. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10353. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10354. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10355. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10356. //SendLocalListMaxLength
  10357. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10358. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10359. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  10360. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10361. //ReserveConnectorZeroSupported
  10362. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10363. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10364. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10365. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10366. //* Smart Charging Profile */
  10367. //ChargeProfileMaxStackLevel
  10368. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10369. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10370. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10371. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10372. // ChargingScheduleAllowedChargingRateUnit
  10373. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10374. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10375. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10376. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10377. // ChargingScheduleMaxPeriods
  10378. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10379. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10380. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10381. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10382. // ConnectorSwitch3to1PhaseSupported
  10383. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10384. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10385. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10386. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10387. // MaxChargingProfilesInstalled
  10388. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10389. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10390. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  10391. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10392. fclose(outfile);
  10393. }
  10394. else
  10395. {
  10396. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10397. char keystr[60]={0};
  10398. char readonlystr[10]={0};
  10399. char valuestr[256]={0};
  10400. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10401. if(fp == NULL) {
  10402. DEBUG_INFO("Error opening file");
  10403. return FALSE;
  10404. }
  10405. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  10406. {
  10407. //DEBUG_INFO("Get Configuration \n");
  10408. if(strlen(str) > 0)
  10409. {
  10410. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10411. //*************************key*********************************/
  10412. if(strstr(str, "key") != NULL)
  10413. {
  10414. loc = strstr(str, "key");
  10415. c = 0;
  10416. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10417. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  10418. {
  10419. sstr[c] = loc[strlen("key")+3+c];
  10420. c++;
  10421. }
  10422. sstr[c] = '\0';
  10423. strcpy(keystr,sstr);
  10424. }
  10425. //*************************readonly*********************************/
  10426. if(strstr(str, "readonly") != NULL)
  10427. {
  10428. loc = strstr(str, "readonly");
  10429. c = 0;
  10430. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10431. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  10432. {
  10433. sstr[c] = loc[strlen("readonly")+2+c];
  10434. c++;
  10435. }
  10436. sstr[c] = '\0';
  10437. strcpy(readonlystr,sstr);
  10438. }
  10439. //*************************value*********************************/
  10440. if(strstr(str, "value") != NULL)
  10441. {
  10442. loc = strstr(str, "value");
  10443. c = 0;
  10444. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10445. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  10446. {
  10447. sstr[c] = loc[strlen("value")+3+c];
  10448. c++;
  10449. }
  10450. sstr[c] = '\0';
  10451. strcpy(valuestr,sstr);
  10452. }
  10453. // DEBUG_INFO("keystr=%s\n",keystr);
  10454. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10455. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10456. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10457. {
  10458. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10459. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10460. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10461. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10462. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10463. }
  10464. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10465. {
  10466. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10467. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10468. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10469. }
  10470. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10471. {
  10472. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10473. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10474. }
  10475. if(strcmp(keystr, "BlinkRepeat") == 0)
  10476. {
  10477. //Charger.BlinkRepeat = Integer.parseInt(value);
  10478. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10479. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10480. }
  10481. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10482. {
  10483. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10484. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10485. }
  10486. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10487. {
  10488. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10489. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10490. }
  10491. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10492. {
  10493. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10494. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  10495. }
  10496. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10497. {
  10498. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10499. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10500. HeartBeatWaitTime = atoi(valuestr);
  10501. }
  10502. if(strcmp(keystr, "LightIntensity") == 0)
  10503. {
  10504. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10505. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10506. }
  10507. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10508. {
  10509. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10510. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10511. }
  10512. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10513. {
  10514. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10515. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10516. }
  10517. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10518. {
  10519. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10520. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10521. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10522. }
  10523. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10524. {
  10525. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10526. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10527. }
  10528. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10529. {
  10530. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10531. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10532. }
  10533. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10534. {
  10535. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10536. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10537. }
  10538. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10539. {
  10540. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10541. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10542. }
  10543. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10544. {
  10545. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10546. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10547. }
  10548. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10549. {
  10550. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10551. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10552. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10553. }
  10554. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10555. {
  10556. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10557. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10558. }
  10559. if(strcmp(keystr, "ResetRetries") == 0)
  10560. {
  10561. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10562. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10563. }
  10564. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10565. {
  10566. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10567. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10568. }
  10569. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10570. {
  10571. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10572. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10573. }
  10574. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10575. {
  10576. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10577. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10578. }
  10579. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10580. {
  10581. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10582. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10583. }
  10584. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10585. {
  10586. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10587. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10588. }
  10589. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10590. {
  10591. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10592. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10593. }
  10594. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10595. {
  10596. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10597. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10598. }
  10599. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10600. {
  10601. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10602. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10603. }
  10604. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10605. {
  10606. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10607. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10608. }
  10609. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10610. {
  10611. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10612. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10613. }
  10614. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10615. {
  10616. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10617. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10618. TransactionMessageAttemptsValue = atoi(valuestr);
  10619. }
  10620. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10621. {
  10622. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10623. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10624. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10625. }
  10626. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10627. {
  10628. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10629. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10630. }
  10631. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10632. {
  10633. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10634. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10635. }
  10636. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  10637. {
  10638. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10639. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  10640. }
  10641. if(strcmp(keystr, "AuthorizationKey") == 0)
  10642. {
  10643. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10644. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  10645. }
  10646. if(strcmp(keystr, "SecurityProfile") == 0)
  10647. {
  10648. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10649. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  10650. }
  10651. if(strcmp(keystr, "DefaultPrice") == 0)
  10652. {
  10653. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10654. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  10655. }
  10656. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  10657. {
  10658. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10659. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  10660. }
  10661. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  10662. {
  10663. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10664. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  10665. }
  10666. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10667. {
  10668. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10669. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10670. }
  10671. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10672. {
  10673. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10674. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10675. }
  10676. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10677. {
  10678. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10679. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10680. }
  10681. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10682. {
  10683. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10684. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10685. }
  10686. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10687. {
  10688. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10689. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10690. }
  10691. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10692. {
  10693. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10694. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10695. }
  10696. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10697. {
  10698. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10699. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10700. }
  10701. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10702. {
  10703. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10704. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10705. }
  10706. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10707. {
  10708. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10709. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10710. }
  10711. }
  10712. }
  10713. fclose(fp);
  10714. }
  10715. return 0;
  10716. }
  10717. void StoreConfigurationTable(void)
  10718. {
  10719. FILE *outfile;
  10720. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10721. if(outfile == NULL)
  10722. {
  10723. DEBUG_INFO("Error opening file");
  10724. return ;
  10725. }
  10726. /*Core Profile*/
  10727. //AllowOfflineTxForUnknownId
  10728. /*
  10729. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10730. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10731. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10732. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10733. */
  10734. //DEBUG_INFO("data=%s\n",data);
  10735. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10736. //AuthorizationCacheEnabled
  10737. /*
  10738. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10739. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10740. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10741. */
  10742. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10743. //AuthorizeRemoteTxRequests
  10744. /*
  10745. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10746. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10747. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10748. */
  10749. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10750. //BlinkRepeat
  10751. /*
  10752. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10753. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10754. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10755. */
  10756. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10757. //ClockAlignedDataInterval
  10758. /*
  10759. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10760. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10761. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10762. */
  10763. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10764. //ConnectionTimeOut
  10765. /*
  10766. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10767. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10768. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10769. */
  10770. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10771. //GetConfigurationMaxKeys
  10772. /*
  10773. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10775. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10776. */
  10777. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10778. // HeartbeatInterval
  10779. /*
  10780. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10781. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10782. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10783. */
  10784. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10785. // LightIntensity
  10786. /*
  10787. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10788. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10789. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10790. */
  10791. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10792. // LocalAuthorizeOffline
  10793. /*
  10794. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10795. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10796. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10797. */
  10798. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10799. // LocalPreAuthorize
  10800. /*
  10801. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10803. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10804. */
  10805. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10806. // MaxEnergyOnInvalidId
  10807. /*
  10808. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10809. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10810. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10811. */
  10812. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10813. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10814. // MeterValuesAlignedData
  10815. /*
  10816. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10817. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10818. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10819. */
  10820. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10821. // MeterValuesAlignedDataMaxLength
  10822. /*
  10823. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10824. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10825. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10826. */
  10827. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10828. // MeterValuesSampledData
  10829. /*
  10830. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10831. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10832. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10833. */
  10834. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10835. // MeterValuesSampledDataMaxLength
  10836. /*
  10837. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10838. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10839. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10840. */
  10841. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10842. // MeterValueSampleInterval
  10843. /*
  10844. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10845. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10846. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10847. */
  10848. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10849. // MinimumStatusDuration
  10850. /*
  10851. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10852. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10853. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10854. */
  10855. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10856. // NumberOfConnectors
  10857. /*
  10858. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10859. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10860. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10861. {
  10862. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10863. }
  10864. else
  10865. {
  10866. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10867. }
  10868. */
  10869. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10870. // ResetRetries
  10871. /*
  10872. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10874. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10875. */
  10876. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10877. // ConnectorPhaseRotation
  10878. /*
  10879. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10880. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10881. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10882. */
  10883. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10884. // ConnectorPhaseRotationMaxLength
  10885. /*
  10886. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10888. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10889. */
  10890. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10891. // StopTransactionOnEVSideDisconnect
  10892. /*
  10893. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10894. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10895. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10896. */
  10897. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10898. // StopTransactionOnInvalidId
  10899. /*
  10900. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  10901. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10902. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10903. */
  10904. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10905. // StopTxnAlignedData
  10906. /*
  10907. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  10908. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10909. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10910. */
  10911. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10912. // StopTxnAlignedDataMaxLength
  10913. /*
  10914. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10915. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10916. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10917. */
  10918. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10919. // StopTxnSampledData
  10920. /*
  10921. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10922. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10923. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  10924. */
  10925. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10926. // StopTxnSampledDataMaxLength
  10927. /*
  10928. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10929. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10930. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10931. */
  10932. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10933. // SupportedFeatureProfiles
  10934. /*
  10935. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10936. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10937. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10938. */
  10939. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10940. // SupportedFeatureProfilesMaxLength
  10941. /*
  10942. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10943. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10944. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10945. */
  10946. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10947. // TransactionMessageAttempts
  10948. /*
  10949. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10950. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10951. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10952. */
  10953. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10954. // TransactionMessageRetryInterval
  10955. /*
  10956. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10957. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10958. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10959. */
  10960. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10961. // UnlockConnectorOnEVSideDisconnect
  10962. /*
  10963. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10964. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10965. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10966. */
  10967. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10968. // WebSocketPingInterval
  10969. /*
  10970. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10971. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10972. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10973. */
  10974. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10975. // QueueOffLineStartTransactionMessage
  10976. /*
  10977. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  10978. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10979. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10980. */
  10981. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10982. // AuthorizationKey
  10983. /*
  10984. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  10985. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  10986. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  10987. */
  10988. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  10989. // SecurityProfile
  10990. /*
  10991. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  10992. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  10993. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  10994. */
  10995. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  10996. // DefaultPrice
  10997. /*
  10998. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  10999. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  11000. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  11001. */
  11002. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  11003. // CustomDisplayCostAndPrice
  11004. /*
  11005. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  11006. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  11007. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  11008. */
  11009. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  11010. // CustomIdleFeeAfterStop
  11011. /*
  11012. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  11013. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  11014. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  11015. */
  11016. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  11017. //* Local Auth List Management Profile*/
  11018. //LocalAuthListEnabled
  11019. /*
  11020. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11021. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  11022. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11023. */
  11024. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11025. //LocalAuthListMaxLength
  11026. /*
  11027. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  11028. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  11029. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  11030. */
  11031. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  11032. //SendLocalListMaxLength
  11033. /*
  11034. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  11035. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  11036. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  11037. */
  11038. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  11039. //ReserveConnectorZeroSupported
  11040. /*
  11041. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  11042. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  11043. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  11044. */
  11045. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11046. //* Smart Charging Profile */
  11047. //ChargeProfileMaxStackLevel
  11048. /*
  11049. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  11050. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  11051. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  11052. */
  11053. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11054. // ChargingScheduleAllowedChargingRateUnit
  11055. /*
  11056. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  11057. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  11058. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  11059. */
  11060. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11061. // ChargingScheduleMaxPeriods
  11062. /*
  11063. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  11064. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  11065. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  11066. */
  11067. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11068. // ConnectorSwitch3to1PhaseSupported
  11069. /*
  11070. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11071. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11072. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  11073. */
  11074. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11075. // MaxChargingProfilesInstalled
  11076. /*
  11077. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11078. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11079. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  11080. */
  11081. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11082. fclose(outfile);
  11083. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11084. }
  11085. void getKeyValue(char *keyReq)
  11086. {
  11087. int isEmpty = FALSE;
  11088. int isKnowKey = FALSE;
  11089. DEBUG_INFO("keyReq = %s\n", keyReq);
  11090. if((keyReq == NULL) || (strlen(keyReq) == 0))
  11091. isEmpty = TRUE;
  11092. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  11093. {
  11094. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  11095. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  11096. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11097. {
  11098. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  11099. }
  11100. else
  11101. {
  11102. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  11103. }
  11104. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  11105. isKnowKey = TRUE;
  11106. }
  11107. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  11108. {
  11109. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  11110. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  11111. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11112. {
  11113. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  11114. }
  11115. else
  11116. {
  11117. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  11118. }
  11119. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  11120. isKnowKey = TRUE;
  11121. }
  11122. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  11123. {
  11124. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  11125. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  11126. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11127. {
  11128. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  11129. }
  11130. else
  11131. {
  11132. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  11133. }
  11134. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  11135. isKnowKey = TRUE;
  11136. }
  11137. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  11138. {
  11139. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  11140. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  11141. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11142. {
  11143. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  11144. }
  11145. else
  11146. {
  11147. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  11148. }
  11149. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  11150. isKnowKey = TRUE;
  11151. }
  11152. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  11153. {
  11154. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  11155. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  11156. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11157. {
  11158. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  11159. }
  11160. else
  11161. {
  11162. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  11163. }
  11164. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  11165. isKnowKey = TRUE;
  11166. }
  11167. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  11168. {
  11169. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  11170. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  11171. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11172. {
  11173. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  11174. }
  11175. else
  11176. {
  11177. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  11178. }
  11179. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  11180. isKnowKey = TRUE;
  11181. }
  11182. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  11183. {
  11184. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  11185. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  11186. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11187. {
  11188. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  11189. }
  11190. else
  11191. {
  11192. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  11193. }
  11194. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  11195. isKnowKey = TRUE;
  11196. }
  11197. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  11198. {
  11199. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  11200. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  11201. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11202. {
  11203. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  11204. }
  11205. else
  11206. {
  11207. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  11208. }
  11209. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  11210. isKnowKey = TRUE;
  11211. }
  11212. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  11213. {
  11214. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  11215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  11216. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11217. {
  11218. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  11219. }
  11220. else
  11221. {
  11222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  11223. }
  11224. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  11225. isKnowKey = TRUE;
  11226. }
  11227. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  11228. {
  11229. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  11230. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  11231. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11232. {
  11233. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  11234. }
  11235. else
  11236. {
  11237. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  11238. }
  11239. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  11240. isKnowKey = TRUE;
  11241. }
  11242. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  11243. {
  11244. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  11245. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  11246. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11247. {
  11248. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  11249. }
  11250. else
  11251. {
  11252. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  11253. }
  11254. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  11255. isKnowKey = TRUE;
  11256. }
  11257. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  11258. {
  11259. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  11260. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  11261. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11262. {
  11263. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11264. }
  11265. else
  11266. {
  11267. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11268. }
  11269. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  11270. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  11271. isKnowKey = TRUE;
  11272. }
  11273. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  11274. {
  11275. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  11276. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  11277. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11278. {
  11279. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11280. }
  11281. else
  11282. {
  11283. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11284. }
  11285. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  11286. isKnowKey = TRUE;
  11287. }
  11288. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  11289. {
  11290. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  11291. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  11292. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11293. {
  11294. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11295. }
  11296. else
  11297. {
  11298. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11299. }
  11300. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  11301. isKnowKey = TRUE;
  11302. }
  11303. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  11304. {
  11305. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  11306. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  11307. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11308. {
  11309. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  11310. }
  11311. else
  11312. {
  11313. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  11314. }
  11315. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  11316. isKnowKey = TRUE;
  11317. }
  11318. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  11319. {
  11320. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  11321. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  11322. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11323. {
  11324. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11325. }
  11326. else
  11327. {
  11328. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11329. }
  11330. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  11331. isKnowKey = TRUE;
  11332. }
  11333. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  11334. {
  11335. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  11336. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  11337. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11338. {
  11339. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  11340. }
  11341. else
  11342. {
  11343. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  11344. }
  11345. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  11346. isKnowKey = TRUE;
  11347. }
  11348. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  11349. {
  11350. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  11351. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  11352. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11353. {
  11354. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  11355. }
  11356. else
  11357. {
  11358. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  11359. }
  11360. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  11361. isKnowKey = TRUE;
  11362. }
  11363. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  11364. {
  11365. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  11366. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  11367. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11368. {
  11369. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  11370. }
  11371. else
  11372. {
  11373. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  11374. }
  11375. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  11376. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  11377. isKnowKey = TRUE;
  11378. }
  11379. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  11380. {
  11381. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  11382. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11383. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11384. {
  11385. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11386. }
  11387. else
  11388. {
  11389. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11390. }
  11391. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11392. isKnowKey = TRUE;
  11393. }
  11394. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11395. {
  11396. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11397. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11398. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11399. {
  11400. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11401. }
  11402. else
  11403. {
  11404. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11405. }
  11406. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11407. isKnowKey = TRUE;
  11408. }
  11409. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11410. {
  11411. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11412. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11413. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11414. {
  11415. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11416. }
  11417. else
  11418. {
  11419. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11420. }
  11421. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11422. isKnowKey = TRUE;
  11423. }
  11424. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11425. {
  11426. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11427. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11428. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11429. {
  11430. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11431. }
  11432. else
  11433. {
  11434. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11435. }
  11436. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11437. isKnowKey = TRUE;
  11438. }
  11439. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11440. {
  11441. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11442. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11443. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11444. {
  11445. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11446. }
  11447. else
  11448. {
  11449. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11450. }
  11451. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11452. isKnowKey = TRUE;
  11453. }
  11454. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11455. {
  11456. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11457. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11458. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11459. {
  11460. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11461. }
  11462. else
  11463. {
  11464. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11465. }
  11466. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11467. isKnowKey = TRUE;
  11468. }
  11469. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11470. {
  11471. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11472. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11473. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11474. {
  11475. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11476. }
  11477. else
  11478. {
  11479. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11480. }
  11481. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11482. isKnowKey = TRUE;
  11483. }
  11484. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11485. {
  11486. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11487. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11488. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11489. {
  11490. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11491. }
  11492. else
  11493. {
  11494. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11495. }
  11496. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11497. isKnowKey = TRUE;
  11498. }
  11499. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11500. {
  11501. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11502. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11503. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11504. {
  11505. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11506. }
  11507. else
  11508. {
  11509. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11510. }
  11511. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11512. isKnowKey = TRUE;
  11513. }
  11514. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11515. {
  11516. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11517. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11518. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11519. {
  11520. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11521. }
  11522. else
  11523. {
  11524. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11525. }
  11526. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11527. isKnowKey = TRUE;
  11528. }
  11529. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11530. {
  11531. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11532. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11533. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11534. {
  11535. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11536. }
  11537. else
  11538. {
  11539. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11540. }
  11541. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11542. isKnowKey = TRUE;
  11543. }
  11544. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11545. {
  11546. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11547. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11548. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11549. {
  11550. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11551. }
  11552. else
  11553. {
  11554. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11555. }
  11556. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11557. isKnowKey = TRUE;
  11558. }
  11559. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11560. {
  11561. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11562. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11563. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11564. {
  11565. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11566. }
  11567. else
  11568. {
  11569. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11570. }
  11571. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11572. isKnowKey = TRUE;
  11573. }
  11574. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11575. {
  11576. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11577. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11578. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11579. {
  11580. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11581. }
  11582. else
  11583. {
  11584. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11585. }
  11586. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11587. isKnowKey = TRUE;
  11588. }
  11589. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11590. {
  11591. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11592. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11593. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11594. {
  11595. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11596. }
  11597. else
  11598. {
  11599. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11600. }
  11601. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11602. isKnowKey = TRUE;
  11603. }
  11604. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  11605. {
  11606. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  11607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  11608. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  11609. {
  11610. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  11611. }
  11612. else
  11613. {
  11614. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  11615. }
  11616. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  11617. isKnowKey = TRUE;
  11618. }
  11619. /*
  11620. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  11621. {
  11622. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  11623. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  11624. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  11625. {
  11626. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  11627. }
  11628. else
  11629. {
  11630. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  11631. }
  11632. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  11633. isKnowKey = TRUE;
  11634. }*/
  11635. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  11636. {
  11637. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  11638. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  11639. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  11640. {
  11641. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  11642. }
  11643. else
  11644. {
  11645. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  11646. }
  11647. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  11648. isKnowKey = TRUE;
  11649. }
  11650. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  11651. {
  11652. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  11653. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  11654. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  11655. {
  11656. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  11657. }
  11658. else
  11659. {
  11660. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  11661. }
  11662. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  11663. isKnowKey = TRUE;
  11664. }
  11665. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  11666. {
  11667. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  11668. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  11669. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  11670. {
  11671. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  11672. }
  11673. else
  11674. {
  11675. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  11676. }
  11677. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  11678. isKnowKey = TRUE;
  11679. }
  11680. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  11681. {
  11682. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  11683. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  11684. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  11685. {
  11686. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  11687. }
  11688. else
  11689. {
  11690. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  11691. }
  11692. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  11693. isKnowKey = TRUE;
  11694. }
  11695. #if 1
  11696. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11697. {
  11698. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11699. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11700. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11701. {
  11702. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11703. }
  11704. else
  11705. {
  11706. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11707. }
  11708. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11709. isKnowKey = TRUE;
  11710. }
  11711. #endif
  11712. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11713. {
  11714. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11715. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11716. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11717. {
  11718. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11719. }
  11720. else
  11721. {
  11722. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11723. }
  11724. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11725. isKnowKey = TRUE;
  11726. }
  11727. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11728. {
  11729. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11730. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11731. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11732. {
  11733. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11734. }
  11735. else
  11736. {
  11737. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11738. }
  11739. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11740. isKnowKey = TRUE;
  11741. }
  11742. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11743. {
  11744. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11745. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11746. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11747. {
  11748. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11749. }
  11750. else
  11751. {
  11752. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11753. }
  11754. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11755. isKnowKey = TRUE;
  11756. }
  11757. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11758. {
  11759. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11760. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11761. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11762. {
  11763. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11764. }
  11765. else
  11766. {
  11767. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11768. }
  11769. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11770. isKnowKey = TRUE;
  11771. }
  11772. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11773. {
  11774. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11775. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11776. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11777. {
  11778. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11779. }
  11780. else
  11781. {
  11782. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11783. }
  11784. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11785. isKnowKey = TRUE;
  11786. }
  11787. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11788. {
  11789. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11790. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11791. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11792. {
  11793. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11794. }
  11795. else
  11796. {
  11797. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11798. }
  11799. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11800. isKnowKey = TRUE;
  11801. }
  11802. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11803. {
  11804. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11805. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11806. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11807. {
  11808. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11809. }
  11810. else
  11811. {
  11812. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11813. }
  11814. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11815. isKnowKey = TRUE;
  11816. }
  11817. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11818. {
  11819. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11820. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11821. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11822. {
  11823. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11824. }
  11825. else
  11826. {
  11827. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11828. }
  11829. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11830. isKnowKey = TRUE;
  11831. }
  11832. //=========================================================
  11833. if(!isEmpty && !isKnowKey)
  11834. {
  11835. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11836. strcpy(unknownkey[UnknownKeynum], keyReq);
  11837. UnknownKeynum = UnknownKeynum + 1;
  11838. }
  11839. }
  11840. void processUnkownKey(void)
  11841. {
  11842. DEBUG_INFO("processUnkownKey...\n");
  11843. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11844. for(int index=0; index < UnknownKeynum; index++)
  11845. {
  11846. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11847. {
  11848. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11849. }
  11850. }
  11851. }
  11852. int setKeyValue(char *key, char *value)
  11853. {
  11854. int isSuccess = NotSupported;
  11855. int check_ascii=0;
  11856. char str[10]={0};
  11857. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  11858. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11859. {
  11860. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11861. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11862. {
  11863. strcpy(str, (const char*)value);
  11864. for(int i = 0; str[i]; i++){
  11865. str[i] = tolower(str[i]);
  11866. }
  11867. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11868. isSuccess = ConfigurationStatus_Accepted;
  11869. }
  11870. else
  11871. {
  11872. isSuccess = ConfigurationStatus_Rejected;
  11873. }
  11874. }
  11875. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11876. {
  11877. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11878. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11879. {
  11880. strcpy(str, (const char*)value);
  11881. for(int i = 0; str[i]; i++){
  11882. str[i] = tolower(str[i]);
  11883. }
  11884. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11885. isSuccess = ConfigurationStatus_Accepted;
  11886. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11887. }
  11888. else
  11889. {
  11890. isSuccess = ConfigurationStatus_Rejected;
  11891. }
  11892. }
  11893. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11894. {
  11895. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11896. {
  11897. strcpy(str, (const char*)value);
  11898. for(int i = 0; str[i]; i++)
  11899. {
  11900. str[i] = tolower(str[i]);
  11901. }
  11902. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  11903. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11904. isSuccess = ConfigurationStatus_Accepted;
  11905. }
  11906. else
  11907. {
  11908. isSuccess = ConfigurationStatus_Rejected;
  11909. }
  11910. }
  11911. if(strcmp(key, "BlinkRepeat") == 0)
  11912. {
  11913. //Charger.BlinkRepeat = Integer.parseInt(value);
  11914. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11915. {
  11916. check_ascii = value[0];
  11917. if( (check_ascii < 48) || (check_ascii > 57) )
  11918. {
  11919. isSuccess = ConfigurationStatus_Rejected;
  11920. }
  11921. else
  11922. {
  11923. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  11924. isSuccess = ConfigurationStatus_Accepted;
  11925. }
  11926. }
  11927. else
  11928. {
  11929. isSuccess = ConfigurationStatus_Rejected;
  11930. }
  11931. }
  11932. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  11933. {
  11934. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11935. {
  11936. check_ascii = value[0];
  11937. if( (check_ascii < 48) || (check_ascii > 57) )
  11938. {
  11939. isSuccess = ConfigurationStatus_Rejected;
  11940. }
  11941. else
  11942. {
  11943. if((atoi(value) == 0) || (atoi(value) >= 10))
  11944. {
  11945. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  11946. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  11947. isSuccess = ConfigurationStatus_Accepted;
  11948. }
  11949. else
  11950. isSuccess = ConfigurationStatus_Rejected;
  11951. }
  11952. }
  11953. else
  11954. {
  11955. isSuccess = ConfigurationStatus_Rejected;
  11956. }
  11957. }
  11958. if(strcmp(key, "ConnectionTimeOut") == 0 )
  11959. {
  11960. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].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. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  11970. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  11971. isSuccess = ConfigurationStatus_Accepted;
  11972. }
  11973. }
  11974. else
  11975. {
  11976. isSuccess = ConfigurationStatus_Rejected;
  11977. }
  11978. }
  11979. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  11980. {
  11981. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11982. {
  11983. check_ascii = value[0];
  11984. if( (check_ascii < 48) || (check_ascii > 57) )
  11985. {
  11986. isSuccess = ConfigurationStatus_Rejected;
  11987. }
  11988. else
  11989. {
  11990. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11991. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  11992. isSuccess = ConfigurationStatus_Accepted;
  11993. }
  11994. }
  11995. else
  11996. {
  11997. isSuccess = ConfigurationStatus_Rejected;
  11998. }
  11999. }
  12000. if(strcmp(key, "HeartbeatInterval") == 0)
  12001. {
  12002. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  12003. {
  12004. check_ascii = value[0];
  12005. if( (check_ascii < 48) || (check_ascii > 57) )
  12006. {
  12007. isSuccess = ConfigurationStatus_Rejected;
  12008. }
  12009. else
  12010. {
  12011. if((atoi(value) == 0) || (atoi(value) >= 10))
  12012. {
  12013. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  12014. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  12015. HeartBeatWaitTime = atoi(value);
  12016. isSuccess = ConfigurationStatus_Accepted;
  12017. }
  12018. else
  12019. {
  12020. isSuccess = ConfigurationStatus_Rejected;
  12021. }
  12022. }
  12023. }
  12024. else
  12025. {
  12026. isSuccess = ConfigurationStatus_Rejected;
  12027. }
  12028. }
  12029. if(strcmp(key, "LightIntensity") == 0)
  12030. {
  12031. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  12032. {
  12033. check_ascii = value[0];
  12034. if( (check_ascii < 48) || (check_ascii > 57) )
  12035. {
  12036. isSuccess = ConfigurationStatus_Rejected;
  12037. }
  12038. else
  12039. {
  12040. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  12041. isSuccess = ConfigurationStatus_Accepted;
  12042. }
  12043. }
  12044. else
  12045. {
  12046. isSuccess = ConfigurationStatus_Rejected;
  12047. }
  12048. }
  12049. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  12050. {
  12051. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  12052. {
  12053. strcpy(str, (const char*)value);
  12054. for(int i = 0; str[i]; i++)
  12055. {
  12056. str[i] = tolower(str[i]);
  12057. }
  12058. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12059. isSuccess = ConfigurationStatus_Accepted;
  12060. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12061. }
  12062. else
  12063. {
  12064. isSuccess = ConfigurationStatus_Rejected;
  12065. }
  12066. }
  12067. if(strcmp(key, "LocalPreAuthorize") == 0)
  12068. {
  12069. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  12070. {
  12071. strcpy(str, (const char*)value);
  12072. for(int i = 0; str[i]; i++)
  12073. {
  12074. str[i] = tolower(str[i]);
  12075. }
  12076. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12077. isSuccess = ConfigurationStatus_Accepted;
  12078. }
  12079. else
  12080. {
  12081. isSuccess = ConfigurationStatus_Rejected;
  12082. }
  12083. }
  12084. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  12085. {
  12086. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  12087. {
  12088. check_ascii = value[0];
  12089. if( (check_ascii < 48) || (check_ascii > 57) )
  12090. {
  12091. isSuccess = ConfigurationStatus_Rejected;
  12092. }
  12093. else
  12094. {
  12095. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  12096. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  12097. isSuccess = ConfigurationStatus_Accepted;
  12098. }
  12099. }
  12100. else
  12101. {
  12102. isSuccess = ConfigurationStatus_Rejected;
  12103. }
  12104. }
  12105. if(strcmp(key, "MeterValuesAlignedData") == 0)
  12106. {
  12107. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  12108. {
  12109. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  12110. isSuccess = ConfigurationStatus_Accepted;
  12111. }
  12112. else
  12113. {
  12114. isSuccess = ConfigurationStatus_Rejected;
  12115. }
  12116. }
  12117. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  12118. {
  12119. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  12120. {
  12121. check_ascii = value[0];
  12122. if( (check_ascii < 48) || (check_ascii > 57) )
  12123. {
  12124. isSuccess = ConfigurationStatus_Rejected;
  12125. }
  12126. else
  12127. {
  12128. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12129. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  12130. isSuccess = ConfigurationStatus_Accepted;
  12131. }
  12132. }
  12133. else
  12134. {
  12135. isSuccess = ConfigurationStatus_Rejected;
  12136. }
  12137. }
  12138. if(strcmp(key, "MeterValuesSampledData") == 0 )
  12139. {
  12140. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  12141. {
  12142. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  12143. isSuccess = ConfigurationStatus_Accepted;
  12144. }
  12145. else
  12146. {
  12147. isSuccess = ConfigurationStatus_Rejected;
  12148. }
  12149. }
  12150. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  12151. {
  12152. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  12153. {
  12154. check_ascii = value[0];
  12155. if( (check_ascii < 48) || (check_ascii > 57) )
  12156. {
  12157. isSuccess = ConfigurationStatus_Rejected;
  12158. }
  12159. else
  12160. {
  12161. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12162. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  12163. isSuccess = ConfigurationStatus_Accepted;
  12164. }
  12165. }
  12166. else
  12167. {
  12168. isSuccess = ConfigurationStatus_Rejected;
  12169. }
  12170. }
  12171. if(strcmp(key, "MeterValueSampleInterval") == 0)
  12172. {
  12173. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12174. {
  12175. check_ascii = value[0];
  12176. if( (check_ascii < 48) || (check_ascii > 57) )
  12177. {
  12178. isSuccess = ConfigurationStatus_Rejected;
  12179. }
  12180. else
  12181. {
  12182. if((atoi(value) == 0) || (atoi(value) >= 10))
  12183. {
  12184. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12185. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  12186. isSuccess = ConfigurationStatus_Accepted;
  12187. }
  12188. else
  12189. {
  12190. isSuccess = ConfigurationStatus_Rejected;
  12191. }
  12192. }
  12193. }
  12194. else
  12195. {
  12196. isSuccess = ConfigurationStatus_Rejected;
  12197. }
  12198. }
  12199. if(strcmp(key, "MinimumStatusDuration") == 0)
  12200. {
  12201. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12202. {
  12203. check_ascii = value[0];
  12204. if( (check_ascii < 48) || (check_ascii > 57) )
  12205. {
  12206. isSuccess = ConfigurationStatus_Rejected;
  12207. }
  12208. else
  12209. {
  12210. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  12211. {
  12212. isSuccess = ConfigurationStatus_Rejected;
  12213. }
  12214. else
  12215. {
  12216. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  12217. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  12218. server_cycle_Status = atoi(value); //StatusNotification Cycle
  12219. isSuccess = ConfigurationStatus_Accepted;
  12220. }
  12221. }
  12222. }
  12223. else
  12224. {
  12225. isSuccess = ConfigurationStatus_Rejected;
  12226. }
  12227. }
  12228. if(strcmp(key, "NumberOfConnectors") == 0)
  12229. {
  12230. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12231. {
  12232. check_ascii = value[0];
  12233. if( (check_ascii < 48) || (check_ascii > 57) )
  12234. {
  12235. isSuccess = ConfigurationStatus_Rejected;
  12236. }
  12237. else
  12238. {
  12239. //Charger.ResetRetries = Integer.parseInt(value);
  12240. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  12241. isSuccess = ConfigurationStatus_Accepted;
  12242. }
  12243. }
  12244. else
  12245. {
  12246. isSuccess = ConfigurationStatus_Rejected;
  12247. }
  12248. }
  12249. if(strcmp(key, "ResetRetries") == 0)
  12250. {
  12251. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12252. {
  12253. check_ascii = value[0];
  12254. if( (check_ascii < 48) || (check_ascii > 57) )
  12255. {
  12256. isSuccess = ConfigurationStatus_Rejected;
  12257. }
  12258. else
  12259. {
  12260. //Charger.ResetRetries = Integer.parseInt(value);
  12261. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  12262. isSuccess = ConfigurationStatus_Accepted;
  12263. }
  12264. }
  12265. else
  12266. {
  12267. isSuccess = ConfigurationStatus_Rejected;
  12268. }
  12269. }
  12270. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  12271. {
  12272. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12273. {
  12274. strcpy(str, (const char*)value);
  12275. for(int i = 0; str[i]; i++)
  12276. {
  12277. str[i] = tolower(str[i]);
  12278. }
  12279. if(strcmp(str, "notapplicable")== 0)
  12280. {
  12281. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  12282. isSuccess = ConfigurationStatus_Accepted;
  12283. }
  12284. else if(strcmp(str, "unknown")== 0)
  12285. {
  12286. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  12287. isSuccess = ConfigurationStatus_Accepted;
  12288. }
  12289. else if(strcmp(str, "rst")== 0)
  12290. {
  12291. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  12292. isSuccess = ConfigurationStatus_Accepted;
  12293. }
  12294. else if(strcmp(str, "rts")== 0)
  12295. {
  12296. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  12297. isSuccess = ConfigurationStatus_Accepted;
  12298. }
  12299. else if(strcmp(str, "srt")== 0)
  12300. {
  12301. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  12302. isSuccess = ConfigurationStatus_Accepted;
  12303. }
  12304. else if(strcmp(str, "str")== 0)
  12305. {
  12306. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  12307. isSuccess = ConfigurationStatus_Accepted;
  12308. }
  12309. else if(strcmp(str, "trs")== 0)
  12310. {
  12311. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  12312. isSuccess = ConfigurationStatus_Accepted;
  12313. }
  12314. else if(strcmp(str, "tsr")== 0)
  12315. {
  12316. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  12317. isSuccess = ConfigurationStatus_Accepted;
  12318. }
  12319. else
  12320. {
  12321. isSuccess = ConfigurationStatus_Rejected;
  12322. }
  12323. }
  12324. else
  12325. {
  12326. isSuccess = ConfigurationStatus_Rejected;
  12327. }
  12328. }
  12329. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  12330. {
  12331. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12332. {
  12333. check_ascii = value[0];
  12334. if( (check_ascii < 48) || (check_ascii > 57) )
  12335. {
  12336. isSuccess = ConfigurationStatus_Rejected;
  12337. }
  12338. else
  12339. {
  12340. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  12341. isSuccess = ConfigurationStatus_Accepted;
  12342. }
  12343. }
  12344. else
  12345. {
  12346. isSuccess = ConfigurationStatus_Rejected;
  12347. }
  12348. }
  12349. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  12350. {
  12351. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12352. {
  12353. strcpy(str, (const char*)value);
  12354. for(int i = 0; str[i]; i++)
  12355. {
  12356. str[i] = tolower(str[i]);
  12357. }
  12358. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12359. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12360. isSuccess = ConfigurationStatus_Accepted;
  12361. }
  12362. else
  12363. {
  12364. isSuccess = ConfigurationStatus_Rejected;
  12365. }
  12366. }
  12367. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  12368. {
  12369. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12370. {
  12371. strcpy(str, (const char*)value);
  12372. for(int i = 0; str[i]; i++)
  12373. {
  12374. str[i] = tolower(str[i]);
  12375. }
  12376. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  12377. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12378. isSuccess = ConfigurationStatus_Accepted;
  12379. }
  12380. else
  12381. {
  12382. isSuccess = ConfigurationStatus_Rejected;
  12383. }
  12384. }
  12385. if(strcmp(key, "StopTxnAlignedData") == 0)
  12386. {
  12387. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12388. {
  12389. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  12390. isSuccess = ConfigurationStatus_Accepted;
  12391. }
  12392. else
  12393. {
  12394. isSuccess = ConfigurationStatus_Rejected;
  12395. }
  12396. }
  12397. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  12398. {
  12399. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12400. {
  12401. check_ascii = value[0];
  12402. if( (check_ascii < 48) || (check_ascii > 57) )
  12403. {
  12404. isSuccess = ConfigurationStatus_Rejected;
  12405. }
  12406. else
  12407. {
  12408. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  12409. isSuccess = ConfigurationStatus_Accepted;
  12410. }
  12411. }
  12412. else
  12413. {
  12414. isSuccess = ConfigurationStatus_Rejected;
  12415. }
  12416. }
  12417. if(strcmp(key, "StopTxnSampledData") == 0)
  12418. {
  12419. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12420. {
  12421. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  12422. isSuccess = ConfigurationStatus_Accepted;
  12423. }
  12424. else
  12425. {
  12426. isSuccess = ConfigurationStatus_Rejected;
  12427. }
  12428. }
  12429. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  12430. {
  12431. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12432. {
  12433. check_ascii = value[0];
  12434. if( (check_ascii < 48) || (check_ascii > 57) )
  12435. {
  12436. isSuccess = ConfigurationStatus_Rejected;
  12437. }
  12438. else
  12439. {
  12440. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  12441. isSuccess = ConfigurationStatus_Accepted;
  12442. }
  12443. }
  12444. else
  12445. {
  12446. isSuccess = ConfigurationStatus_Rejected;
  12447. }
  12448. }
  12449. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  12450. {
  12451. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12452. {
  12453. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  12454. isSuccess = ConfigurationStatus_Accepted;
  12455. }
  12456. else
  12457. {
  12458. isSuccess = ConfigurationStatus_Rejected;
  12459. }
  12460. }
  12461. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  12462. {
  12463. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12464. {
  12465. check_ascii = value[0];
  12466. if( (check_ascii < 48) || (check_ascii > 57) )
  12467. {
  12468. isSuccess = ConfigurationStatus_Rejected;
  12469. }
  12470. else
  12471. {
  12472. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  12473. isSuccess = ConfigurationStatus_Accepted;
  12474. }
  12475. }
  12476. else
  12477. {
  12478. isSuccess = ConfigurationStatus_Rejected;
  12479. }
  12480. }
  12481. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12482. {
  12483. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12484. {
  12485. check_ascii = value[0];
  12486. if( (check_ascii < 48) || (check_ascii > 57) )
  12487. {
  12488. isSuccess = ConfigurationStatus_Rejected;
  12489. }
  12490. else
  12491. {
  12492. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12493. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12494. TransactionMessageAttemptsValue = atoi(value);
  12495. isSuccess = ConfigurationStatus_Accepted;
  12496. }
  12497. }
  12498. else
  12499. {
  12500. isSuccess = ConfigurationStatus_Rejected;
  12501. }
  12502. }
  12503. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12504. {
  12505. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12506. {
  12507. check_ascii = value[0];
  12508. if( (check_ascii < 48) || (check_ascii > 57) )
  12509. {
  12510. isSuccess = ConfigurationStatus_Rejected;
  12511. }
  12512. else
  12513. {
  12514. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12515. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12516. TransactionMessageRetryIntervalValue = atoi(value);
  12517. isSuccess = ConfigurationStatus_Accepted;
  12518. }
  12519. }
  12520. else
  12521. {
  12522. isSuccess = ConfigurationStatus_Rejected;
  12523. }
  12524. }
  12525. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12526. {
  12527. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12528. {
  12529. strcpy(str, (const char*)value);
  12530. for(int i = 0; str[i]; i++)
  12531. {
  12532. str[i] = tolower(str[i]);
  12533. }
  12534. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12535. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12536. isSuccess = ConfigurationStatus_Accepted;
  12537. }
  12538. else
  12539. {
  12540. isSuccess = ConfigurationStatus_Rejected;
  12541. }
  12542. }
  12543. if(strcmp(key, "WebSocketPingInterval") == 0)
  12544. {
  12545. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12546. {
  12547. check_ascii = value[0];
  12548. if( (check_ascii < 48) || (check_ascii > 57) )
  12549. {
  12550. isSuccess = ConfigurationStatus_Rejected;
  12551. }
  12552. else
  12553. {
  12554. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12555. isSuccess = ConfigurationStatus_Accepted;
  12556. }
  12557. }
  12558. else
  12559. {
  12560. isSuccess = ConfigurationStatus_Rejected;
  12561. }
  12562. }
  12563. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  12564. {
  12565. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12566. {
  12567. strcpy(str, (const char*)value);
  12568. for(int i = 0; str[i]; i++)
  12569. {
  12570. str[i] = tolower(str[i]);
  12571. }
  12572. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12573. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12574. isSuccess = ConfigurationStatus_Accepted;
  12575. }
  12576. else
  12577. {
  12578. isSuccess = ConfigurationStatus_Rejected;
  12579. }
  12580. }
  12581. if(strcmp(key, "AuthorizationKey") == 0)
  12582. {
  12583. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  12584. {
  12585. strcpy(str, (const char*)value);
  12586. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  12587. isSuccess = ConfigurationStatus_Accepted;
  12588. }
  12589. else
  12590. {
  12591. isSuccess = ConfigurationStatus_Rejected;
  12592. }
  12593. }
  12594. if(strcmp(key, "SecurityProfile") == 0)
  12595. {
  12596. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  12597. {
  12598. check_ascii = value[0];
  12599. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  12600. {
  12601. isSuccess = ConfigurationStatus_Rejected;
  12602. }
  12603. else if(check_ascii == 0x33)
  12604. {
  12605. isSuccess = NotSupported;
  12606. }
  12607. else
  12608. {
  12609. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  12610. {
  12611. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  12612. isSuccess = ConfigurationStatus_Accepted;
  12613. }
  12614. else
  12615. isSuccess = ConfigurationStatus_Rejected;
  12616. }
  12617. }
  12618. else
  12619. {
  12620. isSuccess = ConfigurationStatus_Rejected;
  12621. }
  12622. }
  12623. if(strcmp(key, "DefaultPrice") == 0)
  12624. {
  12625. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  12626. {
  12627. strcpy(str, (const char*)value);
  12628. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  12629. isSuccess = ConfigurationStatus_Accepted;
  12630. }
  12631. else
  12632. {
  12633. isSuccess = ConfigurationStatus_Rejected;
  12634. }
  12635. }
  12636. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  12637. {
  12638. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  12639. {
  12640. strcpy(str, (const char*)value);
  12641. for(int i = 0; str[i]; i++)
  12642. {
  12643. str[i] = tolower(str[i]);
  12644. }
  12645. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12646. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12647. isSuccess = ConfigurationStatus_Accepted;
  12648. }
  12649. else
  12650. {
  12651. isSuccess = ConfigurationStatus_Rejected;
  12652. }
  12653. }
  12654. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  12655. {
  12656. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  12657. {
  12658. strcpy(str, (const char*)value);
  12659. for(int i = 0; str[i]; i++)
  12660. {
  12661. str[i] = tolower(str[i]);
  12662. }
  12663. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12664. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12665. isSuccess = ConfigurationStatus_Accepted;
  12666. }
  12667. else
  12668. {
  12669. isSuccess = ConfigurationStatus_Rejected;
  12670. }
  12671. }
  12672. #if 0
  12673. //For OCPP Test Case
  12674. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  12675. {
  12676. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12677. {
  12678. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  12679. isSuccess = ConfigurationStatus_Accepted;
  12680. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12681. }
  12682. else
  12683. {
  12684. isSuccess = ConfigurationStatus_Rejected;
  12685. }
  12686. }
  12687. #endif
  12688. #if 1
  12689. if(strcmp(key, "LocalAuthListEnabled") == 0)
  12690. {
  12691. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12692. {
  12693. strcpy(str, (const char*)value);
  12694. for(int i = 0; str[i]; i++)
  12695. {
  12696. str[i] = tolower(str[i]);
  12697. }
  12698. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12699. isSuccess = ConfigurationStatus_Accepted;
  12700. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12701. }
  12702. else
  12703. {
  12704. isSuccess = ConfigurationStatus_Rejected;
  12705. }
  12706. }
  12707. #endif
  12708. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12709. {
  12710. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12711. {
  12712. check_ascii = value[0];
  12713. if( (check_ascii < 48) || (check_ascii > 57) )
  12714. {
  12715. isSuccess = ConfigurationStatus_Rejected;
  12716. }
  12717. else
  12718. {
  12719. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12720. isSuccess = ConfigurationStatus_Accepted;
  12721. }
  12722. }
  12723. else
  12724. {
  12725. isSuccess = ConfigurationStatus_Rejected;
  12726. }
  12727. }
  12728. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12729. {
  12730. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12731. {
  12732. check_ascii = value[0];
  12733. if( (check_ascii < 48) || (check_ascii > 57) )
  12734. {
  12735. isSuccess = ConfigurationStatus_Rejected;
  12736. }
  12737. else
  12738. {
  12739. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12740. isSuccess = ConfigurationStatus_Accepted;
  12741. }
  12742. }
  12743. else
  12744. {
  12745. isSuccess = ConfigurationStatus_Rejected;
  12746. }
  12747. }
  12748. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12749. {
  12750. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12751. {
  12752. strcpy(str, (const char*)value);
  12753. for(int i = 0; str[i]; i++)
  12754. {
  12755. str[i] = tolower(str[i]);
  12756. }
  12757. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12758. isSuccess = ConfigurationStatus_Accepted;
  12759. }
  12760. else
  12761. {
  12762. isSuccess = ConfigurationStatus_Rejected;
  12763. }
  12764. }
  12765. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12766. {
  12767. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12768. {
  12769. check_ascii = value[0];
  12770. if( (check_ascii < 48) || (check_ascii > 57) )
  12771. {
  12772. isSuccess = ConfigurationStatus_Rejected;
  12773. }
  12774. else
  12775. {
  12776. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12777. isSuccess = ConfigurationStatus_Accepted;
  12778. }
  12779. }
  12780. else
  12781. {
  12782. isSuccess = ConfigurationStatus_Rejected;
  12783. }
  12784. }
  12785. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12786. {
  12787. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12788. {
  12789. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12790. isSuccess = ConfigurationStatus_Accepted;
  12791. }
  12792. else
  12793. {
  12794. isSuccess = ConfigurationStatus_Rejected;
  12795. }
  12796. }
  12797. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12798. {
  12799. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12800. {
  12801. check_ascii = value[0];
  12802. if( (check_ascii < 48) || (check_ascii > 57) )
  12803. {
  12804. isSuccess = ConfigurationStatus_Rejected;
  12805. }
  12806. else
  12807. {
  12808. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12809. isSuccess = ConfigurationStatus_Accepted;
  12810. }
  12811. }
  12812. else
  12813. {
  12814. isSuccess = ConfigurationStatus_Rejected;
  12815. }
  12816. }
  12817. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12818. {
  12819. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12820. {
  12821. strcpy(str, (const char*)value);
  12822. for(int i = 0; str[i]; i++)
  12823. {
  12824. str[i] = tolower(str[i]);
  12825. }
  12826. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12827. isSuccess = ConfigurationStatus_Accepted;
  12828. }
  12829. else
  12830. {
  12831. isSuccess = ConfigurationStatus_Rejected;
  12832. }
  12833. }
  12834. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12835. {
  12836. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12837. {
  12838. check_ascii = value[0];
  12839. if( (check_ascii < 48) || (check_ascii > 57) )
  12840. {
  12841. isSuccess = ConfigurationStatus_Rejected;
  12842. }
  12843. else
  12844. {
  12845. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12846. isSuccess = ConfigurationStatus_Accepted;
  12847. }
  12848. }
  12849. else
  12850. {
  12851. isSuccess = ConfigurationStatus_Rejected;
  12852. }
  12853. }
  12854. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12855. return isSuccess;
  12856. }
  12857. int TransactionMessageAttemptsGet(void)
  12858. {
  12859. return TransactionMessageAttemptsValue;
  12860. }
  12861. int FirstHeartBeatResponse(void)
  12862. {
  12863. return FirstHeartBeat;
  12864. }
  12865. int TransactionMessageRetryIntervalGet(void)
  12866. {
  12867. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12868. }
  12869. int ReadHttpStatus(int sock)
  12870. {
  12871. //char c;
  12872. char buff[1024]="",*ptr=buff+1;
  12873. int bytes_received, status;
  12874. DEBUG_INFO("Begin Response ..\n");
  12875. while((bytes_received = recv(sock, ptr, 1, 0))){
  12876. if(bytes_received==-1){
  12877. perror("ReadHttpStatus");
  12878. exit(1);
  12879. }
  12880. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  12881. ptr++;
  12882. }
  12883. *ptr=0;
  12884. ptr=buff+1;
  12885. sscanf(ptr,"%*s %d ", &status);
  12886. DEBUG_INFO("%s\n",ptr);
  12887. DEBUG_INFO("status=%d\n",status);
  12888. DEBUG_INFO("End Response ..\n");
  12889. return (bytes_received>0)?status:0;
  12890. }
  12891. //the only filed that it parsed is 'Content-Length'
  12892. int ParseHeader(int sock)
  12893. {
  12894. //char c;
  12895. char buff[1024]="",*ptr=buff+4;
  12896. int bytes_received;
  12897. DEBUG_INFO("Begin HEADER ..\n");
  12898. while((bytes_received = recv(sock, ptr, 1, 0))){
  12899. if(bytes_received==-1){
  12900. perror("Parse Header");
  12901. exit(1);
  12902. }
  12903. if(
  12904. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  12905. (ptr[-1]=='\r') && (*ptr=='\n' )
  12906. ) break;
  12907. ptr++;
  12908. }
  12909. *ptr=0;
  12910. ptr=buff+4;
  12911. //printf("%s",ptr);
  12912. if(bytes_received){
  12913. ptr=strstr(ptr,"Content-Length:");
  12914. if(ptr){
  12915. sscanf(ptr,"%*s %d",&bytes_received);
  12916. }else
  12917. bytes_received=-1; //unknown size
  12918. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  12919. }
  12920. DEBUG_INFO("End HEADER ..\n");
  12921. return bytes_received ;
  12922. }
  12923. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  12924. {
  12925. char rmFileCmd[100]={0};
  12926. char FilePath[100]={0};
  12927. char ftpbuf[200];
  12928. int systemresult;
  12929. //DEBUG_INFO("filename=%s\n",filename);
  12930. //DEBUG_INFO("url=%s\n",url);
  12931. sprintf(FilePath,"/mnt/%s",filename);
  12932. system("ping 8.8.8.8 &");
  12933. if((access(FilePath,F_OK))!=-1)
  12934. {
  12935. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12936. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12937. system(rmFileCmd);
  12938. }
  12939. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12940. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  12941. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12942. systemresult = system(ftpbuf);
  12943. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12944. if(systemresult != 0)
  12945. {
  12946. DEBUG_INFO("http DownLoad error!\n");
  12947. return FALSE;
  12948. }
  12949. system("pkill ping");
  12950. return TRUE;
  12951. }
  12952. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  12953. {
  12954. char rmFileCmd[100]={0};
  12955. char FilePath[100]={0};
  12956. char ftpbuf[200];
  12957. int systemresult;
  12958. //char temp[100];
  12959. sprintf(FilePath,"/mnt/%s",filename);
  12960. system("ping 8.8.8.8 &");
  12961. if((access(FilePath,F_OK))!=-1)
  12962. {
  12963. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12964. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12965. system(rmFileCmd);
  12966. }
  12967. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12968. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  12969. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  12970. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12971. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12972. systemresult = system(ftpbuf);
  12973. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12974. if(systemresult != 0)
  12975. {
  12976. printf("wget error!\n");
  12977. return FALSE;
  12978. }
  12979. system("pkill ping");
  12980. return TRUE;
  12981. }
  12982. int httpUploadFile(char *location, char *path, char *filename,char *url)
  12983. {
  12984. char rmFileCmd[100]={0};
  12985. char FilePath[100]={0};
  12986. char ftpbuf[200];
  12987. int systemresult;
  12988. //DEBUG_INFO("filename=%s\n",filename);
  12989. //DEBUG_INFO("url=%s\n",url);
  12990. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  12991. if((access(FilePath,F_OK))!=-1)
  12992. {
  12993. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12994. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12995. system(rmFileCmd);
  12996. }
  12997. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  12998. if(fp == NULL)
  12999. {
  13000. DEBUG_INFO("log is NULL\n");
  13001. return FALSE;
  13002. }
  13003. else
  13004. {
  13005. fprintf(fp, "%s\n", url);
  13006. fprintf(fp, "%s\n", filename);
  13007. fclose(fp);
  13008. }
  13009. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13010. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  13011. systemresult = system(ftpbuf);
  13012. DEBUG_INFO("systemresult = %d\n",systemresult);
  13013. if(systemresult != 0)
  13014. {
  13015. DEBUG_INFO("http upload error!\n");
  13016. return FALSE;
  13017. }
  13018. return TRUE;
  13019. }
  13020. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  13021. {
  13022. struct hostent* server;
  13023. char *IPbuffer;
  13024. char ftpbuf[200];
  13025. int systemresult;
  13026. // To retrieve host information
  13027. server = gethostbyname(location);
  13028. // To convert an Internet network
  13029. // address into ASCII string
  13030. IPbuffer = inet_ntoa(*((struct in_addr*)
  13031. server->h_addr_list[0]));
  13032. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13033. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  13034. /* format : ftpput -u username -p passwd IP target source*/
  13035. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  13036. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  13037. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13038. systemresult = system(ftpbuf);
  13039. DEBUG_INFO("systemresult=%d\n",systemresult);
  13040. if(systemresult != 0)
  13041. {
  13042. DEBUG_INFO("ftpput error!\n");
  13043. return FALSE;
  13044. }
  13045. return TRUE;
  13046. }
  13047. /**
  13048. * Place the contents of the specified file into a memory buffer
  13049. *
  13050. * @param[in] filename The path and name of the file to read
  13051. * @param[out] filebuffer A pointer to the contents in memory
  13052. * @return status 0 success, 1 on failure
  13053. */
  13054. int get_file_contents(const char* filename, char** outbuffer) {
  13055. FILE* file = NULL;
  13056. long filesize;
  13057. const int blocksize = 1;
  13058. size_t readsize;
  13059. char* filebuffer;
  13060. // Open the file
  13061. file = fopen(filename, "r");
  13062. if (NULL == file)
  13063. {
  13064. printf("'%s' not opened\n", filename);
  13065. exit(EXIT_FAILURE);
  13066. }
  13067. // Determine the file size
  13068. fseek(file, 0, SEEK_END);
  13069. filesize = ftell(file);
  13070. rewind (file);
  13071. // Allocate memory for the file contents
  13072. filebuffer = (char*) malloc(sizeof(char) * filesize);
  13073. *outbuffer = filebuffer;
  13074. if (filebuffer == NULL)
  13075. {
  13076. fputs ("malloc out-of-memory", stderr);
  13077. exit(EXIT_FAILURE);
  13078. }
  13079. // Read in the file
  13080. readsize = fread(filebuffer, blocksize, filesize, file);
  13081. if (readsize != filesize)
  13082. {
  13083. fputs ("didn't read file completely",stderr);
  13084. exit(EXIT_FAILURE);
  13085. }
  13086. // Clean exit
  13087. fclose(file);
  13088. return EXIT_SUCCESS;
  13089. }
  13090. static int selectSqlCount = 0;
  13091. static int callback(void *data, int argc, char **argv, char **azColName){
  13092. int i;
  13093. //printf("%s: ", (const char*)data);
  13094. selectSqlCount = argc;
  13095. for(i = 0; i<argc; i++){
  13096. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  13097. }
  13098. //printf("\n");
  13099. return 0;
  13100. }
  13101. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  13102. //int i;
  13103. //printf("%s:\n", (const char*)data);
  13104. localversion = argv[5] ? atoi(argv[5]) : 0;
  13105. //printf("localversion=%d\n", localversion);
  13106. return 0;
  13107. }
  13108. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  13109. //printf("%s:\n", (const char*)data);
  13110. //idTag
  13111. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  13112. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  13113. //parentIdTag
  13114. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  13115. //expir_date
  13116. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  13117. //status
  13118. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  13119. //version
  13120. if(columenCount > 5)
  13121. idTagQuery.listVersionInt = atoi(columnValue[5]);
  13122. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  13123. return 0;
  13124. }
  13125. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  13126. {
  13127. // localversion = argv[5] ? atoi(argv[5]) : 0;
  13128. // printf("localversion=%d\n", localversion);
  13129. return 0;
  13130. }
  13131. //=========================================
  13132. // Sqlite3 related function
  13133. //=========================================
  13134. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  13135. {
  13136. for (int i = 0; i < n_columns; i++)
  13137. {
  13138. DEBUG_INFO("%s\t", col_values[i]);
  13139. }
  13140. DEBUG_INFO("\n");
  13141. return 0;
  13142. }
  13143. int OCPP_cleanLocalCache()
  13144. {
  13145. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  13146. char *errMsg = 0;
  13147. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  13148. if (SQLITE_OK != rc)
  13149. {
  13150. DEBUG_INFO("SQL error: %s\n",errMsg);
  13151. return FALSE;
  13152. }
  13153. return TRUE;
  13154. }
  13155. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  13156. {
  13157. int isSuccess = TRUE;
  13158. int ret = 0;
  13159. //const char* data = "Callback function called";
  13160. char sql[300];
  13161. char zErrMsg[200];
  13162. memset(sql, 0, 300);
  13163. memset(zErrMsg, 0, 200);
  13164. 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);
  13165. //* Execute SQL statement */
  13166. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  13167. if( ret != SQLITE_OK )
  13168. {
  13169. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13170. isSuccess = FALSE;
  13171. }
  13172. return isSuccess;
  13173. }
  13174. void OCPP_getIdTagFromLocalCache(char idTag[])
  13175. {
  13176. int rc = 0;
  13177. char sql[100];
  13178. char zErrMsg[100];
  13179. memset(sql, 0, 100);
  13180. memset(zErrMsg, 0, 100);
  13181. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  13182. memset(&idTagQuery, 0, sizeof(idTagQuery));
  13183. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  13184. /* Execute SQL statement */
  13185. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  13186. if( rc != SQLITE_OK )
  13187. {
  13188. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13189. }
  13190. }
  13191. void OCPP_getListVerion()
  13192. {
  13193. int rc = 0;
  13194. // const char* data = "Callback function called";
  13195. char sql[100];
  13196. char zErrMsg[100];
  13197. memset(sql, 0, 100);
  13198. memset(zErrMsg, 0, 100);
  13199. strcpy(sql, "select * from ocpp_auth_local order by idx");
  13200. /* Execute SQL statement */
  13201. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  13202. if( rc != SQLITE_OK )
  13203. {
  13204. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13205. }
  13206. }
  13207. void OCPP_get_TableAuthlocalAllData(void)
  13208. {
  13209. int rc = 0;
  13210. char sql[100];
  13211. char zErrMsg[100];
  13212. memset(sql, 0, 100);
  13213. memset(zErrMsg, 0, 100);
  13214. sprintf(sql,"select * from ocpp_auth_local ");
  13215. /* Execute SQL statement */
  13216. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  13217. if( rc != SQLITE_OK )
  13218. {
  13219. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13220. }
  13221. //return ver;
  13222. }
  13223. int OCPP_cleanLocalList()
  13224. {
  13225. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  13226. char *errMsg = 0;
  13227. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  13228. if (SQLITE_OK != rc)
  13229. {
  13230. DEBUG_INFO("%s\n",errMsg);
  13231. return FALSE;
  13232. }
  13233. return TRUE;
  13234. }
  13235. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  13236. {
  13237. int isSuccess = FALSE;
  13238. int ret = 0;
  13239. //const char* data = "Callback function called";
  13240. char sql[300];
  13241. char zErrMsg[200];
  13242. memset(sql, 0, 300);
  13243. memset(zErrMsg, 0, 200);
  13244. 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);
  13245. //* Execute SQL statement */
  13246. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  13247. if( ret != SQLITE_OK )
  13248. {
  13249. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13250. return isSuccess;
  13251. }
  13252. memset(sql, 0, 300);
  13253. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  13254. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  13255. if( ret != SQLITE_OK )
  13256. {
  13257. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13258. return isSuccess;
  13259. }
  13260. isSuccess = TRUE;
  13261. return isSuccess;
  13262. }
  13263. void OCPP_getIdTagFromLocalList(char idTag[])
  13264. {
  13265. int rc = 0;
  13266. // const char* data = "Callback function called";
  13267. char sql[100];
  13268. char zErrMsg[100];
  13269. memset(sql, 0, 100);
  13270. memset(zErrMsg, 0, 100);
  13271. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  13272. memset(&idTagQuery, 0, sizeof(idTagQuery));
  13273. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  13274. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  13275. /* Execute SQL statement */
  13276. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  13277. if( rc != SQLITE_OK )
  13278. {
  13279. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13280. }
  13281. //return ver;
  13282. }
  13283. void OCPP_deleteIdTagFromLocalList(char idTag[])
  13284. {
  13285. //int ver = 0;
  13286. //int isSuccess = FALSE;
  13287. int rc = 0;
  13288. char sql[100];
  13289. char zErrMsg[100];
  13290. memset(sql, 0, 100);
  13291. memset(zErrMsg, 0, 100);
  13292. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  13293. //* Execute SQL statement */
  13294. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  13295. if( rc != SQLITE_OK )
  13296. {
  13297. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13298. }
  13299. }
  13300. int GetOcppServerURL()
  13301. {
  13302. int result = FALSE;
  13303. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  13304. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  13305. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  13306. struct yuarel url;
  13307. char urlStr[512];
  13308. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  13309. {
  13310. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  13311. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13312. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  13313. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  13314. if(yuarel_parse(&url, urlStr) != -1)
  13315. {
  13316. sprintf(OcppProtocol, "%s", url.scheme);
  13317. sprintf(OcppHost, "%s", url.host);
  13318. if(url.path == NULL)
  13319. OcppTempPath[0] = '\0';
  13320. else
  13321. {
  13322. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  13323. {
  13324. sprintf(OcppTempPath, "%s/", url.path);
  13325. }
  13326. else
  13327. {
  13328. sprintf(OcppTempPath, "%s", url.path);
  13329. }
  13330. }
  13331. if(url.port == 0)
  13332. {
  13333. if(strcmp(OcppProtocol, "wss") == 0)
  13334. OcppPort = 443;
  13335. else
  13336. OcppPort = 80;
  13337. }
  13338. else
  13339. OcppPort = url.port;
  13340. result = TRUE;
  13341. }
  13342. }
  13343. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  13344. {
  13345. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  13346. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13347. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  13348. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  13349. if(yuarel_parse(&url, urlStr) != -1)
  13350. {
  13351. sprintf(OcppProtocol, "%s", url.scheme);
  13352. sprintf(OcppHost, "%s", url.host);
  13353. if(url.path == NULL)
  13354. OcppTempPath[0] = '\0';
  13355. else
  13356. sprintf(OcppTempPath, "%s", url.path);
  13357. if(url.port == 0)
  13358. {
  13359. if(strcmp(OcppProtocol, "wss") == 0)
  13360. OcppPort = 443;
  13361. else
  13362. OcppPort = 80;
  13363. }
  13364. else
  13365. OcppPort = url.port;
  13366. result = TRUE;
  13367. }
  13368. }
  13369. else
  13370. {
  13371. strcpy(OcppHost,"");
  13372. }
  13373. return result;
  13374. }
  13375. int GetOcppPath()
  13376. {
  13377. int result = FALSE;
  13378. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  13379. {
  13380. if(OcppTempPath == NULL)
  13381. {
  13382. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13383. }
  13384. else
  13385. {
  13386. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13387. }
  13388. result = TRUE;
  13389. goto End;
  13390. }
  13391. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  13392. {
  13393. if(OcppTempPath == NULL)
  13394. {
  13395. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  13396. }
  13397. else
  13398. {
  13399. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  13400. }
  13401. result = TRUE;
  13402. goto End;
  13403. }
  13404. else
  13405. {
  13406. strcpy(OcppPath,"");
  13407. }
  13408. End:
  13409. return result;
  13410. }
  13411. int GetOcppPort()
  13412. {
  13413. return OcppPort;
  13414. }
  13415. int GetOcppConnStatus(void)
  13416. {
  13417. return ShmOCPP16Data->OcppConnStatus;
  13418. }
  13419. void SetOcppConnStatus(uint8_t status)
  13420. {
  13421. ShmOCPP16Data->OcppConnStatus = status;
  13422. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  13423. }
  13424. int GetHeartBeatWithNOResponse(void)
  13425. {
  13426. return HeartBeatWithNOResponse;
  13427. }
  13428. void SetHeartBeatWithNOResponse(void)
  13429. {
  13430. HeartBeatWithNOResponse = 0;
  13431. }
  13432. void GetStartTransactionIdTag(int gun_index)
  13433. {
  13434. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  13435. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13436. }
  13437. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  13438. {
  13439. char ch;
  13440. FILE *fptr1;
  13441. int temptransactionId;
  13442. char str[100]={0};
  13443. temptransactionId = 0;
  13444. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  13445. {
  13446. DEBUG_INFO("IdTag is empty.\n");
  13447. return temptransactionId;
  13448. }
  13449. /*------ Read the file ----------------*/
  13450. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  13451. if (!fptr1)
  13452. {
  13453. DEBUG_INFO("QueueTransactionId file open error.\n");
  13454. //printf(" File not found or unable to open the input file!!\n");
  13455. return temptransactionId;
  13456. }
  13457. ch=fgetc(fptr1);
  13458. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  13459. rewind(fptr1);
  13460. if(ch!=EOF)
  13461. {
  13462. // printf("%c",ch);
  13463. while (fgets(str, 100, fptr1) != NULL)
  13464. {
  13465. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13466. if(str[0]=='\0')
  13467. {
  13468. break;
  13469. }
  13470. char *revbuf[8] = {0}; // Variable store string split
  13471. int num = 0;// Quantity after string split
  13472. DEBUG_INFO("Transaction queue data= %s\n", str);
  13473. splitstring(str,",",revbuf,&num); // String split
  13474. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  13475. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  13476. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  13477. DEBUG_INFO("------------------------------\n");
  13478. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  13479. {
  13480. if(isStopTransaction)
  13481. {
  13482. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  13483. {
  13484. temptransactionId = atoi(revbuf[2]);
  13485. //break;
  13486. }
  13487. }
  13488. else
  13489. {
  13490. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  13491. {
  13492. temptransactionId = atoi(revbuf[2]);
  13493. //break;
  13494. }
  13495. }
  13496. }
  13497. }
  13498. }
  13499. else
  13500. DEBUG_INFO("EOF\n");
  13501. fclose(fptr1);
  13502. /*------- End of reading ---------------*/
  13503. return temptransactionId;
  13504. }
  13505. void SetTransactionIdZero(int transactionId)
  13506. {
  13507. char ch;
  13508. FILE *fptr1, *fptr2;
  13509. int temptransactionId = 0;
  13510. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  13511. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  13512. if (!fptr1)
  13513. {
  13514. //printf(" File not found or unable to open the input file!!\n");
  13515. return ;
  13516. }
  13517. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13518. if (!fptr2)
  13519. {
  13520. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  13521. fclose(fptr1);
  13522. return ;
  13523. }
  13524. ch=fgetc(fptr1);
  13525. rewind(fptr1);
  13526. if(ch!=EOF)
  13527. {
  13528. // copy all contents to the temporary file except the specific line
  13529. while (fgets(str, 100, fptr1) != NULL)
  13530. {
  13531. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13532. if(str[0]=='\0')
  13533. {
  13534. break;
  13535. }
  13536. char *revbuf[8] = {0};
  13537. int num = 0;
  13538. strcpy(strtemp, str);
  13539. splitstring(str,",",revbuf,&num);
  13540. if(revbuf[2][0] != '\0')
  13541. {
  13542. temptransactionId = atoi(revbuf[2]);
  13543. if(transactionId != temptransactionId)
  13544. {
  13545. fprintf(fptr2, "%s\n", strtemp);
  13546. }
  13547. }
  13548. }
  13549. }
  13550. fclose(fptr1);
  13551. fclose(fptr2);
  13552. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13553. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13554. /*------ Read the file ----------------*/
  13555. }
  13556. int InternetDisconnect(void)
  13557. {
  13558. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13559. }
  13560. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  13561. void storeTempStopTransaction(int gun_index)
  13562. {
  13563. char guid[37]={0};
  13564. int tempIndex = 0;
  13565. char TempStopTransaction[256];
  13566. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  13567. DEBUG_INFO("storeTempStopTransaction...\n");
  13568. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  13569. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  13570. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  13571. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13572. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  13573. {
  13574. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13575. {
  13576. tempIndex = ((gun_index==2) ? 1: 0);
  13577. }
  13578. else
  13579. {
  13580. tempIndex = gun_index;
  13581. }
  13582. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13583. {
  13584. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13585. {
  13586. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  13587. }
  13588. }// END OF CHAdeMO_QUANTITY
  13589. }
  13590. else if(gunType[gun_index] == GUN_TYPE_CCS)
  13591. {
  13592. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13593. {
  13594. tempIndex = ((gun_index==2) ? 1: 0);
  13595. }
  13596. else
  13597. {
  13598. tempIndex = gun_index;
  13599. }
  13600. for (int index = 0; index < CCS_QUANTITY; index++)
  13601. {
  13602. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13603. {
  13604. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  13605. }
  13606. }// END OF CCS_QUANTITY
  13607. }
  13608. else if(gunType[gun_index] == GUN_TYPE_GBT)
  13609. {
  13610. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13611. {
  13612. tempIndex = ((gun_index==2) ? 1: 0);
  13613. }
  13614. else
  13615. {
  13616. tempIndex = gun_index;
  13617. }
  13618. for (int index = 0; index < GB_QUANTITY; index++)
  13619. {
  13620. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13621. {
  13622. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  13623. }
  13624. }// END OF GB_QUANTITY
  13625. }
  13626. else if(gunType[gun_index] == GUN_TYPE_DO)
  13627. {
  13628. tempIndex = gun_index;
  13629. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13630. {
  13631. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13632. {
  13633. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  13634. }
  13635. }
  13636. }
  13637. else
  13638. {
  13639. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13640. {
  13641. tempIndex = 2;
  13642. }
  13643. else
  13644. {
  13645. tempIndex = gun_index;
  13646. }
  13647. for (int index = 0; index < AC_QUANTITY; index++)
  13648. {
  13649. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13650. {
  13651. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  13652. }
  13653. }// END OF AC_QUANTITY
  13654. }
  13655. //Stop Transaction Time
  13656. struct timeval tmnow;
  13657. struct tm *tm;
  13658. char buf[28];//, usec_buf[6];
  13659. gettimeofday(&tmnow, NULL);
  13660. time_t t;
  13661. t = time(NULL);
  13662. /*UTC time and date*/
  13663. tm = gmtime(&t);
  13664. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  13665. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  13666. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  13667. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13668. random_uuid(guid);
  13669. /***********************************transactionData******************************************************/
  13670. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  13671. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  13672. //=================================
  13673. //1. Transaction_Begin
  13674. //=================================
  13675. //============================== Energy.Active.Import.Interval ===========================================
  13676. //idx_sample=0;
  13677. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  13678. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  13679. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  13680. 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*/]);
  13681. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13682. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  13683. {
  13684. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  13685. }
  13686. else
  13687. {
  13688. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  13689. }
  13690. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  13691. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13692. //=================================
  13693. //2. Transaction_End
  13694. //=================================
  13695. //2.1====================================== Current.Import L1 ==============================================
  13696. //idx_sample=1;
  13697. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  13698. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  13699. {
  13700. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13701. {
  13702. tempIndex = ((gun_index==2) ? 1: 0);
  13703. }
  13704. else
  13705. {
  13706. tempIndex = gun_index;
  13707. }
  13708. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13709. {
  13710. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13711. {
  13712. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13713. }
  13714. }// End of for CHAdeMO_QUANTITY
  13715. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13716. }
  13717. else if(gunType[gun_index] == GUN_TYPE_CCS)
  13718. {
  13719. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13720. {
  13721. tempIndex = ((gun_index==2) ? 1: 0);
  13722. }
  13723. else
  13724. {
  13725. tempIndex = gun_index;
  13726. }
  13727. for (int index = 0; index < CCS_QUANTITY; index++)
  13728. {
  13729. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13730. {
  13731. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13732. }
  13733. }// End of for CCS_QUANTITY
  13734. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13735. }
  13736. else if(gunType[gun_index] == GUN_TYPE_GBT)
  13737. {
  13738. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13739. {
  13740. tempIndex = ((gun_index==2) ? 1: 0);
  13741. }
  13742. else
  13743. {
  13744. tempIndex = gun_index;
  13745. }
  13746. for (int index = 0; index < GB_QUANTITY; index++)
  13747. {
  13748. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13749. {
  13750. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13751. }
  13752. }// End of for GB_QUANTITY
  13753. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13754. }
  13755. else if(gunType[gun_index] == GUN_TYPE_DO)
  13756. {
  13757. tempIndex = gun_index;
  13758. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13759. {
  13760. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13761. {
  13762. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13763. }
  13764. }
  13765. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13766. }
  13767. else
  13768. {
  13769. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13770. {
  13771. tempIndex = 2;
  13772. }
  13773. else
  13774. {
  13775. tempIndex = gun_index;
  13776. }
  13777. for (int index = 0; index < AC_QUANTITY; index++)
  13778. {
  13779. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13780. {
  13781. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  13782. }
  13783. }// End of for AC_QUANTITY
  13784. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13785. }
  13786. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13787. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  13788. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  13789. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13790. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  13791. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13792. //2.2===================================== Energy.Active.Import.Interval ==========================================
  13793. //idx_sample=2;
  13794. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13795. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  13796. {
  13797. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13798. {
  13799. tempIndex = ((gun_index==2) ? 1: 0);
  13800. }
  13801. else
  13802. {
  13803. tempIndex = gun_index;
  13804. }
  13805. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13806. {
  13807. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13808. {
  13809. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13810. }
  13811. }// END OF CHAdeMO_QUANTITY
  13812. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13813. }
  13814. else if(gunType[gun_index] == GUN_TYPE_CCS)
  13815. {
  13816. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13817. {
  13818. tempIndex = ((gun_index==2) ? 1: 0);
  13819. }
  13820. else
  13821. {
  13822. tempIndex = gun_index;
  13823. }
  13824. for (int index = 0; index < CCS_QUANTITY; index++)
  13825. {
  13826. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13827. {
  13828. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13829. }
  13830. }// END OF CCS_QUANTITY
  13831. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13832. }
  13833. else if(gunType[gun_index] == GUN_TYPE_GBT)
  13834. {
  13835. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13836. {
  13837. tempIndex = ((gun_index==2) ? 1: 0);
  13838. }
  13839. else
  13840. {
  13841. tempIndex = gun_index;
  13842. }
  13843. for (int index = 0; index < GB_QUANTITY; index++)
  13844. {
  13845. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13846. {
  13847. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13848. }
  13849. }// END OF GB_QUANTITY
  13850. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13851. }
  13852. else if(gunType[gun_index] == GUN_TYPE_DO)
  13853. {
  13854. tempIndex = gun_index;
  13855. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13856. {
  13857. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13858. {
  13859. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13860. }
  13861. }
  13862. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13863. }
  13864. else
  13865. {
  13866. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13867. {
  13868. tempIndex = 2;
  13869. }
  13870. else
  13871. {
  13872. tempIndex = gun_index;
  13873. }
  13874. for (int index = 0; index < AC_QUANTITY; index++)
  13875. {
  13876. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13877. {
  13878. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13879. }
  13880. }// END OF AC_QUANTITY
  13881. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13882. }
  13883. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13884. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  13885. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  13886. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13887. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  13888. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13889. //2.3====================================== Power.Active.Import =========================================
  13890. //idx_sample=3;
  13891. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13892. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  13893. {
  13894. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13895. {
  13896. tempIndex = ((gun_index==2) ? 1: 0);
  13897. }
  13898. else
  13899. {
  13900. tempIndex = gun_index;
  13901. }
  13902. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13903. {
  13904. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13905. {
  13906. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13907. }
  13908. } // End for CHAdeMO_QUANTITY
  13909. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13910. }
  13911. else if(gunType[gun_index] == GUN_TYPE_CCS)
  13912. {
  13913. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13914. {
  13915. tempIndex = ((gun_index==2) ? 1: 0);
  13916. }
  13917. else
  13918. {
  13919. tempIndex = gun_index;
  13920. }
  13921. for (int index = 0; index < CCS_QUANTITY; index++)
  13922. {
  13923. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13924. {
  13925. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13926. }
  13927. } // END for CCS_QUANTITY
  13928. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13929. }
  13930. else if(gunType[gun_index] == GUN_TYPE_GBT)
  13931. {
  13932. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13933. {
  13934. tempIndex = ((gun_index==2) ? 1: 0);
  13935. }
  13936. else
  13937. {
  13938. tempIndex = gun_index;
  13939. }
  13940. for (int index = 0; index < GB_QUANTITY; index++)
  13941. {
  13942. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13943. {
  13944. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13945. }
  13946. }// END for GB_QUANTITY
  13947. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13948. }
  13949. else if(gunType[gun_index] == GUN_TYPE_DO)
  13950. {
  13951. tempIndex = gun_index;
  13952. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13953. {
  13954. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13955. {
  13956. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13957. }
  13958. }
  13959. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13960. }
  13961. else
  13962. {
  13963. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13964. {
  13965. tempIndex = 2;
  13966. }
  13967. else
  13968. {
  13969. tempIndex = gun_index;
  13970. }
  13971. for (int index = 0; index < AC_QUANTITY; index++)
  13972. {
  13973. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13974. {
  13975. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13976. }
  13977. } // END for AC_QUANTITY
  13978. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13979. }
  13980. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13981. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  13982. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  13983. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13984. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  13985. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  13986. //2.4====================================== Voltage L1 ====================================================
  13987. //idx_sample=4;
  13988. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13989. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  13990. {
  13991. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13992. {
  13993. tempIndex = ((gun_index==2) ? 1: 0);
  13994. }
  13995. else
  13996. {
  13997. tempIndex = gun_index;
  13998. }
  13999. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14000. {
  14001. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14002. {
  14003. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14004. }
  14005. } // END OF FOR CHAdeMO_QUANTITY
  14006. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14007. }
  14008. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14009. {
  14010. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14011. {
  14012. tempIndex = ((gun_index==2) ? 1: 0);
  14013. }
  14014. else
  14015. {
  14016. tempIndex = gun_index;
  14017. }
  14018. for (int index = 0; index < CCS_QUANTITY; index++)
  14019. {
  14020. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14021. {
  14022. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14023. }
  14024. } // END OF FOR CCS_QUANTITY
  14025. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14026. }
  14027. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14028. {
  14029. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14030. {
  14031. tempIndex = ((gun_index==2) ? 1: 0);
  14032. }
  14033. else
  14034. {
  14035. tempIndex = gun_index;
  14036. }
  14037. for (int index = 0; index < GB_QUANTITY; index++)
  14038. {
  14039. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14040. {
  14041. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14042. }
  14043. } // END OF FOR GB_QUANTITY
  14044. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14045. }
  14046. else if(gunType[gun_index] == GUN_TYPE_DO)
  14047. {
  14048. tempIndex = gun_index;
  14049. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14050. {
  14051. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14052. {
  14053. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14054. }
  14055. }
  14056. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14057. }
  14058. else
  14059. {
  14060. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14061. {
  14062. tempIndex = 2;
  14063. }
  14064. else
  14065. {
  14066. tempIndex = gun_index;
  14067. }
  14068. for (int index = 0; index < AC_QUANTITY; index++)
  14069. {
  14070. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14071. {
  14072. 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
  14073. }
  14074. } // END OF FOR AC_QUANTITY
  14075. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  14076. }
  14077. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14078. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  14079. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  14080. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  14081. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  14082. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  14083. //2.5============================================== End SoC =========================================================
  14084. //idx_sample=5;
  14085. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14086. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  14087. {
  14088. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  14089. {
  14090. tempIndex = ((gun_index==2) ? 1: 0);
  14091. }
  14092. else
  14093. {
  14094. tempIndex = gun_index;
  14095. }
  14096. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14097. {
  14098. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14099. {
  14100. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14101. {
  14102. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  14103. }
  14104. }
  14105. }
  14106. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14107. {
  14108. for (int index = 0; index < CCS_QUANTITY; index++)
  14109. {
  14110. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14111. {
  14112. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  14113. }
  14114. }
  14115. }
  14116. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14117. {
  14118. for (int index = 0; index < GB_QUANTITY; index++)
  14119. {
  14120. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14121. {
  14122. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  14123. }
  14124. }
  14125. }
  14126. else if(gunType[gun_index] == GUN_TYPE_DO)
  14127. {
  14128. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14129. {
  14130. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14131. {
  14132. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  14133. }
  14134. }
  14135. }
  14136. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14137. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  14138. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  14139. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  14140. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  14141. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  14142. } // END FOR DC CASE
  14143. //2.6====================================== Current.Import L2 ==============================================
  14144. // idx_sample=6;
  14145. // AC 3 phase L2 current
  14146. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  14147. {
  14148. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14149. {
  14150. tempIndex = 2;
  14151. }
  14152. else
  14153. {
  14154. tempIndex = gun_index;
  14155. }
  14156. for (int index = 0; index < AC_QUANTITY; index++)
  14157. {
  14158. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14159. {
  14160. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  14161. }
  14162. }// End of for AC_QUANTITY
  14163. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  14164. }
  14165. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14166. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  14167. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  14168. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  14169. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14170. //2.7====================================== Current.Import L3 ==============================================
  14171. // idx_sample=7;
  14172. // AC 3 phase L3 current
  14173. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  14174. {
  14175. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14176. {
  14177. tempIndex = 2;
  14178. }
  14179. else
  14180. {
  14181. tempIndex = gun_index;
  14182. }
  14183. for (int index = 0; index < AC_QUANTITY; index++)
  14184. {
  14185. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14186. {
  14187. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  14188. }
  14189. }// End of for AC_QUANTITY
  14190. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  14191. }
  14192. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14193. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  14194. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  14195. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  14196. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14197. //2.9====================================== Voltage L2 ====================================================
  14198. //idx_sample=8;
  14199. // AC 3 phase L2 volatge
  14200. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  14201. {
  14202. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14203. {
  14204. tempIndex = 2;
  14205. }
  14206. else
  14207. {
  14208. tempIndex = gun_index;
  14209. }
  14210. for (int index = 0; index < AC_QUANTITY; index++)
  14211. {
  14212. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14213. {
  14214. 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
  14215. }
  14216. } // END OF FOR AC_QUANTITY
  14217. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  14218. }
  14219. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14220. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  14221. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  14222. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  14223. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  14224. //2.10====================================== Voltage L3 ====================================================
  14225. //idx_sample=9;
  14226. // AC 3 phase L3 volatge
  14227. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  14228. {
  14229. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14230. {
  14231. tempIndex = 2;
  14232. }
  14233. else
  14234. {
  14235. tempIndex = gun_index;
  14236. }
  14237. for (int index = 0; index < AC_QUANTITY; index++)
  14238. {
  14239. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14240. {
  14241. 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
  14242. }
  14243. } // END OF FOR AC_QUANTITY
  14244. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  14245. }
  14246. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14247. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  14248. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  14249. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  14250. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  14251. //====================== Start SoC ================================
  14252. //idx_sample=10;
  14253. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14254. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  14255. {
  14256. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  14257. {
  14258. tempIndex = ((gun_index==2) ? 1: 0);
  14259. }
  14260. else
  14261. {
  14262. tempIndex = gun_index;
  14263. }
  14264. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14265. {
  14266. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14267. {
  14268. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14269. {
  14270. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  14271. }
  14272. }
  14273. }
  14274. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14275. {
  14276. for (int index = 0; index < CCS_QUANTITY; index++)
  14277. {
  14278. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14279. {
  14280. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  14281. }
  14282. }
  14283. }
  14284. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14285. {
  14286. for (int index = 0; index < GB_QUANTITY; index++)
  14287. {
  14288. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14289. {
  14290. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  14291. }
  14292. }
  14293. }
  14294. else if(gunType[gun_index] == GUN_TYPE_DO)
  14295. {
  14296. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14297. {
  14298. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14299. {
  14300. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  14301. }
  14302. }
  14303. }
  14304. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  14305. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  14306. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  14307. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  14308. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  14309. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  14310. } // END FOR DC CASE
  14311. //======================================== Message create ==============================================
  14312. json_object *StopTransaction = json_object_new_object();
  14313. json_object *transactionDatas = json_object_new_array();
  14314. json_object *sampledValues = json_object_new_array();
  14315. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  14316. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  14317. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  14318. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  14319. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  14320. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  14321. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  14322. {
  14323. json_object *transactionData = json_object_new_object();
  14324. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  14325. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  14326. {
  14327. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  14328. {
  14329. json_object *sampledValue = json_object_new_object();
  14330. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  14331. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  14332. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  14333. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  14334. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  14335. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  14336. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  14337. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  14338. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  14339. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  14340. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  14341. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  14342. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  14343. json_object_array_add(sampledValues, sampledValue);
  14344. }
  14345. }
  14346. json_object_object_add(transactionData, "sampledValue", sampledValues);
  14347. json_object_array_add(transactionDatas, transactionData);
  14348. }
  14349. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  14350. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  14351. ,MESSAGE_TYPE_CALL
  14352. ,guid
  14353. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  14354. json_object_put(StopTransaction);
  14355. // Check File "TempStopTransaction" Exist
  14356. if((access(TempStopTransaction,F_OK))!=-1)
  14357. {
  14358. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  14359. fclose(fopen(TempStopTransaction, "w"));
  14360. }
  14361. else
  14362. {
  14363. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  14364. FILE *log = fopen(TempStopTransaction, "w+");
  14365. if(log == NULL)
  14366. {
  14367. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  14368. return ;
  14369. }
  14370. else
  14371. {
  14372. fclose(log);
  14373. }
  14374. }
  14375. //Add TempStopTransaction | Update TempStopTransaction
  14376. // open file for writing
  14377. FILE *outfile;
  14378. outfile = fopen (TempStopTransaction, "a");
  14379. //DEBUG_INFO("data = %s\n", queuedata);
  14380. fputs(queuedata, outfile);
  14381. fputs("\n", outfile);
  14382. fclose (outfile);
  14383. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14384. }
  14385. void checkTempStopTransaction(int gun_index)
  14386. {
  14387. FILE *fptr1;
  14388. char ch;
  14389. char str[QUEUE_MESSAGE_LENGTH]={0};
  14390. char guid[37]={0};
  14391. char tempdata[65]={0};
  14392. char connectorStr[2]={0};
  14393. char TempStopTransaction[256];
  14394. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  14395. fptr1 = fopen(TempStopTransaction, "r");
  14396. //TempStopTransaction格式: 槍號,StopTransaction封包
  14397. if (!fptr1)
  14398. {
  14399. //printf(" File not found or unable to open the input file!!\n");
  14400. return ;
  14401. }
  14402. ch=fgetc(fptr1);
  14403. //printf(" Now the content of the file %s is : \n",fname);
  14404. rewind(fptr1);
  14405. if(ch!=EOF)
  14406. {
  14407. // copy all contents to the temporary file except the specific line
  14408. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  14409. {
  14410. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14411. if(str[0]=='\0')
  14412. {
  14413. break;
  14414. }
  14415. //TempStopTransaction格式: 槍號,StopTransaction封包
  14416. strncpy(connectorStr, str, 1);
  14417. if(atoi(connectorStr) != (gun_index+1))
  14418. {
  14419. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  14420. fclose(fptr1);
  14421. return ;
  14422. }
  14423. //random_uuid(guid);
  14424. strncpy(guid, str+6, 36); //copy guid
  14425. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  14426. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  14427. {
  14428. //DEBUG_INFO("StopTransaction mapitem pass\n");
  14429. }
  14430. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  14431. memset(str,0,ARRAY_SIZE(str));
  14432. }
  14433. }
  14434. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  14435. fclose(fptr1);
  14436. remove(TempStopTransaction); // remove the original file
  14437. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14438. }
  14439. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  14440. {
  14441. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  14442. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  14443. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  14444. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  14445. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  14446. }
  14447. int GetWebSocketPingInterval(void)
  14448. {
  14449. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14450. }
  14451. int GetServerSign(void)
  14452. {
  14453. return server_sign;
  14454. }
  14455. uint8_t GetOcppSecurityProfile()
  14456. {
  14457. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14458. }
  14459. void GetOcppChargerBoxId(uint8_t *data)
  14460. {
  14461. sprintf((char*)data, "%s", ShmOCPP16Data->ChargeBoxId);
  14462. }
  14463. void GetOcppSecurityPassword(uint8_t *data)
  14464. {
  14465. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14466. }
  14467. void SetOcppVersion(uint8_t *version)
  14468. {
  14469. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  14470. DEBUG_INFO("ocpp version: %s\n", version);
  14471. if(strstr((char*)version, "ocpp1.6") != NULL)
  14472. {
  14473. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  14474. }
  14475. else if(strstr((char*)version, "ocpp2.0") != NULL)
  14476. {
  14477. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  14478. system("pkill OcppBackend");
  14479. }
  14480. }
  14481. void SetServerSign(int value)
  14482. {
  14483. server_sign = value;
  14484. }
  14485. int GetBootNotificationInterval(void)
  14486. {
  14487. return BootNotificationInterval;
  14488. }
  14489. int GetInternetConn(void)
  14490. {
  14491. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  14492. }
  14493. int isConnectorInitMode(int gun_index)
  14494. {
  14495. int tempIndex = 0;
  14496. int result = TRUE;
  14497. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14498. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14499. {
  14500. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14501. {
  14502. tempIndex = ((gun_index==2) ? 1: 0);
  14503. }
  14504. else
  14505. {
  14506. tempIndex = gun_index;
  14507. }
  14508. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14509. {
  14510. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  14511. {
  14512. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  14513. } //end of the same index
  14514. }//end of for CHAdeMO_QUANTITY
  14515. }
  14516. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14517. {
  14518. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14519. {
  14520. tempIndex = ((gun_index==2) ? 1: 0);
  14521. }
  14522. else
  14523. {
  14524. tempIndex = gun_index;
  14525. }
  14526. for (int index = 0; index < CCS_QUANTITY; index++)
  14527. {
  14528. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14529. {
  14530. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  14531. } //end of the same index
  14532. } // end of for CCS_QUANTITY
  14533. }
  14534. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14535. {
  14536. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14537. {
  14538. tempIndex = ((gun_index==2) ? 1: 0);
  14539. }
  14540. else
  14541. {
  14542. tempIndex = gun_index;
  14543. }
  14544. for (int index = 0; index < GB_QUANTITY; index++)
  14545. {
  14546. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14547. {
  14548. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  14549. } //end of the same index
  14550. } // end of for GB_QUANTITY
  14551. }
  14552. else if(gunType[gun_index] == GUN_TYPE_DO)
  14553. {
  14554. tempIndex = gun_index;
  14555. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14556. {
  14557. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14558. {
  14559. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  14560. } //end of the same index
  14561. }
  14562. }
  14563. else
  14564. {
  14565. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14566. {
  14567. tempIndex = 2;
  14568. }
  14569. else
  14570. {
  14571. tempIndex = gun_index;
  14572. }
  14573. for (int index = 0; index < AC_QUANTITY; index++)
  14574. {
  14575. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14576. {
  14577. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  14578. }//end of the same index
  14579. }//end of for AC_QUANTITY
  14580. }
  14581. return result;
  14582. }
  14583. void refreshProcDogTimer()
  14584. {
  14585. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  14586. }
  14587. void InitialSystemValue(void)
  14588. {
  14589. int connectorIndex = 0;
  14590. //int valueASCII = 0;
  14591. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14592. gunTotalNumber=0;
  14593. SystemInitial = 0;
  14594. localversion=0;
  14595. BootNotificationInterval = 0;
  14596. authorizeRetryTimes = 0;
  14597. GunStatusInterval = 10;
  14598. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14599. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14600. //Hear Beat
  14601. HeartBeatWithNOResponse = 0;
  14602. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  14603. FirstHeartBeat = 0;
  14604. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  14605. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  14606. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  14607. memset(statusModeChage, 0, ARRAY_SIZE(statusModeChage));
  14608. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  14609. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  14610. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  14611. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  14612. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  14613. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  14614. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  14615. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  14616. memset(gunType, 0, ARRAY_SIZE(gunType));
  14617. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14618. {
  14619. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O')
  14620. {
  14621. // DO series
  14622. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  14623. {
  14624. SystemInitial = SystemInitial + 1;
  14625. gunTotalNumber = gunTotalNumber + 1;
  14626. gunType[connectorIndex] = GUN_TYPE_DO;
  14627. connectorIndex = connectorIndex + 1;
  14628. }
  14629. }
  14630. else
  14631. {
  14632. // DM, DW, DS series
  14633. //check connector / socket type (index: 8, 9, 10)
  14634. for(int index=7; index <10 ; index++)
  14635. {
  14636. if(index != 8)
  14637. {
  14638. // DC Connector
  14639. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  14640. {
  14641. SystemInitial = SystemInitial + 1;
  14642. gunTotalNumber = gunTotalNumber + 1;
  14643. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  14644. connectorIndex = connectorIndex + 1;
  14645. }
  14646. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  14647. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  14648. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  14649. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  14650. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  14651. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  14652. {
  14653. SystemInitial = SystemInitial + 1;
  14654. gunTotalNumber = gunTotalNumber + 1;
  14655. gunType[connectorIndex] = GUN_TYPE_CCS;
  14656. connectorIndex = connectorIndex + 1;
  14657. }
  14658. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  14659. {
  14660. SystemInitial = SystemInitial + 1;
  14661. gunTotalNumber = gunTotalNumber + 1;
  14662. gunType[connectorIndex] = GUN_TYPE_GBT;
  14663. connectorIndex = connectorIndex + 1;
  14664. }
  14665. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  14666. {
  14667. SystemInitial = SystemInitial + 1;
  14668. gunTotalNumber = gunTotalNumber + 1;
  14669. gunType[connectorIndex] = GUN_TYPE_DO;
  14670. connectorIndex = connectorIndex + 1;
  14671. }
  14672. }
  14673. else
  14674. {
  14675. // AC Connector
  14676. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14677. {
  14678. SystemInitial = SystemInitial + 1;
  14679. gunTotalNumber = gunTotalNumber + 1;
  14680. gunType[connectorIndex] = GUN_TYPE_AC;
  14681. connectorIndex = connectorIndex + 1;
  14682. }
  14683. }
  14684. }
  14685. }
  14686. //DEBUG_INFO("DC ...\n");
  14687. }
  14688. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  14689. {
  14690. //check connector / socket type (index: 8, 9, 10)
  14691. for(int index=7; index <10 ; index++)
  14692. {
  14693. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14694. {
  14695. SystemInitial = SystemInitial + 1;
  14696. gunTotalNumber = gunTotalNumber + 1;
  14697. gunType[connectorIndex] = GUN_TYPE_AC;
  14698. connectorIndex = connectorIndex + 1;
  14699. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  14700. }
  14701. }
  14702. }
  14703. //Status && ConnectorPlugIn Setting
  14704. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14705. {
  14706. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  14707. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  14708. }
  14709. for (int index = 0; index < CCS_QUANTITY; index++)
  14710. {
  14711. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  14712. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  14713. }
  14714. for (int index = 0; index < GB_QUANTITY; index++)
  14715. {
  14716. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  14717. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  14718. }
  14719. for (int index = 0; index < AC_QUANTITY; index++)
  14720. {
  14721. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  14722. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  14723. }
  14724. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14725. {
  14726. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  14727. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  14728. }
  14729. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  14730. {
  14731. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  14732. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  14733. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  14734. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  14735. }
  14736. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  14737. clientTime.Heartbeat=time((time_t*)NULL);
  14738. sleep(1);
  14739. }
  14740. void LWS_Send(char * str)
  14741. {
  14742. //=====================================================
  14743. // Check InternetConn 0: disconnected, 1: connected
  14744. //====================================================
  14745. if(GetOcppConnStatus() == 0)
  14746. {
  14747. DEBUG_INFO("offline now !!!\n");
  14748. return;
  14749. }
  14750. pthread_mutex_lock(&lock_send);
  14751. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14752. sprintf((char *)SendBuffer, "%s", str);
  14753. SendBufLen = strlen(str);
  14754. pthread_mutex_unlock(&lock_send);
  14755. lws_callback_on_writable(wsi_client);
  14756. //lws_service(context, 0);
  14757. //sleep(1);
  14758. }
  14759. void LWS_SendNow(char * str)
  14760. {
  14761. //=====================================================
  14762. // Check InternetConn 0: disconnected, 1: connected
  14763. //====================================================
  14764. if(GetOcppConnStatus() == 0)
  14765. {
  14766. DEBUG_INFO("offline now !!!\n");
  14767. return;
  14768. }
  14769. pthread_mutex_lock(&lock_send);
  14770. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14771. sprintf((char *)SendBuffer, "%s", str);
  14772. SendBufLen = strlen(str);
  14773. pthread_mutex_unlock(&lock_send);
  14774. lws_callback_on_writable(wsi_client);
  14775. lws_service(context, 0);
  14776. //sleep(1);
  14777. }