MessageHandler.c 728 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089
  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. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  3659. {
  3660. //============================================ Energy.Active.Import.Interval ================================
  3661. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  3662. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  3663. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  3664. 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*/]);
  3665. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3666. 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))
  3667. {
  3668. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  3669. }
  3670. else
  3671. {
  3672. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  3673. }
  3674. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  3675. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3676. }
  3677. //=================================
  3678. // Transaction_End
  3679. //=================================
  3680. // ================================= Current.Import L1 ===============================================
  3681. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  3682. {
  3683. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  3684. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3685. {
  3686. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3687. {
  3688. tempIndex = ((gun_index==2) ? 1: 0);
  3689. }
  3690. else
  3691. {
  3692. tempIndex = gun_index;
  3693. }
  3694. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3695. {
  3696. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3697. {
  3698. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3699. }
  3700. }// End of for CHAdeMO_QUANTITY
  3701. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3702. }
  3703. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3704. {
  3705. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3706. {
  3707. tempIndex = ((gun_index==2) ? 1: 0);
  3708. }
  3709. else
  3710. {
  3711. tempIndex = gun_index;
  3712. }
  3713. for (int index = 0; index < CCS_QUANTITY; index++)
  3714. {
  3715. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3716. {
  3717. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3718. }
  3719. }// End of for CCS_QUANTITY
  3720. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3721. }
  3722. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3723. {
  3724. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3725. {
  3726. tempIndex = ((gun_index==2) ? 1: 0);
  3727. }
  3728. else
  3729. {
  3730. tempIndex = gun_index;
  3731. }
  3732. for (int index = 0; index < GB_QUANTITY; index++)
  3733. {
  3734. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3735. {
  3736. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3737. }
  3738. }// End of for GB_QUANTITY
  3739. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3740. }
  3741. else if(gunType[gun_index] == GUN_TYPE_DO)
  3742. {
  3743. tempIndex = gun_index;
  3744. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3745. {
  3746. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3747. {
  3748. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3749. }
  3750. }
  3751. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3752. }
  3753. else
  3754. {
  3755. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3756. {
  3757. tempIndex = 2;
  3758. }
  3759. else
  3760. {
  3761. tempIndex = gun_index;
  3762. }
  3763. for (int index = 0; index < AC_QUANTITY; index++)
  3764. {
  3765. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3766. {
  3767. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  3768. }
  3769. }// End of for AC_QUANTITY
  3770. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  3771. }
  3772. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3773. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  3774. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  3775. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  3776. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3777. }
  3778. // ================================= Energy.Active.Import.Interval ==============================================
  3779. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  3780. {
  3781. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3782. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3783. {
  3784. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3785. {
  3786. tempIndex = ((gun_index==2) ? 1: 0);
  3787. }
  3788. else
  3789. {
  3790. tempIndex = gun_index;
  3791. }
  3792. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3793. {
  3794. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3795. {
  3796. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3797. }
  3798. }// END OF CHAdeMO_QUANTITY
  3799. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3800. }
  3801. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3802. {
  3803. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3804. {
  3805. tempIndex = ((gun_index==2) ? 1: 0);
  3806. }
  3807. else
  3808. {
  3809. tempIndex = gun_index;
  3810. }
  3811. for (int index = 0; index < CCS_QUANTITY; index++)
  3812. {
  3813. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3814. {
  3815. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3816. }
  3817. }// END OF CCS_QUANTITY
  3818. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3819. }
  3820. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3821. {
  3822. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3823. {
  3824. tempIndex = ((gun_index==2) ? 1: 0);
  3825. }
  3826. else
  3827. {
  3828. tempIndex = gun_index;
  3829. }
  3830. for (int index = 0; index < GB_QUANTITY; index++)
  3831. {
  3832. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3833. {
  3834. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3835. }
  3836. }// END OF GB_QUANTITY
  3837. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3838. }
  3839. else if(gunType[gun_index] == GUN_TYPE_DO)
  3840. {
  3841. tempIndex = gun_index;
  3842. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3843. {
  3844. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3845. {
  3846. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3847. }
  3848. }
  3849. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3850. }
  3851. else
  3852. {
  3853. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3854. {
  3855. tempIndex = 2;
  3856. }
  3857. else
  3858. {
  3859. tempIndex = gun_index;
  3860. }
  3861. for (int index = 0; index < AC_QUANTITY; index++)
  3862. {
  3863. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3864. {
  3865. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3866. }
  3867. }// END OF AC_QUANTITY
  3868. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  3869. }
  3870. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3871. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  3872. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  3873. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  3874. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3875. }
  3876. //=================================== Power.Active.Import ==================================================
  3877. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  3878. {
  3879. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3880. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3881. {
  3882. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3883. {
  3884. tempIndex = ((gun_index==2) ? 1: 0);
  3885. }
  3886. else
  3887. {
  3888. tempIndex = gun_index;
  3889. }
  3890. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3891. {
  3892. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3893. {
  3894. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3895. }
  3896. } // End for CHAdeMO_QUANTITY
  3897. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3898. }
  3899. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3900. {
  3901. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3902. {
  3903. tempIndex = ((gun_index==2) ? 1: 0);
  3904. }
  3905. else
  3906. {
  3907. tempIndex = gun_index;
  3908. }
  3909. for (int index = 0; index < CCS_QUANTITY; index++)
  3910. {
  3911. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3912. {
  3913. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3914. }
  3915. } // END for CCS_QUANTITY
  3916. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3917. }
  3918. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3919. {
  3920. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3921. {
  3922. tempIndex = ((gun_index==2) ? 1: 0);
  3923. }
  3924. else
  3925. {
  3926. tempIndex = gun_index;
  3927. }
  3928. for (int index = 0; index < GB_QUANTITY; index++)
  3929. {
  3930. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3931. {
  3932. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3933. }
  3934. }// END for GB_QUANTITY
  3935. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3936. }
  3937. else if(gunType[gun_index] == GUN_TYPE_DO)
  3938. {
  3939. tempIndex = gun_index;
  3940. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3941. {
  3942. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3943. {
  3944. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3945. }
  3946. }
  3947. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3948. }
  3949. else
  3950. {
  3951. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3952. {
  3953. tempIndex = 2;
  3954. }
  3955. else
  3956. {
  3957. tempIndex = gun_index;
  3958. }
  3959. for (int index = 0; index < AC_QUANTITY; index++)
  3960. {
  3961. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3962. {
  3963. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3964. }
  3965. } // END for AC_QUANTITY
  3966. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  3967. }
  3968. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3969. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  3970. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  3971. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  3972. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  3973. }
  3974. //============================ Voltage L1 ====================================
  3975. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  3976. {
  3977. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3978. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3979. {
  3980. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3981. {
  3982. tempIndex = ((gun_index==2) ? 1: 0);
  3983. }
  3984. else
  3985. {
  3986. tempIndex = gun_index;
  3987. }
  3988. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3989. {
  3990. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3991. {
  3992. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3993. }
  3994. } // END OF FOR CHAdeMO_QUANTITY
  3995. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3996. }
  3997. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3998. {
  3999. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4000. {
  4001. tempIndex = ((gun_index==2) ? 1: 0);
  4002. }
  4003. else
  4004. {
  4005. tempIndex = gun_index;
  4006. }
  4007. for (int index = 0; index < CCS_QUANTITY; index++)
  4008. {
  4009. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4010. {
  4011. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4012. }
  4013. } // END OF FOR CCS_QUANTITY
  4014. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4015. }
  4016. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4017. {
  4018. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4019. {
  4020. tempIndex = ((gun_index==2) ? 1: 0);
  4021. }
  4022. else
  4023. {
  4024. tempIndex = gun_index;
  4025. }
  4026. for (int index = 0; index < GB_QUANTITY; index++)
  4027. {
  4028. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4029. {
  4030. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4031. }
  4032. } // END OF FOR GB_QUANTITY
  4033. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4034. }
  4035. else if(gunType[gun_index] == GUN_TYPE_DO)
  4036. {
  4037. tempIndex = gun_index;
  4038. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4039. {
  4040. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4041. {
  4042. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4043. }
  4044. }
  4045. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4046. }
  4047. else
  4048. {
  4049. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4050. {
  4051. tempIndex = 2;
  4052. }
  4053. else
  4054. {
  4055. tempIndex = gun_index;
  4056. }
  4057. for (int index = 0; index < AC_QUANTITY; index++)
  4058. {
  4059. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4060. {
  4061. 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
  4062. }
  4063. } // END OF FOR AC_QUANTITY
  4064. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  4065. }
  4066. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4067. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  4068. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  4069. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  4070. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4071. }
  4072. //====================== End SoC ================================
  4073. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4074. {
  4075. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4076. 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))
  4077. {
  4078. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4079. {
  4080. tempIndex = ((gun_index==2) ? 1: 0);
  4081. }
  4082. else
  4083. {
  4084. tempIndex = gun_index;
  4085. }
  4086. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4087. {
  4088. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4089. {
  4090. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4091. {
  4092. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  4093. }
  4094. }
  4095. }
  4096. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4097. {
  4098. for (int index = 0; index < CCS_QUANTITY; index++)
  4099. {
  4100. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4101. {
  4102. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  4103. }
  4104. }
  4105. }
  4106. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4107. {
  4108. for (int index = 0; index < GB_QUANTITY; index++)
  4109. {
  4110. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4111. {
  4112. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  4113. }
  4114. }
  4115. }
  4116. else if(gunType[gun_index] == GUN_TYPE_DO)
  4117. {
  4118. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4119. {
  4120. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4121. {
  4122. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  4123. }
  4124. }
  4125. }
  4126. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4127. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  4128. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4129. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  4130. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  4131. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4132. } // END FOR DC CASE
  4133. }
  4134. // ================================= Current.Import L2 ===============================================
  4135. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4136. {
  4137. // AC 3 phse L2 current
  4138. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4139. {
  4140. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4141. {
  4142. tempIndex = 2;
  4143. }
  4144. else
  4145. {
  4146. tempIndex = gun_index;
  4147. }
  4148. for (int index = 0; index < AC_QUANTITY; index++)
  4149. {
  4150. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4151. {
  4152. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  4153. }
  4154. }// End of for AC_QUANTITY
  4155. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  4156. }
  4157. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4158. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  4159. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  4160. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  4161. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4162. }
  4163. // ================================= Current.Import L3 ===============================================
  4164. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4165. {
  4166. // AC 3 phse L3 current
  4167. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4168. {
  4169. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4170. {
  4171. tempIndex = 2;
  4172. }
  4173. else
  4174. {
  4175. tempIndex = gun_index;
  4176. }
  4177. for (int index = 0; index < AC_QUANTITY; index++)
  4178. {
  4179. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4180. {
  4181. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  4182. }
  4183. }// End of for AC_QUANTITY
  4184. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  4185. }
  4186. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4187. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  4188. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  4189. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  4190. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4191. }
  4192. //============================ Voltage L2 ====================================
  4193. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4194. {
  4195. // AC 3 phse L2 voltage
  4196. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4197. {
  4198. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4199. {
  4200. tempIndex = 2;
  4201. }
  4202. else
  4203. {
  4204. tempIndex = gun_index;
  4205. }
  4206. for (int index = 0; index < AC_QUANTITY; index++)
  4207. {
  4208. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4209. {
  4210. 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
  4211. }
  4212. } // END OF FOR AC_QUANTITY
  4213. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  4214. }
  4215. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4216. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  4217. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  4218. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  4219. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4220. }
  4221. //============================ Voltage L3 ====================================
  4222. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4223. {
  4224. // AC 3 phse L3 voltage
  4225. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4226. {
  4227. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4228. {
  4229. tempIndex = 2;
  4230. }
  4231. else
  4232. {
  4233. tempIndex = gun_index;
  4234. }
  4235. for (int index = 0; index < AC_QUANTITY; index++)
  4236. {
  4237. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4238. {
  4239. 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
  4240. }
  4241. } // END OF FOR AC_QUANTITY
  4242. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  4243. }
  4244. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4245. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  4246. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  4247. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  4248. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4249. }
  4250. //====================== Start SoC ================================
  4251. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4252. {
  4253. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4254. 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))
  4255. {
  4256. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4257. {
  4258. tempIndex = ((gun_index==2) ? 1: 0);
  4259. }
  4260. else
  4261. {
  4262. tempIndex = gun_index;
  4263. }
  4264. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4265. {
  4266. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4267. {
  4268. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4269. {
  4270. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  4271. }
  4272. }
  4273. }
  4274. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4275. {
  4276. for (int index = 0; index < CCS_QUANTITY; index++)
  4277. {
  4278. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4279. {
  4280. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  4281. }
  4282. }
  4283. }
  4284. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4285. {
  4286. for (int index = 0; index < GB_QUANTITY; index++)
  4287. {
  4288. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4289. {
  4290. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  4291. }
  4292. }
  4293. }
  4294. else if(gunType[gun_index] == GUN_TYPE_DO)
  4295. {
  4296. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4297. {
  4298. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4299. {
  4300. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  4301. }
  4302. }
  4303. }
  4304. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4305. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  4306. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4307. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  4308. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  4309. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4310. } // END FOR DC CASE
  4311. }
  4312. //================================================ Message create ====================================================
  4313. json_object *StopTransaction = json_object_new_object();
  4314. json_object *transactionDatas = json_object_new_array();
  4315. json_object *sampledValues = json_object_new_array();
  4316. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  4317. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  4318. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  4319. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  4320. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  4321. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  4322. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  4323. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  4324. {
  4325. json_object *transactionData = json_object_new_object();
  4326. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  4327. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  4328. {
  4329. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  4330. {
  4331. json_object *sampledValue = json_object_new_object();
  4332. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  4333. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  4334. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  4335. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  4336. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  4337. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  4338. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  4339. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  4340. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  4341. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  4342. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  4343. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  4344. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  4345. json_object_array_add(sampledValues, sampledValue);
  4346. }
  4347. }
  4348. json_object_object_add(transactionData, "sampledValue", sampledValues);
  4349. json_object_array_add(transactionDatas, transactionData);
  4350. }
  4351. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  4352. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  4353. ,MESSAGE_TYPE_CALL
  4354. ,guid
  4355. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  4356. json_object_put(StopTransaction);
  4357. #if 1 // for TempStopTransaction
  4358. //Delete TempStopTransaction
  4359. if((access(TempStopTransaction,F_OK))!=-1)
  4360. {
  4361. remove(TempStopTransaction); // remove file "TempStopTransaction"
  4362. }
  4363. #endif
  4364. #if 1
  4365. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4366. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4367. {
  4368. result = PASS;
  4369. //DEBUG_INFO("StopTransaction mapitem pass\n");
  4370. }
  4371. #endif
  4372. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4373. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4374. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  4375. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  4376. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4377. {
  4378. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  4379. }
  4380. //for test
  4381. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4382. return result;
  4383. }
  4384. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  4385. {
  4386. mtrace();
  4387. int result = FAIL;
  4388. char guid[37]={0};
  4389. char tempdata[65]={0};
  4390. int tempIndex = 0;
  4391. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4392. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4393. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  4394. //set value
  4395. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4396. 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) )?
  4397. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  4398. -1);
  4399. random_uuid(guid);
  4400. //UTC Date time
  4401. struct timeval tmnow;
  4402. struct tm *tm;
  4403. char buf[28];//, usec_buf[6];
  4404. gettimeofday(&tmnow, NULL);
  4405. time_t t;
  4406. t = time(NULL);
  4407. /*UTC time and date*/
  4408. tm = gmtime(&t);
  4409. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4410. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4411. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4412. //********************************(1)Current.Import L1************************************************/
  4413. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  4414. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  4415. (dataType == ReadingContext_Trigger))
  4416. {
  4417. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4418. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4419. {
  4420. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4421. {
  4422. tempIndex = ((gun_index==2) ? 1: 0);
  4423. }
  4424. else
  4425. {
  4426. tempIndex = gun_index;
  4427. }
  4428. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4429. {
  4430. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4431. {
  4432. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4433. }
  4434. }
  4435. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4436. }
  4437. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4438. {
  4439. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4440. {
  4441. tempIndex = ((gun_index==2) ? 1: 0);
  4442. }
  4443. else
  4444. {
  4445. tempIndex = gun_index;
  4446. }
  4447. for (int index = 0; index < CCS_QUANTITY; index++)
  4448. {
  4449. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4450. {
  4451. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4452. }
  4453. }
  4454. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4455. }
  4456. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4457. {
  4458. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4459. {
  4460. tempIndex = ((gun_index==2) ? 1: 0);
  4461. }
  4462. else
  4463. {
  4464. tempIndex = gun_index;
  4465. }
  4466. for (int index = 0; index < GB_QUANTITY; index++)
  4467. {
  4468. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4469. {
  4470. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4471. }
  4472. }
  4473. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4474. }
  4475. else if(gunType[gun_index] == GUN_TYPE_DO)
  4476. {
  4477. tempIndex = gun_index;
  4478. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4479. {
  4480. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4481. {
  4482. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  4483. }
  4484. }
  4485. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4486. }
  4487. else
  4488. {
  4489. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4490. {
  4491. tempIndex = 2;
  4492. }
  4493. else
  4494. {
  4495. tempIndex = gun_index;
  4496. }
  4497. for (int index = 0; index < AC_QUANTITY; index++)
  4498. {
  4499. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4500. {
  4501. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4502. }
  4503. }
  4504. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4505. }
  4506. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4507. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4508. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4509. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4510. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4511. }
  4512. //********************************(2)Energy.Active.Import.Register ************************************************/
  4513. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4514. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4515. (dataType == ReadingContext_Trigger))
  4516. {
  4517. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4518. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4519. {
  4520. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4521. {
  4522. tempIndex = ((gun_index==2) ? 1: 0);
  4523. }
  4524. else
  4525. {
  4526. tempIndex = gun_index;
  4527. }
  4528. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4529. {
  4530. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4531. {
  4532. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4533. }
  4534. }
  4535. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4536. }
  4537. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4538. {
  4539. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4540. {
  4541. tempIndex = ((gun_index==2) ? 1: 0);
  4542. }
  4543. else
  4544. {
  4545. tempIndex = gun_index;
  4546. }
  4547. for (int index = 0; index < CCS_QUANTITY; index++)
  4548. {
  4549. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4550. {
  4551. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4552. }
  4553. }
  4554. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4555. }
  4556. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4557. {
  4558. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4559. {
  4560. tempIndex = ((gun_index==2) ? 1: 0);
  4561. }
  4562. else
  4563. {
  4564. tempIndex = gun_index;
  4565. }
  4566. for (int index = 0; index < GB_QUANTITY; index++)
  4567. {
  4568. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4569. {
  4570. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4571. }
  4572. }
  4573. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4574. }
  4575. else if(gunType[gun_index] == GUN_TYPE_DO)
  4576. {
  4577. tempIndex = gun_index;
  4578. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4579. {
  4580. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4581. {
  4582. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  4583. }
  4584. }
  4585. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4586. }
  4587. else
  4588. {
  4589. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4590. {
  4591. tempIndex = 2;
  4592. }
  4593. else
  4594. {
  4595. tempIndex = gun_index;
  4596. }
  4597. for (int index = 0; index < AC_QUANTITY; index++)
  4598. {
  4599. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4600. {
  4601. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  4602. }
  4603. }
  4604. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4605. }
  4606. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  4607. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  4608. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  4609. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  4610. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4611. }
  4612. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  4613. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  4614. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  4615. (dataType == ReadingContext_Trigger))
  4616. {
  4617. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4618. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4619. {
  4620. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4621. {
  4622. tempIndex = ((gun_index==2) ? 1: 0);
  4623. }
  4624. else
  4625. {
  4626. tempIndex = gun_index;
  4627. }
  4628. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4629. {
  4630. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4631. {
  4632. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  4633. }
  4634. } // END OF FOR CHAdeMO_QUANTITY
  4635. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4636. }
  4637. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4638. {
  4639. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4640. {
  4641. tempIndex = ((gun_index==2) ? 1: 0);
  4642. }
  4643. else
  4644. {
  4645. tempIndex = gun_index;
  4646. }
  4647. for (int index = 0; index < CCS_QUANTITY; index++)
  4648. {
  4649. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4650. {
  4651. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  4652. }
  4653. } // END OF CCS_QUANTITY
  4654. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4655. }
  4656. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4657. {
  4658. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4659. {
  4660. tempIndex = ((gun_index==2) ? 1: 0);
  4661. }
  4662. else
  4663. {
  4664. tempIndex = gun_index;
  4665. }
  4666. for (int index = 0; index < GB_QUANTITY; index++)
  4667. {
  4668. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4669. {
  4670. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  4671. }
  4672. } // END OF GB_QUANTITY
  4673. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4674. }
  4675. else if(gunType[gun_index] == GUN_TYPE_DO)
  4676. {
  4677. tempIndex = gun_index;
  4678. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4679. {
  4680. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4681. {
  4682. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  4683. }
  4684. }
  4685. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4686. }
  4687. else
  4688. {
  4689. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4690. {
  4691. tempIndex = 2;
  4692. }
  4693. else
  4694. {
  4695. tempIndex = gun_index;
  4696. }
  4697. for (int index = 0; index < AC_QUANTITY; index++)
  4698. {
  4699. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4700. {
  4701. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  4702. }
  4703. }
  4704. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  4705. }
  4706. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  4707. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  4708. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  4709. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  4710. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4711. }
  4712. //********************************(4)Power.Active.Import************************************************/
  4713. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Power.Active.Import") != NULL)) ||
  4714. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Power.Active.Import") != NULL)) ||
  4715. (dataType == ReadingContext_Trigger))
  4716. {
  4717. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4718. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4719. {
  4720. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4721. {
  4722. tempIndex = ((gun_index==2) ? 1: 0);
  4723. }
  4724. else
  4725. {
  4726. tempIndex = gun_index;
  4727. }
  4728. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4729. {
  4730. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4731. {
  4732. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  4733. }
  4734. } // END OF FOR
  4735. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4736. }
  4737. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4738. {
  4739. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4740. {
  4741. tempIndex = ((gun_index==2) ? 1: 0);
  4742. }
  4743. else
  4744. {
  4745. tempIndex = gun_index;
  4746. }
  4747. for (int index = 0; index < CCS_QUANTITY; index++)
  4748. {
  4749. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4750. {
  4751. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  4752. }
  4753. }
  4754. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4755. }
  4756. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4757. {
  4758. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4759. {
  4760. tempIndex = ((gun_index==2) ? 1: 0);
  4761. }
  4762. else
  4763. {
  4764. tempIndex = gun_index;
  4765. }
  4766. for (int index = 0; index < GB_QUANTITY; index++)
  4767. {
  4768. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4769. {
  4770. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4771. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  4772. }
  4773. }
  4774. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4775. }
  4776. else if(gunType[gun_index] == GUN_TYPE_DO)
  4777. {
  4778. tempIndex = gun_index;
  4779. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4780. {
  4781. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4782. {
  4783. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4784. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  4785. }
  4786. }
  4787. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4788. }
  4789. else
  4790. {
  4791. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4792. {
  4793. tempIndex = 2;
  4794. }
  4795. else
  4796. {
  4797. tempIndex = gun_index;
  4798. }
  4799. for (int index = 0; index < AC_QUANTITY; index++)
  4800. {
  4801. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4802. {
  4803. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  4804. }
  4805. }
  4806. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  4807. }
  4808. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  4809. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  4810. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  4811. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  4812. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  4813. }
  4814. //***********************************************(5)VOLTAGE L1******************************************************/
  4815. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  4816. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  4817. (dataType == ReadingContext_Trigger))
  4818. {
  4819. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4820. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4821. {
  4822. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4823. {
  4824. tempIndex = ((gun_index==2) ? 1: 0);
  4825. }
  4826. else
  4827. {
  4828. tempIndex = gun_index;
  4829. }
  4830. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4831. {
  4832. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4833. {
  4834. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  4835. }
  4836. }
  4837. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4838. }
  4839. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4840. {
  4841. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4842. {
  4843. tempIndex = ((gun_index==2) ? 1: 0);
  4844. }
  4845. else
  4846. {
  4847. tempIndex = gun_index;
  4848. }
  4849. for (int index = 0; index < CCS_QUANTITY; index++)
  4850. {
  4851. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4852. {
  4853. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  4854. }
  4855. }
  4856. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4857. }
  4858. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4859. {
  4860. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4861. {
  4862. tempIndex = ((gun_index==2) ? 1: 0);
  4863. }
  4864. else
  4865. {
  4866. tempIndex = gun_index;
  4867. }
  4868. for (int index = 0; index < GB_QUANTITY; index++)
  4869. {
  4870. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4871. {
  4872. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  4873. }
  4874. }
  4875. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4876. }
  4877. else if(gunType[gun_index] == GUN_TYPE_DO)
  4878. {
  4879. tempIndex = gun_index;
  4880. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4881. {
  4882. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4883. {
  4884. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  4885. }
  4886. }
  4887. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4888. }
  4889. else
  4890. {
  4891. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4892. {
  4893. tempIndex = 2;
  4894. }
  4895. else
  4896. {
  4897. tempIndex = gun_index;
  4898. }
  4899. for (int index = 0; index < AC_QUANTITY; index++)
  4900. {
  4901. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4902. {
  4903. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  4904. }
  4905. }
  4906. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  4907. }
  4908. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  4909. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  4910. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  4911. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  4912. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4913. }
  4914. //***********************************************(6)SOC******************************************************/
  4915. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "SOC") != NULL)) ||
  4916. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "SOC") != NULL)) ||
  4917. (dataType == ReadingContext_Trigger))
  4918. {
  4919. 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))
  4920. {
  4921. //idx_sample=5;
  4922. //sampledValue = NULL;
  4923. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4924. {
  4925. tempIndex = ((gun_index==2) ? 1: 0);
  4926. }
  4927. else
  4928. {
  4929. tempIndex = gun_index;
  4930. }
  4931. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4932. {
  4933. //tempIndex = ((gun_index==2) ? 1: 0);
  4934. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4935. {
  4936. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4937. {
  4938. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  4939. }
  4940. }
  4941. }
  4942. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4943. {
  4944. //tempIndex = ((gun_index==2) ? 1: 0);
  4945. for (int index = 0; index < CCS_QUANTITY; index++)
  4946. {
  4947. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4948. {
  4949. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  4950. }
  4951. }
  4952. }
  4953. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4954. {
  4955. //tempIndex = ((gun_index==2) ? 1: 0);
  4956. for (int index = 0; index < GB_QUANTITY; index++)
  4957. {
  4958. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4959. {
  4960. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  4961. }
  4962. }
  4963. }
  4964. else if(gunType[gun_index] == GUN_TYPE_DO)
  4965. {
  4966. //tempIndex = ((gun_index==2) ? 1: 0);
  4967. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4968. {
  4969. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4970. {
  4971. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  4972. }
  4973. }
  4974. }
  4975. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  4976. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  4977. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  4978. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  4979. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  4980. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  4981. }
  4982. }
  4983. //********************************(7)Current.Import L2************************************************/
  4984. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  4985. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  4986. (dataType == ReadingContext_Trigger))
  4987. {
  4988. // Only for AC 3 phase
  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[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  5004. }
  5005. }
  5006. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  5007. }
  5008. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  5009. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  5010. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  5011. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  5012. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5013. }
  5014. //********************************(8)Current.Import L3************************************************/
  5015. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5016. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5017. (dataType == ReadingContext_Trigger))
  5018. {
  5019. // Only for AC 3 phase
  5020. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5021. {
  5022. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5023. {
  5024. tempIndex = 2;
  5025. }
  5026. else
  5027. {
  5028. tempIndex = gun_index;
  5029. }
  5030. for (int index = 0; index < AC_QUANTITY; index++)
  5031. {
  5032. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5033. {
  5034. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  5035. }
  5036. }
  5037. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  5038. }
  5039. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  5040. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  5041. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  5042. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  5043. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5044. }
  5045. //***********************************************(9)VOLTAGE L2******************************************************/
  5046. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5047. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5048. (dataType == ReadingContext_Trigger))
  5049. {
  5050. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5051. {
  5052. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5053. {
  5054. tempIndex = 2;
  5055. }
  5056. else
  5057. {
  5058. tempIndex = gun_index;
  5059. }
  5060. for (int index = 0; index < AC_QUANTITY; index++)
  5061. {
  5062. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5063. {
  5064. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  5065. }
  5066. }
  5067. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  5068. }
  5069. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  5070. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  5071. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  5072. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  5073. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5074. }
  5075. //***********************************************(10)VOLTAGE L3******************************************************/
  5076. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5077. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5078. (dataType == ReadingContext_Trigger))
  5079. {
  5080. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5081. {
  5082. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5083. {
  5084. tempIndex = 2;
  5085. }
  5086. else
  5087. {
  5088. tempIndex = gun_index;
  5089. }
  5090. for (int index = 0; index < AC_QUANTITY; index++)
  5091. {
  5092. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5093. {
  5094. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  5095. }
  5096. }
  5097. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  5098. }
  5099. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  5100. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  5101. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  5102. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  5103. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5104. }
  5105. // Message create ====================================================================================================
  5106. if(TRUE)
  5107. {
  5108. json_object *MeterValueReq = json_object_new_object();
  5109. json_object *MeterValues = json_object_new_array();
  5110. json_object *sampledValues = json_object_new_array();
  5111. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  5112. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  5113. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  5114. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  5115. {
  5116. json_object *MeterValue = json_object_new_object();
  5117. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  5118. {
  5119. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  5120. {
  5121. json_object *sampledValue = json_object_new_object();
  5122. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  5123. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  5124. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  5125. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  5126. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  5127. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  5128. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  5129. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  5130. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  5131. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  5132. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  5133. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  5134. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  5135. json_object_array_add(sampledValues, sampledValue);
  5136. }
  5137. }
  5138. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  5139. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  5140. json_object_array_add(MeterValues, MeterValue);
  5141. }
  5142. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  5143. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  5144. ,gun_index + 1
  5145. ,MESSAGE_TYPE_CALL
  5146. ,guid
  5147. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  5148. json_object_put(MeterValueReq);
  5149. }
  5150. // Put request guid to hash map
  5151. sprintf(tempdata, "MeterValues,%d", (gun_index));
  5152. 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*/)
  5153. {
  5154. result = PASS;
  5155. //DEBUG_INFO("MeterValues mapitem pass\n");
  5156. }
  5157. if((dataType != ReadingContext_Trigger) &&
  5158. (dataType != ReadingContext_Sample_Clock) &&
  5159. (ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1))
  5160. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  5161. else
  5162. {
  5163. if(FirstHeartBeat)
  5164. LWS_Send(queuedata +2);
  5165. }
  5166. return result;
  5167. }
  5168. //==========================================
  5169. // send confirm routine
  5170. //==========================================
  5171. int sendCancelReservationConfirmation(char *uuid,char *payload)
  5172. {
  5173. mtrace();
  5174. int result = FAIL;
  5175. char message[100]={0};
  5176. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  5177. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5178. LWS_Send(message);
  5179. result = TRUE;
  5180. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  5181. return result;
  5182. }
  5183. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  5184. {
  5185. mtrace();
  5186. int result = FAIL;
  5187. char message[100]={0};
  5188. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  5189. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5190. LWS_Send(message);
  5191. result = TRUE;
  5192. return result;
  5193. }
  5194. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  5195. {
  5196. mtrace();
  5197. int result = FAIL;
  5198. char message[100]={0};
  5199. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  5200. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5201. LWS_Send(message);
  5202. result = TRUE;
  5203. return result;
  5204. }
  5205. int sendClearCacheConfirmation(char *uuid,char *payload)
  5206. {
  5207. mtrace();
  5208. int result = FAIL;
  5209. char message[500]={0};
  5210. DEBUG_INFO("sendClearCacheConfirmation...\n");
  5211. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5212. LWS_Send(message);
  5213. return result;
  5214. }
  5215. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  5216. {
  5217. mtrace();
  5218. int result = FAIL;
  5219. char message[500]={0};
  5220. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  5221. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5222. LWS_Send(message);
  5223. return result;
  5224. }
  5225. int sendDataTransferConfirmation(char *uuid,char *payload)
  5226. {
  5227. mtrace();
  5228. char statusStr[20]={0};
  5229. char dataStr[10]={0};
  5230. char sstr[20]={0};
  5231. int c = 0;
  5232. char *loc;
  5233. int result = FAIL;
  5234. DEBUG_INFO("sendDataTransferConfirmation...\n");
  5235. /**********************status**************************/
  5236. loc = strstr(payload, "status");
  5237. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5238. c = 0;
  5239. while (loc[3+strlen("status")+c] != '\"')
  5240. {
  5241. sstr[c] = loc[3+strlen("status")+c];
  5242. c++;
  5243. }
  5244. sstr[c] = '\0';
  5245. strcpy(statusStr, sstr);
  5246. /**********************data**************************/
  5247. loc = strstr(payload, "data");
  5248. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5249. c = 0;
  5250. while (loc[3+strlen("data")+c] != '\"')
  5251. {
  5252. sstr[c] = loc[3+strlen("data")+c];
  5253. c++;
  5254. }
  5255. sstr[c] = '\0';
  5256. strcpy(dataStr, sstr);
  5257. return result;
  5258. }
  5259. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  5260. {
  5261. mtrace();
  5262. int result = FAIL;
  5263. char message[1000]={0};
  5264. int CompositeScheduleIndex = 0;
  5265. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  5266. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  5267. if(nPeriod == 0)
  5268. {
  5269. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  5270. {
  5271. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  5272. ,MESSAGE_TYPE_CALLRESULT
  5273. ,uuid
  5274. ,payload
  5275. ,connectorIdInt);
  5276. }
  5277. else
  5278. {
  5279. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  5280. ,MESSAGE_TYPE_CALLRESULT
  5281. ,uuid
  5282. ,payload
  5283. ,connectorIdInt
  5284. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5285. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5286. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5287. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  5288. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  5289. }
  5290. }
  5291. else
  5292. {
  5293. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  5294. ,MESSAGE_TYPE_CALLRESULT
  5295. ,uuid
  5296. ,payload
  5297. ,connectorIdInt
  5298. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5299. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5300. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5301. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  5302. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  5303. {
  5304. if (idx_sample == 0)
  5305. {
  5306. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5307. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5308. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5309. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5310. }
  5311. else
  5312. {
  5313. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5314. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5315. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5316. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5317. }
  5318. }
  5319. sprintf(message + strlen(message), "]}}]");
  5320. }
  5321. LWS_Send(message);
  5322. result = TRUE;
  5323. return result;
  5324. }
  5325. int sendGetConfigurationConfirmation(char *uuid)
  5326. {
  5327. mtrace();
  5328. int result = FAIL;
  5329. int MaxKeySupported = 0;
  5330. int sentConfigurationNumber= 0;
  5331. int sentunConfigurationNumber= 0;
  5332. char message[4000]={0};
  5333. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  5334. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  5335. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  5336. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  5337. ,MESSAGE_TYPE_CALLRESULT
  5338. ,uuid );
  5339. //configuration key
  5340. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  5341. {
  5342. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  5343. {
  5344. if (sentConfigurationNumber == 0)
  5345. {
  5346. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5347. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5348. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5349. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5350. }
  5351. else
  5352. {
  5353. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5354. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5355. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5356. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5357. }
  5358. sentConfigurationNumber = sentConfigurationNumber + 1;
  5359. }
  5360. }
  5361. sprintf(message + strlen(message), "]");
  5362. if(UnknownKeynum != 0)
  5363. {
  5364. sprintf(message + strlen(message), ",\"unknownKey\":[");
  5365. //unkown key
  5366. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  5367. {
  5368. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  5369. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  5370. if(sentunConfigurationNumber == 0)
  5371. {
  5372. sprintf(message + strlen(message), "\"%s\""
  5373. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5374. }
  5375. else
  5376. {
  5377. sprintf(message + strlen(message), ",\"%s\""
  5378. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5379. }
  5380. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  5381. }
  5382. sprintf(message + strlen(message), "]");
  5383. }
  5384. sprintf(message + strlen(message), "}]");
  5385. LWS_Send(message);
  5386. return result;
  5387. }
  5388. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  5389. {
  5390. mtrace();
  5391. int result = FAIL;
  5392. char message[400]={0};
  5393. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  5394. if(strcmp(payload,"")==0)
  5395. {
  5396. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5397. }
  5398. else
  5399. {
  5400. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5401. }
  5402. LWS_Send(message);
  5403. result = TRUE;
  5404. return result;
  5405. }
  5406. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  5407. {
  5408. mtrace();
  5409. int result = FAIL;
  5410. char message[80]={0};
  5411. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  5412. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  5413. LWS_Send(message);
  5414. result = TRUE;
  5415. return result;
  5416. }
  5417. int sendRemoteStartConfirmation(char *uuid,char *payload)
  5418. {
  5419. mtrace();
  5420. int result = FAIL;
  5421. char message[80]={0};
  5422. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  5423. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5424. LWS_Send(message);
  5425. result = TRUE;
  5426. return result;
  5427. }
  5428. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5429. {
  5430. mtrace();
  5431. int result = FAIL;
  5432. char message[80]={0};
  5433. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5434. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5435. LWS_Send(message);
  5436. result = TRUE;
  5437. return result;
  5438. }
  5439. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5440. {
  5441. mtrace();
  5442. int result = FAIL;
  5443. char message[80]={0};
  5444. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5445. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  5446. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5447. LWS_Send(message);
  5448. result = TRUE;
  5449. return result;
  5450. }
  5451. int sendResetConfirmation(char *uuid,char *payload)
  5452. {
  5453. mtrace();
  5454. int result = FAIL;
  5455. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  5456. char message[80]={0};
  5457. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  5458. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5459. LWS_Send(message);
  5460. result = TRUE;
  5461. return result;
  5462. }
  5463. int sendSendLocalListConfirmation(char *uuid,char *payload)
  5464. {
  5465. mtrace();
  5466. int result = FAIL;
  5467. char message[500]={0};
  5468. // [ 3, "1571284266109", { "status": "Accepted" } ]
  5469. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5470. LWS_Send(message);
  5471. result = TRUE;
  5472. return result;
  5473. }
  5474. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  5475. {
  5476. mtrace();
  5477. int result = FAIL;
  5478. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  5479. char message[80]={0};
  5480. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  5481. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5482. LWS_Send(message);
  5483. result = TRUE;
  5484. return result;
  5485. }
  5486. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  5487. {
  5488. mtrace();
  5489. int result = FAIL;
  5490. char message[80]={0};
  5491. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  5492. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5493. LWS_Send(message);
  5494. result = TRUE;
  5495. return result;
  5496. }
  5497. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  5498. {
  5499. mtrace();
  5500. int result = FAIL;
  5501. char message[80]={0};
  5502. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5503. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  5504. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5505. LWS_Send(message);
  5506. result = TRUE;
  5507. return result;
  5508. }
  5509. int sendUpdateFirmwareConfirmation(char *uuid)
  5510. {
  5511. mtrace();
  5512. int result = FAIL;
  5513. char message[60]={0};
  5514. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5515. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  5516. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5517. LWS_Send(message);
  5518. result = TRUE;
  5519. return result;
  5520. }
  5521. //==========================================
  5522. // send CallError routine
  5523. //==========================================
  5524. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  5525. {
  5526. mtrace();
  5527. char message[220]={0};
  5528. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  5529. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  5530. LWS_Send(message);
  5531. }
  5532. //==========================================
  5533. // Handle server request routine Start
  5534. //==========================================
  5535. int handleCancelReservationRequest(char *uuid, char *payload)
  5536. {
  5537. mtrace();
  5538. int result = FAIL;
  5539. int gunNO = 0;
  5540. int reservationIdInt = -1;
  5541. char comfirmstr[20];
  5542. DEBUG_INFO("handleCancelReservationRequest...\n");
  5543. json_object *CancelReservation;
  5544. CancelReservation = json_tokener_parse(payload);
  5545. if(!is_error(CancelReservation))
  5546. {
  5547. // Required data
  5548. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  5549. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  5550. }
  5551. json_object_put(CancelReservation);
  5552. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  5553. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5554. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  5555. if(reservationIdInt != -1)
  5556. {
  5557. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  5558. //check Transaction active
  5559. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5560. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5561. {
  5562. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  5563. {
  5564. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5565. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5566. if(gunType[2] == GUN_TYPE_CHAdeMO)
  5567. {
  5568. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  5569. }
  5570. else
  5571. {
  5572. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  5573. }
  5574. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5575. goto end;
  5576. }
  5577. }
  5578. for (int index = 0; index < CCS_QUANTITY; index++)
  5579. {
  5580. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  5581. {
  5582. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5583. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5584. if(gunType[2] == GUN_TYPE_CCS)
  5585. {
  5586. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  5587. }
  5588. else
  5589. {
  5590. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  5591. }
  5592. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5593. goto end;
  5594. }
  5595. }
  5596. for (int index = 0; index < GB_QUANTITY; index++)
  5597. {
  5598. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  5599. {
  5600. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5601. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5602. if(gunType[2] == GUN_TYPE_GBT)
  5603. {
  5604. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  5605. }
  5606. else
  5607. {
  5608. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  5609. }
  5610. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5611. goto end;
  5612. }
  5613. }
  5614. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5615. {
  5616. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  5617. {
  5618. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5619. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5620. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  5621. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5622. goto end;
  5623. }
  5624. }
  5625. for (int index = 0; index < AC_QUANTITY; index++)
  5626. {
  5627. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  5628. {
  5629. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5630. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5631. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5632. {
  5633. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  5634. }
  5635. else
  5636. {
  5637. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  5638. }
  5639. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5640. goto end;
  5641. }
  5642. }
  5643. }
  5644. //The reservationId does NOT match the reservationId
  5645. sendCancelReservationConfirmation(uuid, comfirmstr);
  5646. end:
  5647. // Fill in ocpp packet uuid
  5648. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  5649. return result;
  5650. }
  5651. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  5652. {
  5653. mtrace();
  5654. int result = FAIL;
  5655. int gunIndex = 0;
  5656. char typeStr[16]={0};
  5657. char comfirmstr[20];
  5658. int specificId = FALSE;
  5659. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  5660. json_object *ChangeAvailability;
  5661. ChangeAvailability = json_tokener_parse(payload);
  5662. if(!is_error(ChangeAvailability))
  5663. {
  5664. // Required data
  5665. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  5666. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  5667. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  5668. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  5669. }
  5670. json_object_put(ChangeAvailability);
  5671. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5672. {
  5673. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  5674. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  5675. }
  5676. else if(gunIndex == 0)
  5677. {
  5678. for(int i=0; i < gunTotalNumber; i++)
  5679. {
  5680. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  5681. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  5682. }
  5683. }
  5684. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5685. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5686. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  5687. {
  5688. specificId = TRUE;
  5689. }
  5690. if(specificId == FALSE)
  5691. goto end;
  5692. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  5693. {
  5694. //----------------------gunIndex is 0 ------------------------------------------------//
  5695. if(gunIndex == 0)
  5696. {
  5697. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5698. {
  5699. for(int i=0; i < gunTotalNumber; i++)
  5700. {
  5701. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5702. {
  5703. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  5704. {
  5705. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5706. {
  5707. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5708. goto end;
  5709. }
  5710. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5711. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5712. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5713. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5714. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5715. {
  5716. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5717. goto end;
  5718. }
  5719. }
  5720. }//END FOR CHAdeMO_QUANTITY
  5721. for (int index = 0; index < CCS_QUANTITY; index++)
  5722. {
  5723. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  5724. {
  5725. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  5726. {
  5727. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5728. goto end;
  5729. }
  5730. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5731. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5732. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5733. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5734. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5735. {
  5736. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5737. goto end;
  5738. }
  5739. }
  5740. }//END FOR CCS_QUANTITY
  5741. for (int index = 0; index < GB_QUANTITY; index++)
  5742. {
  5743. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  5744. {
  5745. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5746. {
  5747. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5748. goto end;
  5749. }
  5750. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5751. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5752. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5753. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5754. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5755. {
  5756. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5757. goto end;
  5758. }
  5759. }
  5760. }// END FOR GB_QUANTITY
  5761. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5762. {
  5763. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  5764. {
  5765. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5766. {
  5767. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5768. goto end;
  5769. }
  5770. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  5771. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  5772. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  5773. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  5774. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5775. {
  5776. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5777. goto end;
  5778. }
  5779. }
  5780. }// END FOR GENERAL_GUN_QUANTITY
  5781. for (int index = 0; index < AC_QUANTITY; index++)
  5782. {
  5783. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  5784. {
  5785. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5786. {
  5787. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5788. goto end;
  5789. }
  5790. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5791. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5792. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5793. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5794. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5795. {
  5796. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5797. goto end;
  5798. }
  5799. }
  5800. }//END FOR AC_QUANTITY
  5801. }// END FOR gunTotalNumber
  5802. }
  5803. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5804. {
  5805. for(int i=0; i < gunTotalNumber; i++)
  5806. {
  5807. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5808. {
  5809. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5810. goto end;
  5811. }
  5812. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5813. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  5814. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  5815. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  5816. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5817. {
  5818. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5819. goto end;
  5820. }
  5821. }
  5822. }
  5823. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5824. goto end;
  5825. }
  5826. //----------------------gunIndex is not 0 ------------------------------------------------//
  5827. //check Transaction active
  5828. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5829. {
  5830. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  5831. {
  5832. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  5833. {
  5834. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5835. goto end;
  5836. }
  5837. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5838. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5839. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5840. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5841. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5842. {
  5843. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5844. goto end;
  5845. }
  5846. else
  5847. {
  5848. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  5849. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5850. goto end;
  5851. }
  5852. }
  5853. }//END FOR CHAdeMO_QUANTITY
  5854. for (int index = 0; index < CCS_QUANTITY; index++)
  5855. {
  5856. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  5857. {
  5858. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  5859. {
  5860. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5861. goto end;
  5862. }
  5863. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5864. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5865. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5866. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5867. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5868. {
  5869. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5870. goto end;
  5871. }
  5872. else
  5873. {
  5874. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  5875. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5876. goto end;
  5877. }
  5878. }
  5879. }//END FOR CCS_QUANTITY
  5880. for (int index = 0; index < GB_QUANTITY; index++)
  5881. {
  5882. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  5883. {
  5884. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5885. {
  5886. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5887. goto end;
  5888. }
  5889. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5890. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5891. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5892. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5893. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5894. {
  5895. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5896. goto end;
  5897. }
  5898. else
  5899. {
  5900. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  5901. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5902. goto end;
  5903. }
  5904. }
  5905. }// END FOR GB_QUANTITY
  5906. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5907. {
  5908. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  5909. {
  5910. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5911. {
  5912. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5913. goto end;
  5914. }
  5915. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  5916. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  5917. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  5918. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  5919. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5920. {
  5921. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5922. goto end;
  5923. }
  5924. else
  5925. {
  5926. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  5927. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5928. goto end;
  5929. }
  5930. }
  5931. }// END FOR GENERAL_GUN_QUANTITY
  5932. for (int index = 0; index < AC_QUANTITY; index++)
  5933. {
  5934. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  5935. {
  5936. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5937. {
  5938. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5939. goto end;
  5940. }
  5941. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5942. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5943. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5944. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5945. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5946. {
  5947. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5948. goto end;
  5949. }
  5950. else
  5951. {
  5952. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  5953. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5954. goto end;
  5955. }
  5956. }
  5957. }//END FOR AC_QUANTITY
  5958. }//END FOR AvailabilityTypeStr[Inoperative]
  5959. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  5960. {
  5961. //----------------------gunIndex is 0 ------------------------------------------------//
  5962. if(gunIndex == 0)
  5963. {
  5964. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5965. {
  5966. for(int i=0; i < gunTotalNumber; i++)
  5967. {
  5968. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5969. {
  5970. 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
  5971. {
  5972. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5973. goto end;
  5974. }
  5975. }//END FOR CHAdeMO_QUANTITY
  5976. for (int index = 0; index < CCS_QUANTITY; index++)
  5977. {
  5978. 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
  5979. {
  5980. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5981. goto end;
  5982. }
  5983. }//END FOR CCS_QUANTITY
  5984. for (int index = 0; index < GB_QUANTITY; index++)
  5985. {
  5986. 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
  5987. {
  5988. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5989. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5990. goto end;
  5991. }
  5992. }// END FOR GB_QUANTITY
  5993. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5994. {
  5995. 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
  5996. {
  5997. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5998. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5999. goto end;
  6000. }
  6001. }// END FOR GENERAL_GUN_QUANTITY
  6002. for (int index = 0; index < AC_QUANTITY; index++)
  6003. {
  6004. 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
  6005. {
  6006. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6007. goto end;
  6008. }
  6009. }//END FOR CHAdeMO_QUANTITY
  6010. }// END FOR gunTotalNumber
  6011. }
  6012. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6013. {
  6014. for(int i=0; i < gunTotalNumber; i++)
  6015. {
  6016. for (int index = 0; index < AC_QUANTITY; index++)
  6017. {
  6018. 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
  6019. {
  6020. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6021. goto end;
  6022. }
  6023. }//END FOR CHAdeMO_QUANTITY
  6024. } // END FOR gunTotalNumber
  6025. }
  6026. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6027. goto end;
  6028. }
  6029. //----------------------gunIndex is not 0 ------------------------------------------------//
  6030. //check Transaction active
  6031. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6032. {
  6033. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6034. {
  6035. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6036. goto end;
  6037. }
  6038. }//END FOR CHAdeMO_QUANTITY
  6039. for (int index = 0; index < CCS_QUANTITY; index++)
  6040. {
  6041. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6042. {
  6043. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6044. goto end;
  6045. }
  6046. }//END FOR CCS_QUANTITY
  6047. for (int index = 0; index < GB_QUANTITY; index++)
  6048. {
  6049. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6050. {
  6051. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6052. goto end;
  6053. }
  6054. }// END FOR GB_QUANTITY
  6055. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6056. {
  6057. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6058. {
  6059. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6060. goto end;
  6061. }
  6062. }// END FOR GENERAL_GUN_QUANTITY
  6063. for (int index = 0; index < AC_QUANTITY; index++)
  6064. {
  6065. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6066. {
  6067. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6068. goto end;
  6069. }
  6070. }//END FOR AC_QUANTITY
  6071. }//END FOR AvailabilityTypeStr[Operative]
  6072. end:
  6073. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6074. {
  6075. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  6076. }
  6077. else
  6078. {
  6079. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  6080. }
  6081. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6082. {
  6083. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6084. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6085. }
  6086. else if(gunIndex == 0)
  6087. {
  6088. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6089. {
  6090. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  6091. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  6092. }
  6093. }
  6094. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  6095. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6096. return result;
  6097. }
  6098. int handleChangeConfigurationRequest(char *uuid, char *payload)
  6099. {
  6100. mtrace();
  6101. int result = FAIL;
  6102. char keystr[40]={0};
  6103. char valuestr[256]={0};
  6104. char comfirmstr[20]={0};
  6105. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  6106. json_object *ChangeConfiguration;
  6107. ChangeConfiguration = json_tokener_parse(payload);
  6108. if(!is_error(ChangeConfiguration))
  6109. {
  6110. // Required data
  6111. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  6112. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  6113. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  6114. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  6115. }
  6116. json_object_put(ChangeConfiguration);
  6117. if((uuid==NULL) || (payload ==NULL) )
  6118. {
  6119. DEBUG_ERROR("Payload is null\n");
  6120. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6121. }
  6122. else
  6123. {
  6124. int status = setKeyValue(keystr, valuestr);
  6125. switch(status)
  6126. {
  6127. case ConfigurationStatus_Accepted:
  6128. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  6129. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  6130. StoreConfigurationTable();
  6131. break;
  6132. case RebootRequired:
  6133. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  6134. StoreConfigurationTable();
  6135. break;
  6136. case NotSupported:
  6137. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  6138. break;
  6139. case ConfigurationStatus_Rejected:
  6140. default:
  6141. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6142. break;
  6143. }
  6144. }
  6145. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  6146. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  6147. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6148. {
  6149. ChageWebSocketPingInterval(atoi(valuestr));
  6150. }
  6151. if((strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6152. {
  6153. SetOcppConnStatus(FALSE);
  6154. }
  6155. return result;
  6156. }
  6157. int handleClearCacheRequest(char *uuid, char *payload)
  6158. {
  6159. mtrace();
  6160. int result = FAIL;
  6161. char comfirmstr[20];
  6162. char rmFileCmd[100]={0};
  6163. struct stat stats;
  6164. DEBUG_INFO("handleClearCacheRequest...\n");
  6165. stat("/Storage/OCPP", &stats);
  6166. // Check for directory existence
  6167. if (S_ISDIR(stats.st_mode) == 1)
  6168. {}
  6169. else
  6170. {
  6171. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  6172. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  6173. system(rmFileCmd);
  6174. }
  6175. if(OCPP_cleanLocalCache())
  6176. {
  6177. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  6178. }
  6179. else
  6180. {
  6181. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  6182. }
  6183. sendClearCacheConfirmation(uuid, comfirmstr);
  6184. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6185. return result;
  6186. }
  6187. int handleClearChargingProfileRequest(char *uuid, char *payload)
  6188. {
  6189. mtrace();
  6190. int result = FAIL;
  6191. int resultRename;
  6192. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  6193. char chargingProfilePurposeStr[26]={0};
  6194. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  6195. char tempchargingProfilePurposeStr[26]={0};
  6196. char str[100]={0};
  6197. char fname[200]={0};
  6198. char comfirmstr[20]={0};
  6199. char word[1600]={0};
  6200. int clearflag = FALSE;
  6201. int chargingProfileIdIsNULL = FALSE;
  6202. int connectorIsNULL = FALSE;
  6203. int chargingProfilePurposeIsNULL = FALSE;
  6204. int stackLevelIsNULL = FALSE;
  6205. //int GotoEnd = FALSE;
  6206. FILE *fptr1, *fptr2;
  6207. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  6208. int n_chargingProfile=0;
  6209. int isEmptyFile = FALSE;
  6210. char sLineWord[1600]={0};
  6211. char chargingProfiles[10][100]={0};
  6212. int ChargeProfileCount = 0;
  6213. int ch;
  6214. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  6215. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  6216. json_object *ClearChargingProfile;
  6217. ClearChargingProfile = json_tokener_parse(payload);
  6218. if(!is_error(ClearChargingProfile))
  6219. {
  6220. // Optional data
  6221. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  6222. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  6223. else
  6224. chargingProfileIdIsNULL = TRUE;
  6225. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  6226. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  6227. else
  6228. connectorIsNULL = TRUE;
  6229. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  6230. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  6231. else
  6232. chargingProfilePurposeIsNULL = TRUE;
  6233. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  6234. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  6235. else
  6236. stackLevelIsNULL = TRUE;
  6237. }
  6238. json_object_put(ClearChargingProfile);
  6239. if(connectorIsNULL == FALSE)
  6240. {
  6241. switch(connectorIdInt)
  6242. {
  6243. case 0:
  6244. if(chargingProfilePurposeIsNULL == TRUE)
  6245. {
  6246. int l = 0;
  6247. strcpy(fname, ChargePointMaxProfile_JSON);
  6248. if((access(fname,F_OK))!=-1)
  6249. {
  6250. strcpy(chargingProfiles[l], fname);
  6251. l = l + 1;
  6252. }
  6253. strcpy(fname, TxDefaultProfile_0_JSON);
  6254. if((access(fname,F_OK))!=-1)
  6255. {
  6256. strcpy(chargingProfiles[l], fname);
  6257. l = l + 1;
  6258. }
  6259. ChargeProfileCount = l;
  6260. }
  6261. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  6262. {
  6263. strcpy(fname, ChargePointMaxProfile_JSON);
  6264. if((access(fname,F_OK))!=-1)
  6265. {
  6266. strcpy(chargingProfiles[0], fname);
  6267. ChargeProfileCount = 1;
  6268. }
  6269. }
  6270. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6271. {
  6272. strcpy(fname, TxDefaultProfile_0_JSON);
  6273. if((access(fname,F_OK))!=-1)
  6274. {
  6275. strcpy(chargingProfiles[0], fname);
  6276. ChargeProfileCount = 1;
  6277. }
  6278. }
  6279. break;
  6280. default:
  6281. if(chargingProfilePurposeIsNULL == TRUE)
  6282. {
  6283. int m = 0;
  6284. memset(fname, 0, ARRAY_SIZE(fname));
  6285. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6286. if((access(fname,F_OK))!=-1)
  6287. {
  6288. strcpy(chargingProfiles[m], fname);
  6289. m = m + 1;
  6290. }
  6291. memset(fname, 0, ARRAY_SIZE(fname));
  6292. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6293. if((access(fname,F_OK))!=-1)
  6294. {
  6295. strcpy(chargingProfiles[m], fname);
  6296. m = m + 1;
  6297. }
  6298. ChargeProfileCount = m;
  6299. }
  6300. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6301. {
  6302. //strcpy(fname, TxDefaultProfile_1_JSON);
  6303. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6304. if((access(fname,F_OK))!=-1)
  6305. {
  6306. strcpy(chargingProfiles[0], fname);
  6307. ChargeProfileCount = 1;
  6308. }
  6309. }
  6310. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  6311. {
  6312. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6313. if((access(fname,F_OK))!=-1)
  6314. {
  6315. strcpy(chargingProfiles[0], fname);
  6316. ChargeProfileCount = 1;
  6317. }
  6318. //strcpy(fname, TxProfile_1_JSON);
  6319. }
  6320. //strcpy(fname, ChargePointMaxProfile_JSON );
  6321. break;
  6322. }
  6323. }
  6324. else // Check all Charging Profiles
  6325. {
  6326. int i = 0;
  6327. char fnametemp[200]={0};
  6328. ChargeProfileCount = 0;
  6329. //Check ChargePointMaxProfile.json exit
  6330. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  6331. {
  6332. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  6333. i = i + 1;
  6334. }
  6335. //Check TxDefaultProfile_0.json exit
  6336. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  6337. {
  6338. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  6339. i = i + 1;
  6340. }
  6341. //Check TxDefaultProfile_%d.json
  6342. for(int j=1; j <= gunTotalNumber; j++)
  6343. {
  6344. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6345. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  6346. if((access(fnametemp,F_OK))!=-1)
  6347. {
  6348. strcpy(chargingProfiles[i], fnametemp);
  6349. i = i + 1;
  6350. }
  6351. }
  6352. //Check TxProfile_%d.json
  6353. for(int j=1; j <= gunTotalNumber; j++)
  6354. {
  6355. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6356. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  6357. if((access(fnametemp,F_OK))!=-1)
  6358. {
  6359. strcpy(chargingProfiles[i], fnametemp);
  6360. i = i + 1;
  6361. }
  6362. }
  6363. ChargeProfileCount = i;
  6364. }// End connectorIsNULL is TRUE
  6365. if(ChargeProfileCount == 0)
  6366. {
  6367. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6368. goto end;
  6369. }
  6370. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  6371. {
  6372. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6373. goto end;
  6374. }
  6375. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  6376. {
  6377. memset(str, 0, ARRAY_SIZE(str));
  6378. // clear temp file
  6379. sprintf(str,"rm -f %s",temp);
  6380. system(str);
  6381. for(int k=0; k < ChargeProfileCount; k++)
  6382. {
  6383. memset(str, 0, ARRAY_SIZE(str));
  6384. //clear file in C
  6385. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6386. system(str);
  6387. }
  6388. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6389. goto end;
  6390. }
  6391. else if(connectorIsNULL == TRUE)
  6392. {
  6393. for(int k=0; k < ChargeProfileCount; k++)
  6394. {
  6395. fptr1 = fopen(chargingProfiles[k], "r");
  6396. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  6397. //Check Charging Profile Count
  6398. while(fscanf(fptr1, "%s", word) != EOF)
  6399. {
  6400. //DEBUG_INFO("word=%s\n",word);
  6401. if(strstr(word, "chargingProfileId")!= NULL)
  6402. {
  6403. //DEBUG_INFO("test chargingProfileId \n");
  6404. n_chargingProfile = n_chargingProfile + 1;
  6405. //DEBUG_INFO("chargingProfileId Found\n");
  6406. }
  6407. }
  6408. rewind(fptr1);
  6409. //search Charging Profile Element
  6410. //int i= 0;
  6411. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6412. {
  6413. json_object *tmpProfilee;
  6414. tmpProfilee = json_tokener_parse(sLineWord);
  6415. if(!is_error(tmpProfilee))
  6416. {
  6417. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  6418. {
  6419. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  6420. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  6421. }
  6422. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  6423. {
  6424. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  6425. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  6426. }
  6427. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  6428. {
  6429. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  6430. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  6431. }
  6432. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  6433. {
  6434. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  6435. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  6436. }
  6437. }
  6438. json_object_put(tmpProfilee);
  6439. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6440. {
  6441. //------- not write to fptr2-------//
  6442. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6443. //clearflag = TRUE;
  6444. }
  6445. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  6446. {
  6447. //------- not write to fptr2-------//
  6448. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6449. }
  6450. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6451. {
  6452. //------- not write to fptr2-------//
  6453. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6454. }
  6455. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  6456. {
  6457. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6458. }
  6459. else
  6460. {
  6461. fprintf(fptr2, sLineWord);//writing data into file
  6462. }
  6463. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6464. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6465. if(clearflag == TRUE)
  6466. {
  6467. fclose(fptr1);
  6468. fclose(fptr2);
  6469. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6470. system(str);
  6471. // clear temp file
  6472. sprintf(str,"rm -f %s",temp);
  6473. system(str);
  6474. }
  6475. else
  6476. {
  6477. fclose(fptr1);
  6478. fclose(fptr2);
  6479. memset(str, 0, ARRAY_SIZE(str));
  6480. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6481. system(str);
  6482. resultRename = rename(temp, chargingProfiles[k]);
  6483. if(resultRename == 0)
  6484. {
  6485. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  6486. }
  6487. else
  6488. {
  6489. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  6490. }
  6491. if(comfirmstr[0]== 0)
  6492. {
  6493. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6494. }
  6495. //Check chargingProfile is empty file
  6496. /*------ Read the file ----------------*/
  6497. fptr1=fopen(chargingProfiles[k],"r");
  6498. ch=fgetc(fptr1);
  6499. rewind(fptr1);
  6500. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6501. if(ch!=EOF)
  6502. {
  6503. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6504. {
  6505. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6506. if(sLineWord[0]=='\0')
  6507. {
  6508. isEmptyFile = TRUE;
  6509. break;
  6510. }
  6511. else
  6512. {
  6513. isEmptyFile = FALSE;
  6514. break;
  6515. }
  6516. }
  6517. }
  6518. else
  6519. isEmptyFile = TRUE;
  6520. fclose(fptr1);
  6521. if(isEmptyFile == TRUE)
  6522. {
  6523. memset(str, 0, ARRAY_SIZE(str));
  6524. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6525. system(str);
  6526. }
  6527. }
  6528. }// End of while(int k=0; k < ChargePointCount; k++)
  6529. }
  6530. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  6531. {
  6532. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  6533. for(int k=0; k < ChargeProfileCount; k++)
  6534. {
  6535. fptr1 = fopen(chargingProfiles[k], "r");
  6536. fptr2 = fopen(temp, "w+");
  6537. //Check Charging Profile Count
  6538. while(fscanf(fptr1, "%s", word) != EOF)
  6539. {
  6540. //DEBUG_INFO("word=%s\n",word);
  6541. if(strstr(word, "chargingProfileId")!= NULL)
  6542. {
  6543. n_chargingProfile = n_chargingProfile + 1;
  6544. }
  6545. }
  6546. rewind(fptr1);
  6547. //search Charging Profile Element
  6548. //int i= 0;
  6549. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6550. {
  6551. json_object *tmpProfilee;
  6552. tmpProfilee = json_tokener_parse(sLineWord);
  6553. if(!is_error(tmpProfilee))
  6554. {
  6555. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  6556. {
  6557. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  6558. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  6559. }
  6560. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  6561. {
  6562. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  6563. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  6564. }
  6565. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  6566. {
  6567. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  6568. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  6569. }
  6570. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  6571. {
  6572. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  6573. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  6574. }
  6575. }
  6576. json_object_put(tmpProfilee);
  6577. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6578. {
  6579. //------- not write to fptr2-------//
  6580. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6581. //clearflag = TRUE;
  6582. }
  6583. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6584. {
  6585. //------- not write to fptr2-------//
  6586. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6587. }
  6588. else if(stackLevelIsNULL == TRUE)
  6589. {
  6590. //Clear Whole File
  6591. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6592. clearflag = TRUE;
  6593. break;
  6594. }
  6595. else
  6596. {
  6597. fprintf(fptr2, sLineWord);//writing data into file
  6598. }
  6599. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6600. }
  6601. if(clearflag == TRUE)
  6602. {
  6603. fclose(fptr1);
  6604. fclose(fptr2);
  6605. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6606. system(str);
  6607. // clear temp file
  6608. sprintf(str,"rm -f %s",temp);
  6609. system(str);
  6610. }
  6611. else
  6612. {
  6613. fclose(fptr1);
  6614. fclose(fptr2);
  6615. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6616. system(str);
  6617. resultRename = rename(temp, chargingProfiles[k]);
  6618. if(resultRename == 0)
  6619. {
  6620. DEBUG_INFO("File ChargingProfile renamed successfully");
  6621. }
  6622. else
  6623. {
  6624. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6625. }
  6626. if(comfirmstr[0]== 0)
  6627. {
  6628. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6629. }
  6630. //Check chargingProfile is empty file
  6631. /*------ Read the file ----------------*/
  6632. fptr1=fopen(chargingProfiles[k],"r");
  6633. ch=fgetc(fptr1);
  6634. rewind(fptr1);
  6635. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6636. if(ch!=EOF)
  6637. {
  6638. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6639. {
  6640. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6641. if(sLineWord[0]=='\0')
  6642. {
  6643. isEmptyFile = TRUE;
  6644. break;
  6645. }
  6646. else
  6647. {
  6648. isEmptyFile = FALSE;
  6649. break;
  6650. }
  6651. }
  6652. }
  6653. else
  6654. isEmptyFile = TRUE;
  6655. fclose(fptr1);
  6656. if(isEmptyFile == TRUE)
  6657. {
  6658. memset(str, 0, ARRAY_SIZE(str));
  6659. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6660. system(str);
  6661. }
  6662. /*------- End of reading ---------------*/
  6663. }
  6664. } // while(int k=0; k < ChargeProfileCount; k++)
  6665. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  6666. end:
  6667. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  6668. {
  6669. if(connectorIdInt == 0)
  6670. {
  6671. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  6672. {
  6673. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  6674. }
  6675. }
  6676. else
  6677. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  6678. }
  6679. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  6680. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6681. return result;
  6682. }
  6683. void createFirmwareVersionByDataTransfer(void)
  6684. {
  6685. json_object *FirmwareDataTransfer = json_object_new_object();
  6686. // AC & DC model
  6687. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  6688. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  6689. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  6690. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  6691. // DC model
  6692. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O')
  6693. {
  6694. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  6695. {
  6696. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  6697. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  6698. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  6699. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  6700. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  6701. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  6702. }
  6703. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  6704. ((gunType[1] != GUN_TYPE_UNKNOWN) || (gunType[2] != GUN_TYPE_UNKNOWN) || (gunType[3] != GUN_TYPE_UNKNOWN)))
  6705. {
  6706. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  6707. }
  6708. }
  6709. else
  6710. {
  6711. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  6712. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  6713. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  6714. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  6715. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  6716. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  6717. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  6718. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  6719. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  6720. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  6721. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  6722. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  6723. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  6724. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  6725. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  6726. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  6727. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  6728. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  6729. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  6730. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  6731. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  6732. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  6733. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  6734. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  6735. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  6736. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  6737. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  6738. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  6739. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  6740. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  6741. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  6742. }
  6743. // 4G model
  6744. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  6745. {
  6746. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  6747. }
  6748. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  6749. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  6750. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  6751. json_object_put(FirmwareDataTransfer);
  6752. }
  6753. int handleDataTransferRequest(char *uuid, char *payload)
  6754. {
  6755. mtrace();
  6756. json_object *response = json_object_new_object();
  6757. int result = FAIL;
  6758. char tempvendorId[255]={0};
  6759. char tempmessageId[50]={0};
  6760. char tempdata[512]={0};
  6761. char message[2048]={0};
  6762. DEBUG_INFO("handleDataTransferRequest...\n");
  6763. if((uuid != NULL) && (payload != NULL))
  6764. {
  6765. json_object *DataTransfer;
  6766. DataTransfer = json_tokener_parse(payload);
  6767. if(!is_error(DataTransfer))
  6768. {
  6769. // Required data
  6770. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  6771. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  6772. // Optional data
  6773. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  6774. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  6775. if(json_object_object_get(DataTransfer, "data") != NULL)
  6776. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  6777. result = PASS;
  6778. }
  6779. json_object_put(DataTransfer);
  6780. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  6781. {
  6782. // Send all moudle firmware version on EVSE
  6783. createFirmwareVersionByDataTransfer();
  6784. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6785. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  6786. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6787. json_object_put(response);
  6788. }
  6789. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  6790. {
  6791. system("/usr/bin/run_tmate_restart.sh &");
  6792. }
  6793. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  6794. {
  6795. json_object *data;
  6796. data = json_tokener_parse(tempdata);
  6797. if(!is_error(data))
  6798. {
  6799. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  6800. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  6801. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  6802. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  6803. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  6804. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  6805. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  6806. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  6807. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  6808. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  6809. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6810. }
  6811. else
  6812. {
  6813. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6814. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6815. }
  6816. json_object_put(data);
  6817. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6818. json_object_put(response);
  6819. }
  6820. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  6821. {
  6822. json_object *data;
  6823. data = json_tokener_parse(tempdata);
  6824. if(!is_error(data))
  6825. {
  6826. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  6827. if(json_object_object_get(data, "idToken") != NULL)
  6828. {
  6829. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  6830. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  6831. }
  6832. if(json_object_object_get(data, "price") != NULL)
  6833. {
  6834. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  6835. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  6836. }
  6837. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6838. }
  6839. else
  6840. {
  6841. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6842. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6843. }
  6844. json_object_put(data);
  6845. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6846. json_object_put(response);
  6847. }
  6848. else if(strstr(tempmessageId, "RunningCost") != NULL)
  6849. {
  6850. json_object *data;
  6851. data = json_tokener_parse(tempdata);
  6852. if(!is_error(data))
  6853. {
  6854. if(json_object_object_get(data, "txId") != NULL)
  6855. {
  6856. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  6857. for(int idx = 0;idx<gunTotalNumber;idx++)
  6858. {
  6859. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  6860. {
  6861. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  6862. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  6863. if(json_object_object_get(data, "description") != NULL)
  6864. {
  6865. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  6866. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  6867. }
  6868. }
  6869. }
  6870. }
  6871. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6872. }
  6873. else
  6874. {
  6875. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6876. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6877. }
  6878. json_object_put(data);
  6879. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6880. json_object_put(response);
  6881. }
  6882. else if(strstr(tempmessageId, "FinalCost") != NULL)
  6883. {
  6884. json_object *data;
  6885. data = json_tokener_parse(tempdata);
  6886. if(!is_error(data))
  6887. {
  6888. if(json_object_object_get(data, "txId") != NULL)
  6889. {
  6890. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  6891. for(int idx = 0;idx<gunTotalNumber;idx++)
  6892. {
  6893. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  6894. {
  6895. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  6896. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  6897. if(json_object_object_get(data, "description") != NULL)
  6898. {
  6899. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  6900. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  6901. }
  6902. }
  6903. }
  6904. }
  6905. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6906. }
  6907. else
  6908. {
  6909. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6910. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6911. }
  6912. json_object_put(data);
  6913. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6914. json_object_put(response);
  6915. }
  6916. else
  6917. {
  6918. // Can not find valid message id
  6919. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  6920. }
  6921. }
  6922. else
  6923. {
  6924. // Payload is null
  6925. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  6926. }
  6927. LWS_Send(message);
  6928. return result;
  6929. }
  6930. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  6931. {
  6932. mtrace();
  6933. int result = FAIL;
  6934. int connectorIdInt, durationInt;
  6935. char chargingRateUnitStr[4]={0};
  6936. char comfirmstr[20];
  6937. int confirmPeriods = 0;
  6938. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  6939. json_object *GetCompositeSchedule;
  6940. GetCompositeSchedule = json_tokener_parse(payload);
  6941. if(!is_error(GetCompositeSchedule))
  6942. {
  6943. // Required data
  6944. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  6945. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  6946. else
  6947. connectorIdInt = -1;
  6948. if(json_object_object_get(GetCompositeSchedule, "duration"))
  6949. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  6950. else
  6951. durationInt = 86400;
  6952. // Optional data
  6953. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  6954. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  6955. }
  6956. json_object_put(GetCompositeSchedule);
  6957. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  6958. if((connectorIdInt == 0) ||
  6959. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  6960. {
  6961. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  6962. struct StructChargingProfile tmpProfile[1];
  6963. if(strstr(chargingRateUnitStr, "W") != NULL)
  6964. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  6965. else
  6966. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  6967. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6968. {
  6969. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6970. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6971. }
  6972. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  6973. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  6974. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  6975. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6976. {
  6977. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6978. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6979. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  6980. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0))
  6981. {
  6982. confirmPeriods = idx;
  6983. break;
  6984. }
  6985. }
  6986. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6987. }
  6988. else
  6989. {
  6990. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  6991. }
  6992. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  6993. return result;
  6994. }
  6995. int handleGetConfigurationRequest(char *uuid, char *payload)
  6996. {
  6997. mtrace();
  6998. int result = FAIL;
  6999. int MaxKeySupported = 0;
  7000. int n_keys = 0;
  7001. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  7002. DEBUG_INFO("handleGetConfigurationRequest...\n");
  7003. json_object *GetConfiguration;
  7004. GetConfiguration = json_tokener_parse(payload);
  7005. if(!is_error(GetConfiguration))
  7006. {
  7007. // Optional data
  7008. if(json_object_object_get(GetConfiguration, "key") != NULL)
  7009. {
  7010. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  7011. {
  7012. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  7013. n_keys = idx + 1;
  7014. }
  7015. }
  7016. }
  7017. json_object_put(GetConfiguration);
  7018. UnknownKeynum = 0;
  7019. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  7020. MaxKeySupported = GetConfigurationMaxKeysNUM;
  7021. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  7022. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  7023. if(n_keys != 0)
  7024. {
  7025. for(int i=0;i<n_keys;i++)
  7026. {
  7027. getKeyValue(requestKey[i]);
  7028. }
  7029. }
  7030. else
  7031. {
  7032. DEBUG_INFO("There is no key in Message, get all configuration\n");
  7033. getKeyValue("");
  7034. }
  7035. processUnkownKey();
  7036. sendGetConfigurationConfirmation(uuid);
  7037. return result;
  7038. }
  7039. static char fnamePlusPath[100]={0};
  7040. static char fnamePWithNoPath[60]={0};
  7041. void checkUploadLog(void)
  7042. {
  7043. FILE *fp;
  7044. /* Open the command for reading. */
  7045. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  7046. if (fp == NULL) {
  7047. printf("Failed to run command\n" );
  7048. exit(1);
  7049. }
  7050. int ftppathlen = 0;
  7051. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  7052. int i = 0;
  7053. /* Read the output a line at a time - output it. */
  7054. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  7055. if(i==0)
  7056. {
  7057. ftppathlen = strlen(fnamePlusPath);
  7058. printf("%s\n", fnamePlusPath);
  7059. fnamePlusPath[ftppathlen]='\0';
  7060. break;
  7061. }
  7062. i= i+1;
  7063. }
  7064. /* close */
  7065. pclose(fp);
  7066. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  7067. {
  7068. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  7069. {
  7070. fnamePlusPath[k]='\0';
  7071. }
  7072. }
  7073. i=1;
  7074. //char fname[60]={0};
  7075. while(i < ftppathlen)
  7076. {
  7077. int len=ftppathlen-i;
  7078. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  7079. {
  7080. printf("compare '/' all right\n");
  7081. break;
  7082. }
  7083. i=i+1;
  7084. }
  7085. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  7086. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  7087. fnamePWithNoPath[i+1] = '\0';
  7088. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  7089. {
  7090. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  7091. {
  7092. fnamePWithNoPath[j]='\0';
  7093. }
  7094. }
  7095. FILE* fp1 = fopen(fnamePlusPath, "r");
  7096. if (fp1)
  7097. {
  7098. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  7099. // file exists
  7100. fclose(fp1);
  7101. }
  7102. else
  7103. {
  7104. // file doesn't exist
  7105. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  7106. }
  7107. }
  7108. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  7109. {
  7110. mtrace();
  7111. int result = FAIL;
  7112. time_t CurrentTime;
  7113. struct tm *tm;
  7114. pthread_t th_Status;
  7115. CurrentTime = time(NULL);
  7116. tm = localtime(&CurrentTime);
  7117. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  7118. 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);
  7119. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  7120. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  7121. return result;
  7122. }
  7123. void* GetDiagnosticsProcess(void* data)
  7124. {
  7125. pthread_detach(pthread_self());
  7126. mtrace();
  7127. int retriesInt=0, retryIntervalInt=0;
  7128. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  7129. 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};
  7130. int port=0;
  7131. int isSuccess = FALSE;
  7132. char ftpbuf[200]={0};
  7133. char cmdBuf[2048];
  7134. struct tm *tmNow;
  7135. time_t CurrentTime;
  7136. struct tm tmStart;
  7137. struct tm tmStop;
  7138. CurrentTime = time(NULL);
  7139. tmNow=localtime(&CurrentTime);
  7140. uint16_t targetYear, targetMonth;
  7141. json_object *GetDiagnostics;
  7142. DEBUG_INFO("GetDiagnosticsProcess...\n");
  7143. GetDiagnostics = json_tokener_parse(data);
  7144. if(!is_error(GetDiagnostics))
  7145. {
  7146. // Required data
  7147. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  7148. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  7149. // Optional data
  7150. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  7151. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  7152. else
  7153. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  7154. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  7155. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  7156. else
  7157. retryIntervalInt = 30;
  7158. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  7159. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  7160. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  7161. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  7162. }
  7163. json_object_put(GetDiagnostics);
  7164. // Pack log to compress file
  7165. 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) &&
  7166. (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))
  7167. {
  7168. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/log.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  7169. targetYear = tmStart.tm_year;
  7170. targetMonth = tmStart.tm_mon;
  7171. do
  7172. {
  7173. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7174. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7175. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7176. if(targetMonth+1>=13)
  7177. {
  7178. targetYear += 1;
  7179. targetMonth = 1;
  7180. }
  7181. else
  7182. {
  7183. targetMonth += 1;
  7184. }
  7185. }while((targetYear < (tmNow->tm_year+1900)) ||
  7186. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  7187. sprintf(cmdBuf, "%s \t /Storage/ChargeLog/*.db", cmdBuf);
  7188. sprintf(cmdBuf, "%s \t /Storage/OCPP/*.db", cmdBuf);
  7189. sprintf(cmdBuf, "%s \t /Storage/EventLog/*.db", cmdBuf);
  7190. sprintf(cmdBuf, "%s \t /Storage/CCS*.zip", cmdBuf);
  7191. system(cmdBuf);
  7192. }
  7193. else
  7194. {
  7195. system("exec /root/logPackTools 'log' 6");
  7196. }
  7197. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  7198. system(cmdBuf);
  7199. checkUploadLog();
  7200. //****************location*******************/
  7201. if(strcmp(locationstr,"")==0)
  7202. {
  7203. DEBUG_INFO("location is <Empty>!\n");
  7204. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7205. goto end;
  7206. }
  7207. memset(protocol, 0, ARRAY_SIZE(protocol));
  7208. memset(user, 0, ARRAY_SIZE(user) );
  7209. memset(password, 0, ARRAY_SIZE(password));
  7210. memset(host, 0, ARRAY_SIZE(host));
  7211. memset(path, 0, ARRAY_SIZE(path));
  7212. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  7213. memset(host1, 0, ARRAY_SIZE(host1));
  7214. memset(path1, 0, ARRAY_SIZE(path1));
  7215. /*location: ftp://user:password@host:port/path*/
  7216. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  7217. if((access(fnamePlusPath,F_OK))!=-1)
  7218. {
  7219. DEBUG_INFO("fnamePlusPath exist.\n");
  7220. }
  7221. else
  7222. {
  7223. DEBUG_INFO("fnamePlusPath not exist!\n");
  7224. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7225. goto end;
  7226. }
  7227. if(strchr(locationstr,'@')==NULL)
  7228. {
  7229. sscanf(locationstr,
  7230. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  7231. protocol, host, &port, path);
  7232. strcpy(user,"anonymous");
  7233. strcpy(password,"");
  7234. }
  7235. else
  7236. {
  7237. //DEBUG_INFO("pch=%s\n", pch);
  7238. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  7239. protocol, user, password, host, &port, path);
  7240. }
  7241. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  7242. {
  7243. DEBUG_INFO("protocol is not ftp/http ! \n");
  7244. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7245. goto end;
  7246. }
  7247. if(strncmp(locationstr,"http", 4) == 0)
  7248. {
  7249. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  7250. sprintf(ftppath,"/%s", path);
  7251. do
  7252. {
  7253. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  7254. sleep(3);
  7255. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  7256. if(!isSuccess)
  7257. {
  7258. DEBUG_INFO("Diagnostics fail.\n");
  7259. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7260. sleep(retryIntervalInt);
  7261. }
  7262. else
  7263. {
  7264. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  7265. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  7266. }
  7267. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  7268. }
  7269. else
  7270. {
  7271. sscanf(host,"%[^/]%s",host1, path1);
  7272. sprintf(ftppath,"%s", path1);
  7273. int ftppathlen=strlen(ftppath);
  7274. int i=1;
  7275. char filenametemp[50];
  7276. while(i < ftppathlen)
  7277. {
  7278. int len=ftppathlen-i;
  7279. if(ftppath[len]== 47) // '/' ascll code: 47
  7280. {
  7281. DEBUG_INFO("find '/' all right\n");
  7282. break;
  7283. }
  7284. i=i+1;
  7285. }
  7286. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  7287. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  7288. filenametemp[i+1] = 0;
  7289. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  7290. if(port == 0)
  7291. port = 21;
  7292. do
  7293. {
  7294. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  7295. sleep(3);
  7296. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  7297. if(!isSuccess)
  7298. {
  7299. DEBUG_INFO("Diagnostics fail.\n");
  7300. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7301. sleep(retryIntervalInt);
  7302. }
  7303. else
  7304. {
  7305. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  7306. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  7307. }
  7308. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  7309. }
  7310. end:
  7311. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  7312. system("rm -f /mnt/*");
  7313. pthread_exit(NULL);
  7314. }
  7315. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  7316. {
  7317. mtrace();
  7318. int result = FAIL;
  7319. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  7320. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  7321. {
  7322. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  7323. localversion = -1;
  7324. }
  7325. else
  7326. {
  7327. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  7328. OCPP_getListVerion();
  7329. }
  7330. //from db.OCPP_getListVerion
  7331. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  7332. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  7333. sendGetLocalListVersionConfirmation(uuid,"");
  7334. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  7335. return result;
  7336. }
  7337. int handleRemoteStartRequest(char *uuid, char *payload)
  7338. {
  7339. mtrace();
  7340. int result = FAIL;
  7341. int connectorIdInt=0;
  7342. int tempIndex = 0;
  7343. int connectorIdIsNULL, chargingProfileIsNULL;
  7344. char comfirmstr[20]={0};
  7345. char cmdBuf[512];
  7346. json_object *RemoteStartTransaction;
  7347. FILE *fp;
  7348. DEBUG_INFO("handleRemoteStartRequest ...\n");
  7349. if(server_pending == TRUE)
  7350. {
  7351. return 0;
  7352. }
  7353. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  7354. RemoteStartTransaction = json_tokener_parse(payload);
  7355. if(!is_error(RemoteStartTransaction))
  7356. {
  7357. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  7358. {
  7359. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  7360. if(connectorIdInt <= gunTotalNumber)
  7361. {
  7362. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  7363. // Required data
  7364. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  7365. // Optional data
  7366. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  7367. {
  7368. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  7369. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  7370. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  7371. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  7372. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  7373. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  7374. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  7375. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  7376. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  7377. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  7378. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  7379. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  7380. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  7381. {
  7382. 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")));
  7383. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  7384. 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"));
  7385. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  7386. 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"));
  7387. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  7388. 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")));
  7389. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  7390. {
  7391. 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++)
  7392. {
  7393. 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"));
  7394. 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"));
  7395. 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)
  7396. 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"));
  7397. }
  7398. }
  7399. }
  7400. }
  7401. else
  7402. chargingProfileIsNULL = TRUE;
  7403. }
  7404. }
  7405. else
  7406. connectorIdIsNULL = TRUE;
  7407. }
  7408. else
  7409. connectorIdIsNULL = TRUE;
  7410. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  7411. {
  7412. DEBUG_WARN("Connector id is NULL\n.");
  7413. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7414. goto end;
  7415. }
  7416. /*
  7417. enum _SYSTEM_STATUS
  7418. {
  7419. S_BOOTING = 0,
  7420. S_IDLE, = 1
  7421. S_AUTHORIZING, = 2
  7422. S_REASSIGN_CHECK, = 3
  7423. S_REASSIGN, = 4
  7424. S_PRECHARGE, = 5
  7425. S_PREPARING_FOR_EV, = 6
  7426. S_PREPARING_FOR_EVSE, = 7
  7427. S_CHARGING, = 8
  7428. S_TERMINATING, = 9
  7429. S_COMPLETE, = 10
  7430. S_ALARM, = 11
  7431. S_FAULT = 12
  7432. }
  7433. */
  7434. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  7435. {
  7436. //check Transaction active
  7437. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  7438. {
  7439. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7440. {
  7441. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7442. }
  7443. else
  7444. {
  7445. tempIndex = connectorIdInt -1;
  7446. }
  7447. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7448. {
  7449. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  7450. {
  7451. 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))
  7452. {
  7453. //Reserved
  7454. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7455. }
  7456. 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))
  7457. {
  7458. //Reserved
  7459. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7460. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7461. goto end;
  7462. }
  7463. else
  7464. {
  7465. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7466. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  7467. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  7468. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  7469. {
  7470. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  7471. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7472. goto end;
  7473. }
  7474. }//END FOR ELSE
  7475. }
  7476. }// END FOR CHAdeMO_QUANTITY
  7477. }
  7478. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  7479. {
  7480. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7481. {
  7482. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7483. }
  7484. else
  7485. {
  7486. tempIndex = connectorIdInt -1;
  7487. }
  7488. for (int index = 0; index < CCS_QUANTITY; index++)
  7489. {
  7490. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7491. {
  7492. 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))
  7493. {
  7494. //Reserved
  7495. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7496. }
  7497. 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))
  7498. {
  7499. //Reserved
  7500. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7501. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7502. goto end;
  7503. }
  7504. else
  7505. {
  7506. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7507. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7508. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7509. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7510. {
  7511. DEBUG_WARN("CCS connector not allow start\n.");
  7512. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7513. goto end;
  7514. }
  7515. }// END FOR ELSE
  7516. }
  7517. }// END FOR CCS_QUANTITY
  7518. }
  7519. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  7520. {
  7521. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7522. {
  7523. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7524. }
  7525. else
  7526. {
  7527. tempIndex = connectorIdInt -1;
  7528. }
  7529. for (int index = 0; index < GB_QUANTITY; index++)
  7530. {
  7531. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  7532. {
  7533. 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))
  7534. {
  7535. //Reserved
  7536. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7537. }
  7538. 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))
  7539. {
  7540. //Reserved
  7541. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7542. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7543. goto end;
  7544. }
  7545. else
  7546. {
  7547. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7548. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7549. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7550. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7551. {
  7552. DEBUG_WARN("GB connector not allow start\n.");
  7553. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7554. goto end;
  7555. }
  7556. }// END FOR ELSE
  7557. }
  7558. } // END FOR GB_QUANTITY
  7559. }
  7560. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  7561. {
  7562. tempIndex = connectorIdInt -1;
  7563. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7564. {
  7565. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  7566. {
  7567. 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))
  7568. {
  7569. //Reserved
  7570. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7571. }
  7572. 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))
  7573. {
  7574. //Reserved
  7575. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7576. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7577. goto end;
  7578. }
  7579. else
  7580. {
  7581. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7582. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7583. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7584. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7585. {
  7586. DEBUG_WARN("GB connector not allow start\n.");
  7587. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7588. goto end;
  7589. }
  7590. }// END FOR ELSE
  7591. }
  7592. } // END FOR GB_QUANTITY
  7593. }
  7594. else
  7595. {
  7596. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7597. {
  7598. tempIndex = 2;
  7599. }
  7600. else
  7601. {
  7602. tempIndex = connectorIdInt -1;
  7603. }
  7604. for (int index = 0; index < AC_QUANTITY; index++)
  7605. {
  7606. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  7607. {
  7608. 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))
  7609. {
  7610. //Reserved
  7611. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7612. }
  7613. 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))
  7614. {
  7615. //Reserved
  7616. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7617. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7618. goto end;
  7619. }
  7620. else
  7621. {
  7622. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7623. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7624. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7625. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7626. {
  7627. DEBUG_WARN("AC connector not allow start\n.");
  7628. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7629. goto end;
  7630. }
  7631. }//END FOR ELSE
  7632. }
  7633. }// END FOR AC_QUANTITY
  7634. }
  7635. if(chargingProfileIsNULL == FALSE)
  7636. {
  7637. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7638. {
  7639. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7640. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7641. //memset idTag
  7642. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7643. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7644. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7645. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7646. // Save profile to file
  7647. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7648. system(cmdBuf);
  7649. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7650. fp = fopen(cmdBuf, "w");
  7651. 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));
  7652. fclose(fp);
  7653. }
  7654. else
  7655. {
  7656. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  7657. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7658. }
  7659. }
  7660. else
  7661. {
  7662. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7663. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7664. //memset idTag
  7665. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7666. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7667. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7668. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7669. }
  7670. }
  7671. else
  7672. {
  7673. DEBUG_WARN("Connector id over\n.");
  7674. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7675. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7676. }
  7677. end:
  7678. json_object_put(RemoteStartTransaction);
  7679. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  7680. {
  7681. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  7682. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7683. }
  7684. //OCPP send RemoteStartConfirmation by first.
  7685. sendRemoteStartConfirmation(uuid, comfirmstr);
  7686. return result;
  7687. }
  7688. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  7689. {
  7690. mtrace();
  7691. int result = FAIL;
  7692. int match = FALSE;
  7693. int GunNO = 0;
  7694. int tempIndex = 0;
  7695. int transactionIdInt=0;
  7696. int transactionIdIsNULL= TRUE;
  7697. char comfirmstr[20];
  7698. json_object *RemoteStopTransaction;
  7699. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  7700. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  7701. if(server_pending == TRUE)
  7702. {
  7703. return 0;
  7704. }
  7705. RemoteStopTransaction = json_tokener_parse(payload);
  7706. if(!is_error(RemoteStopTransaction))
  7707. {
  7708. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  7709. {
  7710. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  7711. transactionIdIsNULL = FALSE;
  7712. }
  7713. }
  7714. json_object_put(RemoteStopTransaction);
  7715. if(transactionIdIsNULL == FALSE)
  7716. {
  7717. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  7718. {
  7719. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  7720. {
  7721. //check Transaction active
  7722. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7723. {
  7724. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7725. {
  7726. tempIndex = ((gun_index==2) ? 1: 0);
  7727. }
  7728. else
  7729. {
  7730. tempIndex = gun_index;
  7731. }
  7732. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7733. {
  7734. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7735. {
  7736. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7737. {
  7738. match = TRUE;
  7739. GunNO = gun_index;
  7740. }
  7741. }
  7742. }// END FOR CHAdeMO_QUANTITY
  7743. }
  7744. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7745. {
  7746. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7747. {
  7748. tempIndex = ((gun_index==2) ? 1: 0);
  7749. }
  7750. else
  7751. {
  7752. tempIndex = gun_index;
  7753. }
  7754. for (int index = 0; index < CCS_QUANTITY; index++)
  7755. {
  7756. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7757. {
  7758. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7759. {
  7760. match = TRUE;
  7761. GunNO = gun_index;
  7762. }
  7763. }
  7764. }// END FOR CCS_QUANTITY
  7765. }
  7766. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7767. {
  7768. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7769. {
  7770. tempIndex = ((gun_index==2) ? 1: 0);
  7771. }
  7772. else
  7773. {
  7774. tempIndex = gun_index;
  7775. }
  7776. for (int index = 0; index < GB_QUANTITY; index++)
  7777. {
  7778. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7779. {
  7780. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7781. {
  7782. match = TRUE;
  7783. GunNO = gun_index;
  7784. }
  7785. }
  7786. }// END FOR GB_QUANTITY
  7787. }
  7788. else if(gunType[gun_index] == GUN_TYPE_DO)
  7789. {
  7790. tempIndex = gun_index;
  7791. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7792. {
  7793. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7794. {
  7795. 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
  7796. {
  7797. match = TRUE;
  7798. GunNO = gun_index;
  7799. }
  7800. }
  7801. }// END FOR GB_QUANTITY
  7802. }
  7803. else
  7804. {
  7805. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7806. {
  7807. tempIndex = 2;
  7808. }
  7809. else
  7810. {
  7811. tempIndex = gun_index;
  7812. }
  7813. for (int index = 0; index < AC_QUANTITY; index++)
  7814. {
  7815. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7816. {
  7817. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7818. {
  7819. match = TRUE;
  7820. GunNO = gun_index;
  7821. }
  7822. }
  7823. }// END FOR CHAdeMO_QUANTITY
  7824. } // END FOR AC ELSE
  7825. }// CHECK IF ResponseTransactionId == transactionIdInt
  7826. }//END FOR
  7827. if( match == TRUE)
  7828. {
  7829. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  7830. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7831. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  7832. }
  7833. else
  7834. {
  7835. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7836. }
  7837. }
  7838. else
  7839. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7840. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  7841. return result;
  7842. }
  7843. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  7844. {
  7845. mtrace();
  7846. int result = FAIL;
  7847. int connectorIdInt=0, reservationIdInt=0;
  7848. int tempIndex = 0;
  7849. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  7850. char comfirmstr[20]={0};
  7851. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  7852. int c = 0;
  7853. char *loc;
  7854. //char *ptr;
  7855. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  7856. strcpy(sstrtemp, stringtrimspace(payload));
  7857. //***(1)connectorId ****/
  7858. c=0;
  7859. loc = strstr(sstrtemp, "connectorId");
  7860. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7861. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  7862. {
  7863. sstr[c] = loc[strlen("connectorId")+2+c];
  7864. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7865. c++;
  7866. }
  7867. sstr[c] = '\0';
  7868. connectorIdInt = atoi(sstr);
  7869. //***(2)expiryDate ****/
  7870. loc = strstr(sstrtemp, "expiryDate");
  7871. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7872. c = 0;
  7873. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  7874. {
  7875. sstr[c] = loc[3+strlen("expiryDate")+c];
  7876. c++;
  7877. }
  7878. sstr[c] = '\0';
  7879. strcpy(expiryDatestr, sstr);
  7880. //***(3)idTag ****/
  7881. loc = strstr(sstrtemp, "idTag");
  7882. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7883. c = 0;
  7884. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  7885. {
  7886. sstr[c] = loc[3+strlen("idTag")+c];
  7887. c++;
  7888. }
  7889. sstr[c] = '\0';
  7890. strcpy(idTagstr, sstr);
  7891. //***(4)parentIdTag ****/
  7892. loc = strstr(sstrtemp, "parentIdTag");
  7893. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7894. c = 0;
  7895. if(loc == NULL)
  7896. {
  7897. strcpy(parentIdTagstr, "");
  7898. }
  7899. else
  7900. {
  7901. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  7902. {
  7903. sstr[c] = loc[3+strlen("parentIdTag")+c];
  7904. c++;
  7905. }
  7906. sstr[c] = '\0';
  7907. strcpy(parentIdTagstr, sstr);
  7908. }
  7909. //***(5)reservationId ****/
  7910. c=0;
  7911. loc = strstr(sstrtemp, "reservationId");
  7912. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7913. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  7914. {
  7915. sstr[c] = loc[strlen("reservationId")+2+c];
  7916. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7917. c++;
  7918. }
  7919. sstr[c] = '\0';
  7920. reservationIdInt = atoi(sstr);
  7921. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7922. /*
  7923. enum SYSTEM_STATUS
  7924. {
  7925. SYS_MODE_BOOTING = 0,
  7926. SYS_MODE_IDLE = 1,
  7927. SYS_MODE_AUTHORIZING = 2,
  7928. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  7929. SYS_MODE_REASSIGN = 4,
  7930. SYS_MODE_PREPARING = 5,
  7931. SYS_MODE_PREPARE_FOR_EV = 6,
  7932. SYS_MODE_PREPARE_FOR_EVSE = 7,
  7933. SYS_MODE_CHARGING = 8,
  7934. SYS_MODE_TERMINATING = 9,
  7935. SYS_MODE_COMPLETE = 10,
  7936. SYS_MODE_ALARM = 11,
  7937. SYS_MODE_FAULT = 12,
  7938. SYS_MODE_RESERVATION = 13,
  7939. SYS_MODE_BOOKING = 14,
  7940. SYS_MODE_MAINTAIN = 15,
  7941. SYS_MODE_DEBUG = 16,
  7942. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  7943. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  7944. SYS_MODE_UPDATE = 19
  7945. };
  7946. */
  7947. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  7948. {
  7949. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7950. goto end;
  7951. }
  7952. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  7953. {
  7954. //check Transaction active
  7955. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  7956. {
  7957. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7958. {
  7959. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7960. }
  7961. else
  7962. {
  7963. tempIndex = connectorIdInt -1;
  7964. }
  7965. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7966. {
  7967. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7968. {
  7969. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7970. {
  7971. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7972. {
  7973. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7974. {
  7975. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7976. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7977. }
  7978. 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'))
  7979. {
  7980. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7981. }
  7982. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7983. {
  7984. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7985. }
  7986. else
  7987. {
  7988. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7989. }
  7990. }
  7991. 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
  7992. {
  7993. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7994. }
  7995. }
  7996. else
  7997. {
  7998. //replace reservation
  7999. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8000. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8001. }
  8002. }
  8003. } // END FOR CHAdeMO_QUANTITY
  8004. }
  8005. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8006. {
  8007. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8008. {
  8009. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8010. }
  8011. else
  8012. {
  8013. tempIndex = connectorIdInt -1;
  8014. }
  8015. for (int index = 0; index < CCS_QUANTITY; index++)
  8016. {
  8017. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8018. {
  8019. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8020. {
  8021. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8022. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8023. {
  8024. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8025. {
  8026. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8027. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8028. }
  8029. 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'))
  8030. {
  8031. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8032. }
  8033. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  8034. {
  8035. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8036. }
  8037. else
  8038. {
  8039. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8040. }
  8041. }
  8042. 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
  8043. {
  8044. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8045. }
  8046. }
  8047. else
  8048. {
  8049. //replace reservation
  8050. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8051. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8052. }
  8053. }
  8054. } // END FOR CCS_QUANTITY
  8055. }
  8056. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8057. {
  8058. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8059. {
  8060. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8061. }
  8062. else
  8063. {
  8064. tempIndex = connectorIdInt -1;
  8065. }
  8066. for (int index = 0; index < GB_QUANTITY; index++)
  8067. {
  8068. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8069. {
  8070. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8071. {
  8072. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8073. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  8074. {
  8075. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8076. {
  8077. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8078. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8079. }
  8080. 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'))
  8081. {
  8082. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8083. }
  8084. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8085. {
  8086. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8087. }
  8088. else
  8089. {
  8090. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8091. }
  8092. }
  8093. 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
  8094. {
  8095. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8096. }
  8097. }
  8098. else
  8099. {
  8100. //replace reservation
  8101. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8102. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8103. }
  8104. }
  8105. }// END FOR GB_QUANTITY
  8106. }
  8107. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8108. {
  8109. tempIndex = connectorIdInt -1;
  8110. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8111. {
  8112. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8113. {
  8114. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  8115. {
  8116. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8117. 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
  8118. {
  8119. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8120. {
  8121. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8122. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8123. }
  8124. 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'))
  8125. {
  8126. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8127. }
  8128. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8129. {
  8130. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8131. }
  8132. else
  8133. {
  8134. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8135. }
  8136. }
  8137. 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
  8138. {
  8139. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8140. }
  8141. }
  8142. else
  8143. {
  8144. //replace reservation
  8145. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8146. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8147. }
  8148. }
  8149. }// END FOR GB_QUANTITY
  8150. }
  8151. else
  8152. {
  8153. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8154. {
  8155. tempIndex = 2;
  8156. }
  8157. else
  8158. {
  8159. tempIndex = (connectorIdInt -1);
  8160. }
  8161. for (int index = 0; index < AC_QUANTITY; index++)
  8162. {
  8163. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8164. {
  8165. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  8166. {
  8167. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  8168. {
  8169. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8170. {
  8171. 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))
  8172. {
  8173. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8174. }
  8175. else
  8176. {
  8177. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8178. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8179. }
  8180. }
  8181. 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'))
  8182. {
  8183. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8184. }
  8185. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8186. {
  8187. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8188. }
  8189. else
  8190. {
  8191. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8192. }
  8193. }
  8194. 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
  8195. {
  8196. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8197. }
  8198. }
  8199. else
  8200. {
  8201. //replace reservation
  8202. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8203. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8204. }
  8205. }
  8206. } // END FOR AC_QUANTITY
  8207. }
  8208. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8209. }
  8210. else if(connectorIdInt == 0)
  8211. {
  8212. //check Transaction active
  8213. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8214. {
  8215. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  8216. {
  8217. 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'))
  8218. {
  8219. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8220. goto end;
  8221. }
  8222. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8223. {
  8224. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8225. goto end;
  8226. }
  8227. 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
  8228. {
  8229. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8230. goto end;
  8231. }
  8232. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8233. {
  8234. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8235. goto end;
  8236. }
  8237. }
  8238. }// END FOR CHAdeMO_QUANTITY
  8239. for (int index = 0; index < CCS_QUANTITY; index++)
  8240. {
  8241. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8242. {
  8243. 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'))
  8244. {
  8245. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8246. goto end;
  8247. }
  8248. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  8249. {
  8250. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8251. goto end;
  8252. }
  8253. 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
  8254. {
  8255. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8256. goto end;
  8257. }
  8258. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8259. {
  8260. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8261. goto end;
  8262. }
  8263. }
  8264. } // END FOR CCS_QUANTITY
  8265. for (int index = 0; index < GB_QUANTITY; index++)
  8266. {
  8267. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8268. {
  8269. 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'))
  8270. {
  8271. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8272. goto end;
  8273. }
  8274. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8275. {
  8276. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8277. goto end;
  8278. }
  8279. 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
  8280. {
  8281. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8282. goto end;
  8283. }
  8284. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8285. {
  8286. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8287. goto end;
  8288. }
  8289. }
  8290. } // END FOR GB_QUANTITY
  8291. for (int index = 0; index < AC_QUANTITY; index++)
  8292. {
  8293. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  8294. {
  8295. 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'))
  8296. {
  8297. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8298. goto end;
  8299. }
  8300. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8301. {
  8302. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8303. goto end;
  8304. }
  8305. 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
  8306. {
  8307. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8308. goto end;
  8309. }
  8310. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8311. {
  8312. 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))
  8313. {
  8314. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8315. goto end;
  8316. }
  8317. }
  8318. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8319. {
  8320. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8321. goto end;
  8322. }
  8323. }
  8324. }// END FOR AC_QUANTITY
  8325. //The connectorId is 0
  8326. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  8327. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8328. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  8329. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  8330. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  8331. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  8332. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  8333. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  8334. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  8335. result = TRUE;
  8336. return result;
  8337. }
  8338. else
  8339. {
  8340. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8341. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8342. }
  8343. if(strcmp(comfirmstr,"Accepted") == 0)
  8344. {
  8345. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  8346. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  8347. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  8348. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  8349. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  8350. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  8351. result = TRUE;
  8352. return result;
  8353. }
  8354. end:
  8355. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  8356. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  8357. return result;
  8358. }
  8359. int handleResetRequest(char *uuid, char *payload)
  8360. {
  8361. mtrace();
  8362. int result = FAIL;
  8363. char sstr[10]={0},sstrtemp[30]={ 0 };
  8364. char typestr[10]={0};
  8365. char comfirmstr[20]={0};
  8366. int c = 0;
  8367. char *loc;
  8368. DEBUG_INFO("handleResetRequest...\n");
  8369. strcpy(sstrtemp, stringtrimspace(payload));
  8370. loc = strstr(sstrtemp, "type");
  8371. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8372. c = 0;
  8373. while (loc[3+strlen("type")+c] != '\"')
  8374. {
  8375. sstr[c] = loc[3+strlen("type")+c];
  8376. c++;
  8377. }
  8378. sstr[c] = '\0';
  8379. strcpy(typestr,sstr);
  8380. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  8381. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  8382. {
  8383. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  8384. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  8385. result = TRUE;
  8386. return result;
  8387. }
  8388. else
  8389. {
  8390. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  8391. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  8392. goto errorend;
  8393. }
  8394. errorend:
  8395. sendResetConfirmation(uuid, comfirmstr);
  8396. return result;
  8397. }
  8398. int handleSendLocalListRequest(char *uuid, char *payload)
  8399. {
  8400. mtrace();
  8401. int result = FAIL;
  8402. int listVersionInt;
  8403. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  8404. char listsearch[]="listVersion";
  8405. char updateTypesearch[]="updateType";
  8406. char localAuthorizationListsearch[]="localAuthorizationList";
  8407. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  8408. char CardList[500][160]={0};
  8409. char updateTypestr[15]={0};
  8410. char idTagstr[20]={0};
  8411. char parentIdTag[20]={0};
  8412. char expiryDate[30]={0};
  8413. char idTagstatus[16]={0};
  8414. int c = 0;
  8415. int i = 0;
  8416. char *delim1 = "}";
  8417. char * pch;
  8418. char *loc;
  8419. //char *ptr;
  8420. char comfirmstr[20];
  8421. //int n_localAuthorizations = 0;
  8422. int checkState_Faulted = FALSE;
  8423. DEBUG_INFO("handleSendLocalListRequest...\n");
  8424. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  8425. {
  8426. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8427. goto end;
  8428. }
  8429. //check Charge Point state
  8430. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8431. {
  8432. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8433. {
  8434. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8435. }
  8436. }
  8437. for (int index = 0; index < CCS_QUANTITY; index++)
  8438. {
  8439. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8440. {
  8441. checkState_Faulted = TRUE; //OCPP Status
  8442. }
  8443. }
  8444. for (int index = 0; index < GB_QUANTITY; index++)
  8445. {
  8446. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8447. {
  8448. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8449. }
  8450. }
  8451. //check Charge Point state
  8452. for (int index = 0; index < AC_QUANTITY; index++)
  8453. {
  8454. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8455. {
  8456. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8457. }
  8458. }
  8459. if(checkState_Faulted == TRUE)
  8460. {
  8461. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8462. goto end;
  8463. }
  8464. //Filter payload space
  8465. strcpy(sstrtemp, stringtrimspace(payload));
  8466. //listVersion
  8467. c = 0;
  8468. loc = strstr(sstrtemp, listsearch);
  8469. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  8470. {
  8471. sstr[c] = loc[strlen("listVersion")+2+c];
  8472. c++;
  8473. }
  8474. sstr[c] = '\0';
  8475. listVersionInt = atoi(sstr);
  8476. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8477. //updateType
  8478. loc = strstr(sstrtemp, updateTypesearch);
  8479. c = 0;
  8480. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  8481. {
  8482. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  8483. c++;
  8484. }
  8485. sstr[c] = '\0';
  8486. strcpy(updateTypestr, sstr);
  8487. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  8488. //localAuthorizationList
  8489. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8490. loc = strstr(sstrtemp, localAuthorizationListsearch);
  8491. if(loc != NULL) // localAuthorizationList is not NULL
  8492. {
  8493. //Check UpdateType
  8494. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8495. {
  8496. //Local list full update
  8497. printf("Local list full update.\n");
  8498. OCPP_getListVerion();
  8499. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8500. {
  8501. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8502. goto end;
  8503. }
  8504. OCPP_cleanLocalList();
  8505. }
  8506. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8507. {
  8508. //Local list different update
  8509. printf("Local list different update.\n");
  8510. OCPP_getListVerion();
  8511. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8512. {
  8513. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  8514. goto end;
  8515. }
  8516. }
  8517. else
  8518. {
  8519. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8520. goto end;
  8521. }
  8522. c = 0;
  8523. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  8524. {
  8525. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  8526. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8527. c++;
  8528. }
  8529. sstr[c] = '\0';
  8530. //DEBUG_INFO("sstr=%s\n", sstr);
  8531. //parsing strings to words
  8532. i = 0;
  8533. pch = strtok(sstr,delim1);
  8534. while (pch != NULL)
  8535. {
  8536. strcpy(CardList[i], pch);
  8537. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  8538. pch = strtok (NULL, delim1);
  8539. i = i + 1;
  8540. }
  8541. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  8542. //local Authorizations List Numbers
  8543. //n_localAuthorizations = i;
  8544. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8545. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  8546. c= 0;
  8547. while(c < i) // i is CardList Number
  8548. {
  8549. //Search "IdToken"
  8550. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8551. loc = strstr(CardList[c], "idTag");
  8552. int j = 0;
  8553. while (loc[3+strlen("idTag")+j] != '\"')
  8554. {
  8555. sstr[j] = loc[3+strlen("idTag")+j];
  8556. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8557. j++;
  8558. }
  8559. sstr[j] = '\0';
  8560. strcpy(idTagstr, sstr);
  8561. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  8562. //Search "expiryDate"
  8563. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8564. loc = strstr(CardList[c], "expiryDate");
  8565. j = 0;
  8566. if(loc != NULL)
  8567. {
  8568. while (loc[3+strlen("expiryDate")+j] != '\"')
  8569. {
  8570. sstr[j] = loc[3+strlen("expiryDate")+j];
  8571. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8572. j++;
  8573. }
  8574. sstr[j] = '\0';
  8575. strcpy(expiryDate, sstr);
  8576. }
  8577. else
  8578. {
  8579. strcpy(expiryDate, "");
  8580. }
  8581. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  8582. //Search "parentIdTag"
  8583. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8584. loc = strstr(CardList[c], "parentIdTag");
  8585. j = 0;
  8586. if(loc != NULL)
  8587. {
  8588. while (loc[3+strlen("parentIdTag")+j] != '\"')
  8589. {
  8590. sstr[j] = loc[3+strlen("parentIdTag")+j];
  8591. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8592. j++;
  8593. }
  8594. sstr[j] = '\0';
  8595. strcpy(parentIdTag, sstr);
  8596. }
  8597. else
  8598. {
  8599. strcpy(parentIdTag, "");
  8600. }
  8601. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  8602. //Search "status"
  8603. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8604. loc = strstr(CardList[c], "status");
  8605. j = 0;
  8606. while (loc[3+strlen("status")+j] != '\"')
  8607. {
  8608. sstr[j] = loc[3+strlen("status")+j];
  8609. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8610. j++;
  8611. }
  8612. sstr[j] = '\0';
  8613. strcpy(idTagstatus, sstr);
  8614. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  8615. OCPP_getIdTagFromLocalList(idTagstr);
  8616. //OCPP_getIdTagFromLocalList("test"); For Test
  8617. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  8618. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  8619. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8620. {
  8621. //Local list full update
  8622. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8623. // update list
  8624. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8625. //DEBUG_INFO("Local list full update. 1\n");
  8626. //OCPP_get_TableAuthlocalAllData();
  8627. //DEBUG_INFO("Local list full update. 2\n");
  8628. }
  8629. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8630. {
  8631. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8632. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  8633. }
  8634. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  8635. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  8636. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  8637. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  8638. c++;
  8639. }
  8640. }
  8641. else
  8642. {
  8643. //Check UpdateType
  8644. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8645. {
  8646. //Local list full update
  8647. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  8648. OCPP_cleanLocalList();
  8649. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8650. goto end;
  8651. }
  8652. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8653. {
  8654. //Local list different update
  8655. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  8656. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8657. goto end;
  8658. }
  8659. }
  8660. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8661. end:
  8662. sendSendLocalListConfirmation(uuid, comfirmstr);
  8663. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  8664. return result;
  8665. }
  8666. #define MAX 200
  8667. int handleSetChargingProfileRequest(char *uuid, char *payload)
  8668. {
  8669. mtrace();
  8670. int result = FAIL;
  8671. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  8672. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  8673. char chargingProfilePurposeStr[30]={0};
  8674. char chargingProfileKindStr[16]={0};
  8675. char recurrencyKindStr[10]={0};
  8676. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  8677. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  8678. int chargingSchedulePeriodCount = 0;
  8679. char comfirmstr[20]={0};
  8680. int meet= FALSE;
  8681. FILE *fptr1;
  8682. char filename[MAX]={0};
  8683. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  8684. char rmFileCmd[50]={0};
  8685. char tempchargingProfilePurposeStr[30]={0};
  8686. char word[1600]={0};
  8687. int n_chargingProfile = 0;
  8688. json_object *SetChargingProfile;
  8689. DEBUG_INFO("handleSetChargingProfileRequest\n");
  8690. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  8691. SetChargingProfile = json_tokener_parse(payload);
  8692. if(!is_error(SetChargingProfile))
  8693. {
  8694. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  8695. {
  8696. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  8697. if(connectorIdInt == 0)
  8698. {
  8699. memset(&ShmOCPP16Data->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  8700. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  8701. }
  8702. else
  8703. {
  8704. memset(&ShmOCPP16Data->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  8705. ShmOCPP16Data->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  8706. }
  8707. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  8708. }
  8709. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  8710. {
  8711. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  8712. {
  8713. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  8714. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8715. {
  8716. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8717. }
  8718. else
  8719. {
  8720. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8721. }
  8722. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  8723. }
  8724. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  8725. {
  8726. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  8727. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8728. {
  8729. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  8730. }
  8731. else
  8732. {
  8733. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  8734. }
  8735. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  8736. }
  8737. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8738. {
  8739. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  8740. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8741. {
  8742. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8743. }
  8744. else
  8745. {
  8746. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8747. }
  8748. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  8749. }
  8750. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  8751. {
  8752. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  8753. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8754. {
  8755. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8756. }
  8757. else
  8758. {
  8759. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8760. }
  8761. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  8762. }
  8763. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  8764. {
  8765. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  8766. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8767. {
  8768. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  8769. }
  8770. else
  8771. {
  8772. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  8773. }
  8774. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  8775. }
  8776. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  8777. {
  8778. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  8779. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8780. {
  8781. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8782. }
  8783. else
  8784. {
  8785. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8786. }
  8787. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  8788. }
  8789. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  8790. {
  8791. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  8792. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8793. {
  8794. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  8795. }
  8796. else
  8797. {
  8798. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  8799. }
  8800. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  8801. }
  8802. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  8803. {
  8804. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  8805. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8806. {
  8807. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  8808. }
  8809. else
  8810. {
  8811. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  8812. }
  8813. //DEBUG_INFO("validToStr: %s\n", validToStr);
  8814. }
  8815. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  8816. {
  8817. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  8818. {
  8819. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  8820. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8821. {
  8822. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8823. }
  8824. else
  8825. {
  8826. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8827. }
  8828. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  8829. }
  8830. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  8831. {
  8832. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  8833. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8834. {
  8835. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8836. }
  8837. else
  8838. {
  8839. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8840. }
  8841. //DEBUG_INFO("durationInt: %d\n", durationInt);
  8842. }
  8843. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  8844. {
  8845. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  8846. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8847. {
  8848. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8849. }
  8850. else
  8851. {
  8852. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8853. }
  8854. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  8855. }
  8856. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  8857. {
  8858. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  8859. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8860. {
  8861. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8862. }
  8863. else
  8864. {
  8865. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8866. }
  8867. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  8868. }
  8869. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  8870. {
  8871. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  8872. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  8873. if(chargingSchedulePeriodCount <= 10)
  8874. {
  8875. 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++)
  8876. {
  8877. 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)
  8878. {
  8879. 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"));
  8880. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8881. {
  8882. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  8883. }
  8884. else
  8885. {
  8886. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  8887. }
  8888. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  8889. }
  8890. 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)
  8891. {
  8892. 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"));
  8893. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8894. {
  8895. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  8896. }
  8897. else
  8898. {
  8899. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  8900. }
  8901. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  8902. }
  8903. 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)
  8904. {
  8905. 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"));
  8906. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8907. {
  8908. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  8909. }
  8910. else
  8911. {
  8912. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  8913. }
  8914. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  8915. }
  8916. }
  8917. }
  8918. }
  8919. }
  8920. }
  8921. }
  8922. json_object_put(SetChargingProfile);
  8923. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8924. {
  8925. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8926. goto end;
  8927. }
  8928. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8929. {
  8930. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8931. if(connectorIdInt != 0)
  8932. {
  8933. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8934. goto end;
  8935. }
  8936. strcpy(filename, ChargePointMaxProfile_JSON );
  8937. fptr1 = fopen(filename, "r");
  8938. if (!fptr1)
  8939. {
  8940. //file not exist
  8941. DEBUG_INFO("Unable to open the input file!!\n");
  8942. fptr1 = fopen(filename, "w+");
  8943. }
  8944. else
  8945. {
  8946. //Check Charging Profile Count
  8947. while(fscanf(fptr1, "%s", word) != EOF)
  8948. {
  8949. //DEBUG_INFO("word=%s\n",word);
  8950. if(strstr(word, "chargingProfileId")!= NULL)
  8951. {
  8952. //DEBUG_INFO("test chargingProfileId \n");
  8953. n_chargingProfile = n_chargingProfile + 1;
  8954. //DEBUG_INFO("chargingProfileId Found\n");
  8955. }
  8956. }
  8957. }
  8958. fclose(fptr1);
  8959. }
  8960. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8961. {
  8962. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8963. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8964. {
  8965. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8966. goto end;
  8967. }
  8968. memset(filename, 0, ARRAY_SIZE(filename));
  8969. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8970. fptr1 = fopen(filename, "r");
  8971. if (!fptr1)
  8972. {
  8973. //file not exist
  8974. //DEBUG_INFO("Unable to open the input file!!\n");
  8975. fptr1 = fopen(filename, "w+");
  8976. }
  8977. else
  8978. {
  8979. //Check Charging Profile Count
  8980. while(fscanf(fptr1, "%s", word) != EOF)
  8981. {
  8982. //DEBUG_INFO("word=%s\n",word);
  8983. if(strstr(word, "chargingProfileId")!= NULL)
  8984. {
  8985. //DEBUG_INFO("test chargingProfileId \n");
  8986. n_chargingProfile = n_chargingProfile + 1;
  8987. //DEBUG_INFO("chargingProfileId Found\n");
  8988. }
  8989. }
  8990. }
  8991. fclose(fptr1);
  8992. }
  8993. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8994. {
  8995. //printf("set chargingProfile 1-4\n");
  8996. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8997. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  8998. if(connectorIdInt == 0)
  8999. {
  9000. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9001. goto end;
  9002. }
  9003. int tempIndex = 0;
  9004. //check Transaction active
  9005. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9006. {
  9007. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9008. {
  9009. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9010. }
  9011. else
  9012. {
  9013. tempIndex = connectorIdInt -1;
  9014. }
  9015. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9016. {
  9017. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9018. {
  9019. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9020. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9021. {
  9022. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9023. {
  9024. meet = TRUE;
  9025. break;
  9026. }
  9027. }
  9028. }
  9029. }
  9030. }
  9031. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9032. {
  9033. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9034. {
  9035. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9036. }
  9037. else
  9038. {
  9039. tempIndex = connectorIdInt -1;
  9040. }
  9041. for (int index = 0; index < CCS_QUANTITY; index++)
  9042. {
  9043. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9044. {
  9045. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9046. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9047. {
  9048. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9049. {
  9050. meet = TRUE;
  9051. break;
  9052. }
  9053. }
  9054. }
  9055. }
  9056. }
  9057. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9058. {
  9059. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9060. {
  9061. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9062. }
  9063. else
  9064. {
  9065. tempIndex = connectorIdInt -1;
  9066. }
  9067. for (int index = 0; index < GB_QUANTITY; index++)
  9068. {
  9069. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9070. {
  9071. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9072. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9073. {
  9074. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9075. {
  9076. meet = TRUE;
  9077. break;
  9078. }
  9079. }
  9080. }
  9081. }
  9082. }
  9083. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9084. {
  9085. tempIndex = connectorIdInt -1;
  9086. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9087. {
  9088. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9089. {
  9090. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  9091. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9092. {
  9093. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9094. {
  9095. meet = TRUE;
  9096. break;
  9097. }
  9098. }
  9099. }
  9100. }
  9101. }
  9102. else
  9103. {
  9104. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9105. {
  9106. tempIndex = 2;
  9107. }
  9108. else
  9109. {
  9110. tempIndex = (connectorIdInt -1);
  9111. }
  9112. for (int index = 0; index < AC_QUANTITY; index++)
  9113. {
  9114. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9115. {
  9116. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9117. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9118. {
  9119. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9120. {
  9121. meet = TRUE;
  9122. break;
  9123. }
  9124. }
  9125. }
  9126. }
  9127. }
  9128. //check Transaction active
  9129. if(meet == FALSE)
  9130. {
  9131. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9132. goto end;
  9133. }
  9134. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9135. {
  9136. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9137. goto end;
  9138. }
  9139. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9140. fptr1 = fopen(filename, "r");
  9141. if (!fptr1)
  9142. {
  9143. //file not exist
  9144. DEBUG_INFO("Unable to open the input file!!\n");
  9145. fptr1 = fopen(filename, "w+");
  9146. }
  9147. else
  9148. {
  9149. //Check Charging Profile Count
  9150. while(fscanf(fptr1, "%s", word) != EOF)
  9151. {
  9152. //DEBUG_INFO("word=%s\n",word);
  9153. if(strstr(word, "chargingProfileId")!= NULL)
  9154. {
  9155. //DEBUG_INFO("test chargingProfileId \n");
  9156. n_chargingProfile = n_chargingProfile + 1;
  9157. //DEBUG_INFO("chargingProfileId Found\n");
  9158. }
  9159. }
  9160. }
  9161. fclose(fptr1);
  9162. }
  9163. // Check ChargeProfileMaxStackLevel
  9164. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  9165. {
  9166. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9167. goto end;
  9168. }
  9169. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9170. {
  9171. int i = 0;
  9172. char fnametemp[200]={0};
  9173. n_chargingProfile = 0;
  9174. //Check ChargePointMaxProfile.json exit
  9175. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9176. {
  9177. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  9178. //Check Charging Profile Count
  9179. while(fscanf(fptr1, "%s", word) != EOF)
  9180. {
  9181. //DEBUG_INFO("word=%s\n",word);
  9182. if(strstr(word, "chargingProfileId")!= NULL)
  9183. {
  9184. //DEBUG_INFO("test chargingProfileId \n");
  9185. n_chargingProfile = n_chargingProfile + 1;
  9186. i = i + 1;
  9187. //DEBUG_INFO("chargingProfileId Found\n");
  9188. }
  9189. memset(word, 0, ARRAY_SIZE(word));
  9190. }
  9191. fclose(fptr1);
  9192. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  9193. }
  9194. //Check TxDefaultProfile_0.json exit
  9195. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9196. {
  9197. i = 0;
  9198. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  9199. //Check Charging Profile Count
  9200. while(fscanf(fptr1, "%s", word) != EOF)
  9201. {
  9202. //DEBUG_INFO("word=%s\n",word);
  9203. if(strstr(word, "chargingProfileId")!= NULL)
  9204. {
  9205. //DEBUG_INFO("test chargingProfileId \n");
  9206. n_chargingProfile = n_chargingProfile + 1;
  9207. i = i + 1;
  9208. //DEBUG_INFO("chargingProfileId Found\n");
  9209. }
  9210. memset(word, 0, ARRAY_SIZE(word));
  9211. }
  9212. fclose(fptr1);
  9213. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  9214. }
  9215. //Check TxDefaultProfile_%d.json
  9216. for(int j=1; j <= gunTotalNumber; j++)
  9217. {
  9218. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9219. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9220. if((access(fnametemp,F_OK))!=-1)
  9221. {
  9222. i = 0;
  9223. fptr1 = fopen(fnametemp, "r");
  9224. //Check Charging Profile Count
  9225. while(fscanf(fptr1, "%s", word) != EOF)
  9226. {
  9227. //DEBUG_INFO("word=%s\n",word);
  9228. if(strstr(word, "chargingProfileId")!= NULL)
  9229. {
  9230. //DEBUG_INFO("test chargingProfileId \n");
  9231. n_chargingProfile = n_chargingProfile + 1;
  9232. i = i + 1;
  9233. //DEBUG_INFO("chargingProfileId Found\n");
  9234. }
  9235. memset(word, 0, ARRAY_SIZE(word));
  9236. }
  9237. fclose(fptr1);
  9238. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9239. }
  9240. }
  9241. //Check TxProfile_%d.json
  9242. for(int j=1; j <= gunTotalNumber; j++)
  9243. {
  9244. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9245. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9246. if((access(fnametemp,F_OK))!=-1)
  9247. {
  9248. i = 0;
  9249. fptr1 = fopen(fnametemp, "r");
  9250. //Check Charging Profile Count
  9251. while(fscanf(fptr1, "%s", word) != EOF)
  9252. {
  9253. //DEBUG_INFO("word=%s\n",word);
  9254. if(strstr(word, "chargingProfileId")!= NULL)
  9255. {
  9256. //DEBUG_INFO("test chargingProfileId \n");
  9257. n_chargingProfile = n_chargingProfile + 1;
  9258. i = i + 1;
  9259. //DEBUG_INFO("chargingProfileId Found\n");
  9260. }
  9261. memset(word, 0, ARRAY_SIZE(word));
  9262. }
  9263. fclose(fptr1);
  9264. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9265. }
  9266. }
  9267. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  9268. {
  9269. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9270. goto end;
  9271. }
  9272. }
  9273. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9274. //**********************************Write to File********************************************************/
  9275. FILE *infile;
  9276. FILE *outfile;
  9277. infile = fopen (filename, "r");
  9278. outfile = fopen (tempfile, "w");
  9279. int d =0;
  9280. d = fgetc(infile);
  9281. rewind(infile);
  9282. if(d == EOF)
  9283. {
  9284. // Profile is empty
  9285. fprintf(outfile,"%s\n",payload);
  9286. fclose(infile);
  9287. fclose(outfile);
  9288. sprintf(rmFileCmd,"rm -f %s",filename);
  9289. system(rmFileCmd);
  9290. rename(tempfile, filename);
  9291. }
  9292. else
  9293. {
  9294. // Profile is not empty
  9295. char buf[2048]={0};
  9296. int ChargingProfileAdded = FALSE;
  9297. while (fgets(buf, sizeof(buf), infile) != NULL)
  9298. {
  9299. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9300. json_object *tmpChargingProfile;
  9301. tmpChargingProfile = json_tokener_parse(buf);
  9302. if(!is_error(SetChargingProfile))
  9303. {
  9304. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  9305. {
  9306. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  9307. }
  9308. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  9309. {
  9310. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  9311. {
  9312. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  9313. }
  9314. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  9315. {
  9316. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  9317. }
  9318. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9319. {
  9320. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  9321. }
  9322. }
  9323. }
  9324. json_object_put(tmpChargingProfile);
  9325. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  9326. {
  9327. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9328. {
  9329. //DEBUG_INFO("update set chargingProfile to file -0\n");
  9330. if(ChargingProfileAdded == FALSE)
  9331. {
  9332. fprintf(outfile,"%s\n",payload);
  9333. ChargingProfileAdded = TRUE;
  9334. }
  9335. }
  9336. else
  9337. {
  9338. if(tempstackLevelInt < stackLevelInt)
  9339. {
  9340. if(ChargingProfileAdded == FALSE)
  9341. {
  9342. fprintf(outfile,"%s\n",buf);
  9343. fprintf(outfile,"%s\n",payload);
  9344. ChargingProfileAdded = TRUE;
  9345. }
  9346. else
  9347. {
  9348. fprintf(outfile,"%s\n",buf);
  9349. }
  9350. }
  9351. else
  9352. {
  9353. if(ChargingProfileAdded == FALSE)
  9354. {
  9355. fprintf(outfile,"%s\n",buf);
  9356. fprintf(outfile,"%s\n",payload);
  9357. ChargingProfileAdded = TRUE;
  9358. }
  9359. else
  9360. {
  9361. fprintf(outfile,"%s\n",buf);
  9362. }
  9363. }
  9364. }
  9365. }
  9366. else
  9367. {
  9368. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9369. {
  9370. if(ChargingProfileAdded == FALSE)
  9371. {
  9372. fprintf(outfile,"%s\n",buf);
  9373. fprintf(outfile,"%s\n",payload);
  9374. ChargingProfileAdded = TRUE;
  9375. }
  9376. else
  9377. {
  9378. fprintf(outfile,"%s\n",buf);
  9379. }
  9380. }
  9381. else if(tempstackLevelInt < stackLevelInt)
  9382. {
  9383. if(ChargingProfileAdded == FALSE)
  9384. {
  9385. fprintf(outfile,"%s\n",buf);
  9386. fprintf(outfile,"%s\n",payload);
  9387. ChargingProfileAdded = TRUE;
  9388. }
  9389. else
  9390. {
  9391. fprintf(outfile,"%s\n",buf);
  9392. }
  9393. }
  9394. else
  9395. {
  9396. if(ChargingProfileAdded == FALSE)
  9397. {
  9398. fprintf(outfile,"%s\n",buf);
  9399. fprintf(outfile,"%s\n",payload);
  9400. ChargingProfileAdded = TRUE;
  9401. }
  9402. else
  9403. {
  9404. fprintf(outfile,"%s\n",buf);
  9405. }
  9406. }
  9407. }
  9408. } // end of while loop
  9409. fclose(infile);
  9410. fclose(outfile);
  9411. sprintf(rmFileCmd,"rm -f %s",filename);
  9412. system(rmFileCmd);
  9413. rename(tempfile, filename);
  9414. }
  9415. sleep(1);
  9416. result = TRUE;
  9417. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9418. end:
  9419. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  9420. {
  9421. if(connectorIdInt == 0)
  9422. {
  9423. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9424. {
  9425. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  9426. }
  9427. }
  9428. else
  9429. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  9430. }
  9431. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  9432. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9433. return result;
  9434. }
  9435. int handleTriggerMessageRequest(char *uuid, char *payload)
  9436. {
  9437. mtrace();
  9438. int result = FAIL;
  9439. int connectorIdIsNULL = FALSE;
  9440. int connectorIdInt =0;
  9441. char sstr[40]={0},sstrtemp[100]={ 0 };
  9442. char requestedMessagestr[40]={0};
  9443. char comfirmstr[20]={0};
  9444. int c = 0;
  9445. char *loc;
  9446. DEBUG_INFO("handleTriggerMessageRequest\n");
  9447. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  9448. strcpy(sstrtemp, stringtrimspace(payload));
  9449. c = 0;
  9450. loc = strstr(sstrtemp, "requestedMessage");
  9451. while (loc[3+strlen("requestedMessage")+c] != '\"')
  9452. {
  9453. sstr[c] = loc[3+strlen("requestedMessage")+c];
  9454. c++;
  9455. }
  9456. sstr[c] = '\0';
  9457. strcpy(requestedMessagestr, sstr);
  9458. c = 0;
  9459. loc = strstr(sstrtemp, "connectorId");
  9460. if(loc == NULL)
  9461. {
  9462. connectorIdIsNULL = TRUE;
  9463. }
  9464. else
  9465. {
  9466. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9467. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  9468. {
  9469. sstr[c] = loc[strlen("connectorId")+2+c];
  9470. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9471. c++;
  9472. }
  9473. sstr[c] = '\0';
  9474. connectorIdInt = atoi(sstr);
  9475. }
  9476. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  9477. {
  9478. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  9479. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  9480. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  9481. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  9482. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  9483. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  9484. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  9485. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  9486. {
  9487. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  9488. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9489. return TRUE;
  9490. }
  9491. else
  9492. {
  9493. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9494. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9495. }
  9496. }
  9497. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  9498. {
  9499. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  9500. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9501. return TRUE;
  9502. }
  9503. //==========================
  9504. // Trigger message
  9505. //==========================
  9506. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  9507. {
  9508. if((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) &&
  9509. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) &&
  9510. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) &&
  9511. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING) )
  9512. {
  9513. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  9514. }
  9515. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  9516. }
  9517. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  9518. {
  9519. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  9520. }
  9521. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  9522. {
  9523. //sendBootNotificationRequest();
  9524. server_sign = FALSE;
  9525. }
  9526. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  9527. {
  9528. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  9529. }
  9530. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  9531. {
  9532. if(connectorIdIsNULL == FALSE)
  9533. {
  9534. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9535. {
  9536. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  9537. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  9538. }
  9539. }
  9540. else
  9541. {
  9542. for(int idx=0;idx< gunTotalNumber;idx++)
  9543. {
  9544. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  9545. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  9546. }
  9547. }
  9548. }
  9549. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  9550. {
  9551. if(connectorIdIsNULL == FALSE)
  9552. {
  9553. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9554. {
  9555. cpinitateMsg.bits[connectorIdInt -1].StatusNotificationReq = 1;
  9556. }
  9557. }
  9558. else
  9559. {
  9560. for(int idx=0;idx< gunTotalNumber;idx++)
  9561. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  9562. }
  9563. }
  9564. return result;
  9565. }
  9566. int handleUnlockConnectorRequest(char *uuid, char *payload)
  9567. {
  9568. mtrace();
  9569. int result = FAIL;
  9570. int connectorIdInt =0;
  9571. char comfirmstr[20]={0};
  9572. int tempIndex = 0;
  9573. json_object *UnlockConnector;
  9574. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  9575. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  9576. UnlockConnector = json_tokener_parse(payload);
  9577. if(!is_error(UnlockConnector))
  9578. {
  9579. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  9580. {
  9581. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  9582. }
  9583. }
  9584. json_object_put(UnlockConnector);
  9585. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  9586. if(gunTotalNumber == 0)
  9587. {
  9588. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9589. goto end;
  9590. }
  9591. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  9592. {
  9593. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9594. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9595. goto end;
  9596. }
  9597. else
  9598. {
  9599. //check Transaction active
  9600. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  9601. {
  9602. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9603. {
  9604. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9605. }
  9606. else
  9607. {
  9608. tempIndex = connectorIdInt -1;
  9609. }
  9610. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9611. {
  9612. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9613. {
  9614. //stop Transaction
  9615. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9616. }
  9617. }
  9618. }
  9619. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  9620. {
  9621. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9622. {
  9623. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9624. }
  9625. else
  9626. {
  9627. tempIndex = connectorIdInt -1;
  9628. }
  9629. for (int index = 0; index < CCS_QUANTITY; index++)
  9630. {
  9631. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9632. {
  9633. //stop Transaction
  9634. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9635. }
  9636. }
  9637. }
  9638. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  9639. {
  9640. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9641. {
  9642. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9643. }
  9644. else
  9645. {
  9646. tempIndex = connectorIdInt -1;
  9647. }
  9648. for (int index = 0; index < GB_QUANTITY; index++)
  9649. {
  9650. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  9651. {
  9652. //stop Transaction
  9653. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9654. }
  9655. }
  9656. }
  9657. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  9658. {
  9659. tempIndex = connectorIdInt -1;
  9660. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9661. {
  9662. 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)))
  9663. {
  9664. //stop Transaction
  9665. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9666. }
  9667. }
  9668. }
  9669. else
  9670. {
  9671. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9672. {
  9673. tempIndex = 2;
  9674. }
  9675. else
  9676. {
  9677. tempIndex = connectorIdInt-1;
  9678. }
  9679. for (int index = 0; index < AC_QUANTITY; index++)
  9680. {
  9681. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9682. {
  9683. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9684. }
  9685. }
  9686. }
  9687. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  9688. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  9689. result = TRUE;
  9690. return result;
  9691. }
  9692. end:
  9693. //json_object_put(obj); --- remove temporally
  9694. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  9695. return result;
  9696. }
  9697. static char UpdateFirmwarepayloadData[300]={0};
  9698. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  9699. {
  9700. mtrace();
  9701. int result = FAIL;
  9702. pthread_t t;
  9703. sendUpdateFirmwareConfirmation(uuid);
  9704. memset(UpdateFirmwarepayloadData, 0, 300);
  9705. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  9706. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  9707. ////pthread_join(t, NULL); //
  9708. //pthread_detach(t);
  9709. //sendUpdateFirmwareConfirmation(uuid);
  9710. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  9711. return result;
  9712. }
  9713. void *UpdateFirmwareProcess(void *data)
  9714. {
  9715. pthread_detach(pthread_self());
  9716. mtrace();
  9717. int retriesInt =0, retryIntervalInt=0;
  9718. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  9719. int port=0;
  9720. char locationstr[160]={0}, retrieveDatestr[30]={0};
  9721. int isSuccess = 0;
  9722. char ftpbuf[200];
  9723. char temp[100];
  9724. char * pch;
  9725. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  9726. json_object *UpdateFirmware;
  9727. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  9728. if(!is_error(UpdateFirmware))
  9729. {
  9730. // Required data
  9731. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  9732. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  9733. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  9734. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  9735. // Optional data
  9736. if(json_object_object_get(UpdateFirmware, "retries"))
  9737. {
  9738. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  9739. }
  9740. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  9741. {
  9742. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  9743. }
  9744. }
  9745. json_object_put(UpdateFirmware);
  9746. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9747. memset(path, 0, ARRAY_SIZE(path));
  9748. system("rm -f /mnt/*");
  9749. if(strncmp(locationstr,"http", 4) == 0)
  9750. {
  9751. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9752. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  9753. // protocol, user, password, host, path);
  9754. sprintf(ftppath,"/%s", path);
  9755. DEBUG_INFO("locationstr: %s\n", locationstr);
  9756. DEBUG_INFO("protocol: %s\n",protocol);
  9757. DEBUG_INFO("host: %s\n",host);
  9758. DEBUG_INFO("path: %s\n",path);
  9759. DEBUG_INFO("ftppath: %s\n",ftppath);
  9760. int ftppathlen=strlen(ftppath);
  9761. int i=1;
  9762. char filenametemp[50];
  9763. while(i < ftppathlen)
  9764. {
  9765. int len=ftppathlen-i;
  9766. if(ftppath[len]== 47) // '/' ascll code: 47
  9767. {
  9768. DEBUG_INFO("compare '/' all right\n");
  9769. break;
  9770. }
  9771. i=i+1;
  9772. }
  9773. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9774. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9775. filenametemp[i+1] = 0;
  9776. do
  9777. {
  9778. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9779. sleep(3);
  9780. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9781. if(!isSuccess)
  9782. {
  9783. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9784. sleep(retryIntervalInt);
  9785. }
  9786. else
  9787. {
  9788. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9789. }
  9790. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  9791. }
  9792. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  9793. {
  9794. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9795. memset(temp, 0, ARRAY_SIZE(temp));
  9796. //DEBUG_INFO("locationstr=%s\n",locationstr);
  9797. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  9798. int ftppathlen=strlen(ftpbuf);
  9799. int i=1;
  9800. char filenametemp[50];
  9801. while(i < ftppathlen)
  9802. {
  9803. int len=ftppathlen-i;
  9804. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9805. {
  9806. DEBUG_INFO(" compare '/' all right\n");
  9807. break;
  9808. }
  9809. i=i+1;
  9810. }
  9811. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9812. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9813. filenametemp[i+1] = 0;
  9814. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9815. pch=strchr(temp,'@');
  9816. if(pch==NULL)
  9817. {
  9818. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9819. protocol, host, &port, path);
  9820. strcpy(user,"anonymous");
  9821. strcpy(password,"");
  9822. }
  9823. else
  9824. {
  9825. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9826. protocol, user, password, host, &port, path);
  9827. }
  9828. sscanf(host,"%[^/]%s",host1, path1);
  9829. sprintf(ftppath,"%s", path1);
  9830. //DEBUG_INFO("protocol =%s\n",protocol);
  9831. //DEBUG_INFO("user =%s\n",user);
  9832. //DEBUG_INFO("password =%s\n",password);
  9833. //DEBUG_INFO("host1 =%s\n",host1);
  9834. //DEBUG_INFO("port =%d\n",port);
  9835. //DEBUG_INFO("path1 =%s\n",path1);
  9836. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9837. //ftpFile(host, user, password, port, ftppath, fname);
  9838. //download firmware pthred
  9839. if(port == 0)
  9840. {
  9841. port = 21;
  9842. }
  9843. do
  9844. {
  9845. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9846. sleep(3);
  9847. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9848. if(!isSuccess)
  9849. {
  9850. //BulldogUtil.sleepMs(interval*1000);
  9851. DEBUG_INFO("Update firmware request and download file fail.\n");
  9852. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9853. sleep(retryIntervalInt);
  9854. }
  9855. else
  9856. {
  9857. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9858. }
  9859. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9860. }
  9861. else
  9862. {
  9863. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9864. }
  9865. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9866. pthread_exit(NULL);
  9867. }
  9868. //==========================================
  9869. // Handle server response routine
  9870. //==========================================
  9871. void handleAuthorizeResponse(char *payload, int gun_index)
  9872. {
  9873. mtrace();
  9874. char expiryDatestr[30]={0};
  9875. char parentIdTagstr[20]={0};
  9876. char statusstr[20]={0};
  9877. int expiryDateISNULL=FALSE;
  9878. int parentIdTagISNULL=FALSE;
  9879. DEBUG_INFO("handleAuthorizeResponse...\n");
  9880. json_object *Authorize;
  9881. Authorize = json_tokener_parse(payload);
  9882. if(!is_error(Authorize))
  9883. {
  9884. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  9885. {
  9886. // Required data
  9887. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  9888. // Optional data
  9889. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  9890. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  9891. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  9892. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  9893. }
  9894. }
  9895. json_object_put(Authorize);
  9896. if(expiryDateISNULL == FALSE)
  9897. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9898. if(parentIdTagISNULL == FALSE)
  9899. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9900. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9901. //Update idTag information to authorization cache if supproted
  9902. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9903. {
  9904. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  9905. }
  9906. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9907. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9908. authorizeRetryTimes = 0;
  9909. }
  9910. void handleBootNotificationResponse(char *payload, int gun_index)
  9911. {
  9912. mtrace();
  9913. char statusStr[12]={0};
  9914. char currentTimeStr[30]={0};
  9915. int intervalInt = 0;
  9916. struct tm tp;
  9917. char buf[28]={0};
  9918. char timebuf[50]={0};
  9919. DEBUG_INFO("handleBootNotificationResponse...\n");
  9920. json_object *BootNotification;
  9921. BootNotification = json_tokener_parse(payload);
  9922. if(!is_error(BootNotification))
  9923. {
  9924. // Required data
  9925. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  9926. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  9927. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  9928. }
  9929. json_object_put(BootNotification);
  9930. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9931. BootNotificationInterval = intervalInt;
  9932. HeartBeatWaitTime = intervalInt;
  9933. //write back to ShmOCPP16Data->BootNotification
  9934. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  9935. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9936. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  9937. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  9938. {
  9939. server_sign = TRUE;
  9940. server_pending =FALSE;
  9941. }
  9942. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  9943. {
  9944. server_pending = TRUE;
  9945. }
  9946. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9947. tp.tm_isdst = -1;
  9948. //time_t utc = mktime(&tp);
  9949. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9950. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9951. sprintf(timebuf,"date -s '%s'",buf);
  9952. system(timebuf);
  9953. srand(time(NULL));
  9954. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  9955. //==============================================
  9956. // RTC sync
  9957. //==============================================
  9958. system("/sbin/hwclock -w --systohc");
  9959. SetOcppConnStatus(TRUE);
  9960. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  9961. }
  9962. void handleDataTransferResponse(char *payload, int gun_index)
  9963. {
  9964. char sstr[160]={0};//sstr[200]={ 0 };
  9965. int c = 0;
  9966. char *loc;
  9967. DEBUG_INFO("handleDataTransferResponse ...\n");
  9968. loc = strstr(payload, "status");
  9969. printf("loc=%s\n",loc);
  9970. c = 0;
  9971. while (loc[3+strlen("status")+c] != '\"')
  9972. {
  9973. sstr[c] = loc[3+strlen("status")+c];
  9974. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9975. c++;
  9976. }
  9977. sstr[c] = '\0';
  9978. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  9979. }
  9980. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  9981. {
  9982. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  9983. //struct json_object *obj;
  9984. // obj = json_tokener_parse(payload);
  9985. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  9986. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  9987. //No fields are defined.
  9988. }
  9989. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  9990. {
  9991. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  9992. //struct json_object *obj;
  9993. // obj = json_tokener_parse(payload);
  9994. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  9995. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  9996. //No fields are defined.
  9997. }
  9998. void handleHeartbeatResponse(char *payload, int gun_index)
  9999. {
  10000. mtrace();
  10001. struct tm tp;
  10002. char buf[28]={0};
  10003. char timebuf[50]={0};
  10004. DEBUG_INFO("handleHeartbeatResponse...\n");
  10005. json_object *Heartbeat;
  10006. Heartbeat = json_tokener_parse(payload);
  10007. if(!is_error(Heartbeat))
  10008. {
  10009. // Required data
  10010. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  10011. }
  10012. json_object_put(Heartbeat);
  10013. if(FirstHeartBeat == 0)
  10014. {
  10015. FirstHeartBeat = 1;
  10016. DEBUG_INFO("FirstHeartBeat \n");
  10017. }
  10018. HeartBeatWithNOResponse = 0;
  10019. clientTime.Heartbeat=time((time_t*)NULL);
  10020. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10021. tp.tm_isdst = -1;
  10022. //time_t utc = mktime(&tp);
  10023. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  10024. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  10025. sprintf(timebuf,"date -s '%s'",buf);
  10026. system(timebuf);
  10027. //==============================================
  10028. // RTC sync
  10029. //==============================================
  10030. system("/sbin/hwclock -w --systohc");
  10031. }
  10032. void handleMeterValuesResponse(char *payload, int gun_index)
  10033. {
  10034. mtrace();
  10035. DEBUG_INFO("handleMeterValuesResponse...\n");
  10036. }
  10037. void handleStartTransactionResponse(char *payload, int gun_index)
  10038. {
  10039. mtrace();
  10040. //int transactionIdInt = 0;
  10041. FILE *outfile;
  10042. char data[100]={0};
  10043. DEBUG_INFO("handleStartTransactionResponse...\n");
  10044. json_object *StartTransaction;
  10045. StartTransaction = json_tokener_parse(payload);
  10046. if(!is_error(StartTransaction))
  10047. {
  10048. // Required data
  10049. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  10050. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  10051. // Optional data
  10052. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  10053. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  10054. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  10055. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  10056. }
  10057. json_object_put(StartTransaction);
  10058. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  10059. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  10060. //-----------Start : write to the Queue TransactionId file -----------------//
  10061. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  10062. {}
  10063. else
  10064. {
  10065. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  10066. if(log == NULL)
  10067. {
  10068. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  10069. return ;
  10070. }
  10071. else
  10072. {
  10073. fclose(log);
  10074. }
  10075. }
  10076. // open file for writing
  10077. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  10078. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  10079. {
  10080. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  10081. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  10082. fputs(data, outfile);
  10083. fclose (outfile);
  10084. }
  10085. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10086. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10087. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  10088. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  10089. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10090. }
  10091. void handleStatusNotificationResponse(char *payload, int gun_index)
  10092. {
  10093. mtrace();
  10094. DEBUG_INFO("handleStatusNotificationResponse...\n");
  10095. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  10096. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  10097. }
  10098. void handleStopTransactionnResponse(char *payload, int gun_index)
  10099. {
  10100. mtrace();
  10101. DEBUG_INFO("handleStopTransactionnResponse...\n");
  10102. json_object *StopTransaction;
  10103. StopTransaction = json_tokener_parse(payload);
  10104. if(!is_error(StopTransaction))
  10105. {
  10106. // Optional data
  10107. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  10108. {
  10109. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  10110. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  10111. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  10112. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  10113. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  10114. }
  10115. }
  10116. json_object_put(StopTransaction);
  10117. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  10118. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  10119. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10120. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10121. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  10122. }
  10123. //==========================================
  10124. // Handle Error routine
  10125. //==========================================
  10126. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  10127. {
  10128. mtrace();
  10129. #ifdef SystemLogMessage
  10130. DEBUG_INFO("errorCode: %s\n", errorCode);
  10131. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  10132. DEBUG_INFO("errorDetails: %s\n", payload);
  10133. #endif
  10134. }
  10135. //===============================================
  10136. // Common routine
  10137. //===============================================
  10138. int initialConfigurationTable(void)
  10139. {
  10140. //clock_t start_t, end_t, total_t;
  10141. FILE *fp;
  10142. FILE *outfile;
  10143. char str[512]={0};
  10144. char sstr[256]={0};
  10145. int c = 0;
  10146. char *loc;
  10147. int confVersion = 1;
  10148. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  10149. //start_t = clock();
  10150. //printf("Starting of the program, start_t = %ld\n", start_t);
  10151. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  10152. // Check configuration file size is correct
  10153. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  10154. {
  10155. struct stat st;
  10156. stat("/Storage/OCPP/OCPPConfiguration", &st);
  10157. if(st.st_size < 3100)
  10158. {
  10159. system("rm -f /Storage/OCPP/OCPPConfiguration");
  10160. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  10161. }
  10162. }
  10163. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  10164. {
  10165. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10166. if(outfile == NULL)
  10167. {
  10168. DEBUG_INFO("Error opening file\n");
  10169. return FALSE;
  10170. }
  10171. /*Core Profile*/
  10172. //AllowOfflineTxForUnknownId
  10173. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10174. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10175. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  10176. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10177. //AuthorizationCacheEnabled
  10178. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10179. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10180. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10181. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10182. //AuthorizeRemoteTxRequests
  10183. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10184. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10185. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  10186. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10187. //BlinkRepeat
  10188. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10189. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10190. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10191. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10192. //ClockAlignedDataInterval
  10193. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10194. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10195. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10196. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10197. //ConnectionTimeOut
  10198. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10199. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10200. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10201. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10202. //GetConfigurationMaxKeys
  10203. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10204. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10205. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  10206. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10207. // HeartbeatInterval
  10208. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10209. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10210. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  10211. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10212. // LightIntensity
  10213. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10214. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10215. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10216. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10217. // LocalAuthorizeOffline
  10218. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  10219. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10220. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10221. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10222. // LocalPreAuthorize
  10223. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10224. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10225. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10226. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10227. // MaxEnergyOnInvalidId
  10228. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10229. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10230. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10231. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10232. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10233. // MeterValuesAlignedData
  10234. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10235. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10236. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10237. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10238. else
  10239. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10240. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10241. // MeterValuesAlignedDataMaxLength
  10242. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10243. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10244. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10245. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  10246. else
  10247. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "9" );
  10248. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10249. // MeterValuesSampledData
  10250. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10251. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10252. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10253. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10254. else
  10255. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10256. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10257. // MeterValuesSampledDataMaxLength
  10258. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10259. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10260. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10261. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  10262. else
  10263. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "9" );
  10264. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10265. // MeterValueSampleInterval
  10266. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10267. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10268. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  10269. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10270. // MinimumStatusDuration
  10271. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10272. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10273. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  10274. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  10275. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10276. // NumberOfConnectors
  10277. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10278. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10279. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10280. {
  10281. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10282. }
  10283. else
  10284. {
  10285. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10286. }
  10287. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10288. // ResetRetries
  10289. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10290. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10291. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10292. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10293. // ConnectorPhaseRotation
  10294. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10295. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10296. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10297. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10298. // ConnectorPhaseRotationMaxLength
  10299. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10300. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10301. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10302. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10303. // StopTransactionOnEVSideDisconnect
  10304. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10305. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10306. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10307. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10308. // StopTransactionOnInvalidId
  10309. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  10310. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10311. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10312. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10313. // StopTxnAlignedData
  10314. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  10315. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10316. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10317. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10318. // StopTxnAlignedDataMaxLength
  10319. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10320. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10321. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10322. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10323. // StopTxnSampledData
  10324. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10325. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10326. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10327. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10328. else
  10329. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10330. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10331. // StopTxnSampledDataMaxLength
  10332. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10333. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10334. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10335. {
  10336. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  10337. }
  10338. else
  10339. {
  10340. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  10341. }
  10342. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10343. // SupportedFeatureProfiles
  10344. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10345. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10346. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10347. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10348. // SupportedFeatureProfilesMaxLength
  10349. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10350. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10351. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10352. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10353. // TransactionMessageAttempts
  10354. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10355. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10356. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10357. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10358. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10359. // TransactionMessageRetryInterval
  10360. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10361. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10362. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10363. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10364. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10365. // UnlockConnectorOnEVSideDisconnect
  10366. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10367. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10368. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10369. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10370. // WebSocketPingInterval
  10371. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10372. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10373. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10374. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10375. // QueueOffLineStartTransactionMessage
  10376. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  10377. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10378. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10379. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10380. // AuthorizationKey
  10381. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  10382. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  10383. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "" );
  10384. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  10385. // SecurityProfile
  10386. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  10387. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  10388. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "0" );
  10389. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  10390. // DefaultPrice
  10391. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  10392. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  10393. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  10394. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  10395. // CustomDisplayCostAndPrice
  10396. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  10397. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  10398. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  10399. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  10400. // CustomIdleFeeAfterStop
  10401. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  10402. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  10403. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  10404. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  10405. // Configuration Version
  10406. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  10407. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  10408. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  10409. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  10410. //* Local Auth List Management Profile*/
  10411. #if 0
  10412. //For OCTT Test Case
  10413. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10414. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  10415. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10416. #endif
  10417. #if 1
  10418. //LocalAuthListEnabled
  10419. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10420. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10421. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10422. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10423. #endif
  10424. //LocalAuthListMaxLength
  10425. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10426. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10427. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10428. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10429. //SendLocalListMaxLength
  10430. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10431. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10432. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  10433. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10434. //ReserveConnectorZeroSupported
  10435. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10436. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10437. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10438. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10439. //* Smart Charging Profile */
  10440. //ChargeProfileMaxStackLevel
  10441. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10442. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10443. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10444. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10445. // ChargingScheduleAllowedChargingRateUnit
  10446. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10447. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10448. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10449. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10450. // ChargingScheduleMaxPeriods
  10451. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10452. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10453. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10454. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10455. // ConnectorSwitch3to1PhaseSupported
  10456. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10457. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10458. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10459. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10460. // MaxChargingProfilesInstalled
  10461. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10462. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10463. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  10464. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10465. fclose(outfile);
  10466. }
  10467. else
  10468. {
  10469. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10470. char keystr[60]={0};
  10471. char readonlystr[10]={0};
  10472. char valuestr[256]={0};
  10473. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10474. if(fp == NULL) {
  10475. DEBUG_INFO("Error opening file");
  10476. return FALSE;
  10477. }
  10478. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  10479. {
  10480. //DEBUG_INFO("Get Configuration \n");
  10481. if(strlen(str) > 0)
  10482. {
  10483. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10484. //*************************key*********************************/
  10485. if(strstr(str, "key") != NULL)
  10486. {
  10487. loc = strstr(str, "key");
  10488. c = 0;
  10489. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10490. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  10491. {
  10492. sstr[c] = loc[strlen("key")+3+c];
  10493. c++;
  10494. }
  10495. sstr[c] = '\0';
  10496. strcpy(keystr,sstr);
  10497. }
  10498. //*************************readonly*********************************/
  10499. if(strstr(str, "readonly") != NULL)
  10500. {
  10501. loc = strstr(str, "readonly");
  10502. c = 0;
  10503. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10504. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  10505. {
  10506. sstr[c] = loc[strlen("readonly")+2+c];
  10507. c++;
  10508. }
  10509. sstr[c] = '\0';
  10510. strcpy(readonlystr,sstr);
  10511. }
  10512. //*************************value*********************************/
  10513. if(strstr(str, "value") != NULL)
  10514. {
  10515. loc = strstr(str, "value");
  10516. c = 0;
  10517. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10518. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  10519. {
  10520. sstr[c] = loc[strlen("value")+3+c];
  10521. c++;
  10522. }
  10523. sstr[c] = '\0';
  10524. strcpy(valuestr,sstr);
  10525. }
  10526. // DEBUG_INFO("keystr=%s\n",keystr);
  10527. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10528. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10529. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10530. {
  10531. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10532. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10533. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10534. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10535. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10536. }
  10537. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10538. {
  10539. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10540. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10541. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10542. }
  10543. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10544. {
  10545. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10546. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10547. }
  10548. if(strcmp(keystr, "BlinkRepeat") == 0)
  10549. {
  10550. //Charger.BlinkRepeat = Integer.parseInt(value);
  10551. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10552. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10553. }
  10554. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10555. {
  10556. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10557. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10558. }
  10559. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10560. {
  10561. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10562. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10563. }
  10564. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10565. {
  10566. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10567. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  10568. }
  10569. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10570. {
  10571. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10572. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10573. HeartBeatWaitTime = atoi(valuestr);
  10574. }
  10575. if(strcmp(keystr, "LightIntensity") == 0)
  10576. {
  10577. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10578. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10579. }
  10580. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10581. {
  10582. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10583. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10584. }
  10585. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10586. {
  10587. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10588. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10589. }
  10590. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10591. {
  10592. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10593. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10594. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10595. }
  10596. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10597. {
  10598. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10599. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10600. }
  10601. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10602. {
  10603. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10604. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10605. }
  10606. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10607. {
  10608. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10609. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10610. }
  10611. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10612. {
  10613. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10614. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10615. }
  10616. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10617. {
  10618. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10619. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10620. }
  10621. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10622. {
  10623. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10624. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10625. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10626. }
  10627. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10628. {
  10629. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10630. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10631. }
  10632. if(strcmp(keystr, "ResetRetries") == 0)
  10633. {
  10634. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10635. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10636. }
  10637. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10638. {
  10639. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10640. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10641. }
  10642. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10643. {
  10644. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10645. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10646. }
  10647. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10648. {
  10649. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10650. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10651. }
  10652. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10653. {
  10654. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10655. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10656. }
  10657. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10658. {
  10659. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10660. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10661. }
  10662. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10663. {
  10664. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10665. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10666. }
  10667. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10668. {
  10669. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10670. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10671. }
  10672. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10673. {
  10674. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10675. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10676. }
  10677. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10678. {
  10679. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10680. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10681. }
  10682. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10683. {
  10684. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10685. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10686. }
  10687. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10688. {
  10689. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10690. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10691. TransactionMessageAttemptsValue = atoi(valuestr);
  10692. }
  10693. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10694. {
  10695. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10696. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10697. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10698. }
  10699. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10700. {
  10701. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10702. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10703. }
  10704. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10705. {
  10706. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10707. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10708. }
  10709. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  10710. {
  10711. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10712. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  10713. }
  10714. if(strcmp(keystr, "AuthorizationKey") == 0)
  10715. {
  10716. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10717. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  10718. }
  10719. if(strcmp(keystr, "SecurityProfile") == 0)
  10720. {
  10721. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10722. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  10723. }
  10724. if(strcmp(keystr, "DefaultPrice") == 0)
  10725. {
  10726. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10727. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  10728. }
  10729. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  10730. {
  10731. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10732. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  10733. }
  10734. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  10735. {
  10736. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10737. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  10738. }
  10739. if(strcmp(keystr, "ConfigurationVersion") == 0)
  10740. {
  10741. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10742. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  10743. }
  10744. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10745. {
  10746. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10747. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10748. }
  10749. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10750. {
  10751. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10752. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10753. }
  10754. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10755. {
  10756. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10757. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10758. }
  10759. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10760. {
  10761. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10762. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10763. }
  10764. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10765. {
  10766. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10767. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10768. }
  10769. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10770. {
  10771. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10772. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10773. }
  10774. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10775. {
  10776. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10777. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10778. }
  10779. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10780. {
  10781. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10782. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10783. }
  10784. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10785. {
  10786. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10787. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10788. }
  10789. }
  10790. }
  10791. fclose(fp);
  10792. }
  10793. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  10794. {
  10795. return PASS;
  10796. }
  10797. else
  10798. {
  10799. return FAIL;
  10800. }
  10801. }
  10802. void StoreConfigurationTable(void)
  10803. {
  10804. FILE *outfile;
  10805. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10806. if(outfile == NULL)
  10807. {
  10808. DEBUG_INFO("Error opening file");
  10809. return ;
  10810. }
  10811. /*Core Profile*/
  10812. //AllowOfflineTxForUnknownId
  10813. /*
  10814. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10815. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10816. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10817. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10818. */
  10819. //DEBUG_INFO("data=%s\n",data);
  10820. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10821. //AuthorizationCacheEnabled
  10822. /*
  10823. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10824. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10825. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10826. */
  10827. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10828. //AuthorizeRemoteTxRequests
  10829. /*
  10830. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10831. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10832. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10833. */
  10834. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10835. //BlinkRepeat
  10836. /*
  10837. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10838. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10839. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10840. */
  10841. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10842. //ClockAlignedDataInterval
  10843. /*
  10844. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10845. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10846. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10847. */
  10848. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10849. //ConnectionTimeOut
  10850. /*
  10851. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10852. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10853. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10854. */
  10855. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10856. //GetConfigurationMaxKeys
  10857. /*
  10858. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10859. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10860. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10861. */
  10862. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10863. // HeartbeatInterval
  10864. /*
  10865. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10866. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10867. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10868. */
  10869. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10870. // LightIntensity
  10871. /*
  10872. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10874. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10875. */
  10876. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10877. // LocalAuthorizeOffline
  10878. /*
  10879. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10880. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10881. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10882. */
  10883. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10884. // LocalPreAuthorize
  10885. /*
  10886. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10888. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10889. */
  10890. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10891. // MaxEnergyOnInvalidId
  10892. /*
  10893. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10894. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10895. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10896. */
  10897. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10898. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10899. // MeterValuesAlignedData
  10900. /*
  10901. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10902. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10903. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10904. */
  10905. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10906. // MeterValuesAlignedDataMaxLength
  10907. /*
  10908. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10909. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10910. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10911. */
  10912. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10913. // MeterValuesSampledData
  10914. /*
  10915. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10916. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10917. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10918. */
  10919. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10920. // MeterValuesSampledDataMaxLength
  10921. /*
  10922. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10923. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10924. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10925. */
  10926. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10927. // MeterValueSampleInterval
  10928. /*
  10929. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10930. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10931. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10932. */
  10933. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10934. // MinimumStatusDuration
  10935. /*
  10936. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10937. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10938. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10939. */
  10940. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10941. // NumberOfConnectors
  10942. /*
  10943. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10944. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10945. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10946. {
  10947. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10948. }
  10949. else
  10950. {
  10951. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10952. }
  10953. */
  10954. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10955. // ResetRetries
  10956. /*
  10957. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10958. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10959. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10960. */
  10961. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10962. // ConnectorPhaseRotation
  10963. /*
  10964. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10965. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10966. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10967. */
  10968. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10969. // ConnectorPhaseRotationMaxLength
  10970. /*
  10971. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10972. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10973. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10974. */
  10975. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10976. // StopTransactionOnEVSideDisconnect
  10977. /*
  10978. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10979. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10980. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10981. */
  10982. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10983. // StopTransactionOnInvalidId
  10984. /*
  10985. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  10986. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10987. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10988. */
  10989. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10990. // StopTxnAlignedData
  10991. /*
  10992. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  10993. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10994. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10995. */
  10996. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10997. // StopTxnAlignedDataMaxLength
  10998. /*
  10999. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  11000. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  11001. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  11002. */
  11003. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  11004. // StopTxnSampledData
  11005. /*
  11006. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  11007. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  11008. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  11009. */
  11010. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  11011. // StopTxnSampledDataMaxLength
  11012. /*
  11013. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  11014. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  11015. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  11016. */
  11017. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  11018. // SupportedFeatureProfiles
  11019. /*
  11020. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  11021. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  11022. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  11023. */
  11024. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  11025. // SupportedFeatureProfilesMaxLength
  11026. /*
  11027. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  11028. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  11029. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  11030. */
  11031. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  11032. // TransactionMessageAttempts
  11033. /*
  11034. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  11035. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  11036. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  11037. */
  11038. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11039. // TransactionMessageRetryInterval
  11040. /*
  11041. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  11042. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  11043. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  11044. */
  11045. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11046. // UnlockConnectorOnEVSideDisconnect
  11047. /*
  11048. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  11049. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  11050. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  11051. */
  11052. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  11053. // WebSocketPingInterval
  11054. /*
  11055. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  11056. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  11057. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  11058. */
  11059. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  11060. // QueueOffLineStartTransactionMessage
  11061. /*
  11062. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  11063. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  11064. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  11065. */
  11066. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  11067. // AuthorizationKey
  11068. /*
  11069. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  11070. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  11071. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  11072. */
  11073. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  11074. // SecurityProfile
  11075. /*
  11076. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  11077. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  11078. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  11079. */
  11080. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  11081. // DefaultPrice
  11082. /*
  11083. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  11084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  11085. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  11086. */
  11087. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  11088. // CustomDisplayCostAndPrice
  11089. /*
  11090. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  11091. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  11092. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  11093. */
  11094. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  11095. // CustomIdleFeeAfterStop
  11096. /*
  11097. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  11098. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  11099. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  11100. */
  11101. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  11102. //* Local Auth List Management Profile*/
  11103. //LocalAuthListEnabled
  11104. /*
  11105. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11106. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  11107. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11108. */
  11109. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11110. //LocalAuthListMaxLength
  11111. /*
  11112. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  11113. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  11114. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  11115. */
  11116. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  11117. //SendLocalListMaxLength
  11118. /*
  11119. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  11120. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  11121. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  11122. */
  11123. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  11124. //ReserveConnectorZeroSupported
  11125. /*
  11126. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  11127. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  11128. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  11129. */
  11130. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11131. //* Smart Charging Profile */
  11132. //ChargeProfileMaxStackLevel
  11133. /*
  11134. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  11135. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  11136. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  11137. */
  11138. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11139. // ChargingScheduleAllowedChargingRateUnit
  11140. /*
  11141. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  11142. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  11143. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  11144. */
  11145. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11146. // ChargingScheduleMaxPeriods
  11147. /*
  11148. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  11149. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  11150. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  11151. */
  11152. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11153. // ConnectorSwitch3to1PhaseSupported
  11154. /*
  11155. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11156. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11157. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  11158. */
  11159. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11160. // MaxChargingProfilesInstalled
  11161. /*
  11162. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11163. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11164. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  11165. */
  11166. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11167. fclose(outfile);
  11168. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11169. }
  11170. void getKeyValue(char *keyReq)
  11171. {
  11172. int isEmpty = FALSE;
  11173. int isKnowKey = FALSE;
  11174. DEBUG_INFO("keyReq = %s\n", keyReq);
  11175. if((keyReq == NULL) || (strlen(keyReq) == 0))
  11176. isEmpty = TRUE;
  11177. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  11178. {
  11179. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  11180. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  11181. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11182. {
  11183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  11184. }
  11185. else
  11186. {
  11187. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  11188. }
  11189. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  11190. isKnowKey = TRUE;
  11191. }
  11192. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  11193. {
  11194. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  11195. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  11196. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11197. {
  11198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  11199. }
  11200. else
  11201. {
  11202. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  11203. }
  11204. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  11205. isKnowKey = TRUE;
  11206. }
  11207. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  11208. {
  11209. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  11210. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  11211. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11212. {
  11213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  11214. }
  11215. else
  11216. {
  11217. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  11218. }
  11219. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  11220. isKnowKey = TRUE;
  11221. }
  11222. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  11223. {
  11224. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  11225. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  11226. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11227. {
  11228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  11229. }
  11230. else
  11231. {
  11232. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  11233. }
  11234. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  11235. isKnowKey = TRUE;
  11236. }
  11237. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  11238. {
  11239. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  11240. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  11241. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11242. {
  11243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  11244. }
  11245. else
  11246. {
  11247. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  11248. }
  11249. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  11250. isKnowKey = TRUE;
  11251. }
  11252. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  11253. {
  11254. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  11255. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  11256. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11257. {
  11258. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  11259. }
  11260. else
  11261. {
  11262. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  11263. }
  11264. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  11265. isKnowKey = TRUE;
  11266. }
  11267. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  11268. {
  11269. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  11270. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  11271. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11272. {
  11273. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  11274. }
  11275. else
  11276. {
  11277. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  11278. }
  11279. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  11280. isKnowKey = TRUE;
  11281. }
  11282. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  11283. {
  11284. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  11285. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  11286. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11287. {
  11288. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  11289. }
  11290. else
  11291. {
  11292. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  11293. }
  11294. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  11295. isKnowKey = TRUE;
  11296. }
  11297. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  11298. {
  11299. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  11300. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  11301. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11302. {
  11303. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  11304. }
  11305. else
  11306. {
  11307. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  11308. }
  11309. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  11310. isKnowKey = TRUE;
  11311. }
  11312. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  11313. {
  11314. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  11315. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  11316. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11317. {
  11318. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  11319. }
  11320. else
  11321. {
  11322. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  11323. }
  11324. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  11325. isKnowKey = TRUE;
  11326. }
  11327. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  11328. {
  11329. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  11330. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  11331. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11332. {
  11333. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  11334. }
  11335. else
  11336. {
  11337. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  11338. }
  11339. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  11340. isKnowKey = TRUE;
  11341. }
  11342. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  11343. {
  11344. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  11345. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  11346. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11347. {
  11348. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11349. }
  11350. else
  11351. {
  11352. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11353. }
  11354. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  11355. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  11356. isKnowKey = TRUE;
  11357. }
  11358. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  11359. {
  11360. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  11361. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  11362. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11363. {
  11364. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11365. }
  11366. else
  11367. {
  11368. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11369. }
  11370. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  11371. isKnowKey = TRUE;
  11372. }
  11373. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  11374. {
  11375. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  11376. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  11377. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11378. {
  11379. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11380. }
  11381. else
  11382. {
  11383. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11384. }
  11385. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  11386. isKnowKey = TRUE;
  11387. }
  11388. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  11389. {
  11390. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  11391. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  11392. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11393. {
  11394. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  11395. }
  11396. else
  11397. {
  11398. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  11399. }
  11400. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  11401. isKnowKey = TRUE;
  11402. }
  11403. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  11404. {
  11405. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  11406. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  11407. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11408. {
  11409. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11410. }
  11411. else
  11412. {
  11413. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11414. }
  11415. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  11416. isKnowKey = TRUE;
  11417. }
  11418. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  11419. {
  11420. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  11421. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  11422. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11423. {
  11424. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  11425. }
  11426. else
  11427. {
  11428. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  11429. }
  11430. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  11431. isKnowKey = TRUE;
  11432. }
  11433. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  11434. {
  11435. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  11436. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  11437. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11438. {
  11439. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  11440. }
  11441. else
  11442. {
  11443. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  11444. }
  11445. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  11446. isKnowKey = TRUE;
  11447. }
  11448. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  11449. {
  11450. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  11451. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  11452. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11453. {
  11454. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  11455. }
  11456. else
  11457. {
  11458. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  11459. }
  11460. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  11461. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  11462. isKnowKey = TRUE;
  11463. }
  11464. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  11465. {
  11466. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  11467. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11468. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11469. {
  11470. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11471. }
  11472. else
  11473. {
  11474. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11475. }
  11476. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11477. isKnowKey = TRUE;
  11478. }
  11479. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11480. {
  11481. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11482. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11483. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11484. {
  11485. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11486. }
  11487. else
  11488. {
  11489. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11490. }
  11491. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11492. isKnowKey = TRUE;
  11493. }
  11494. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11495. {
  11496. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11497. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11498. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11499. {
  11500. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11501. }
  11502. else
  11503. {
  11504. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11505. }
  11506. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11507. isKnowKey = TRUE;
  11508. }
  11509. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11510. {
  11511. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11512. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11513. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11514. {
  11515. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11516. }
  11517. else
  11518. {
  11519. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11520. }
  11521. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11522. isKnowKey = TRUE;
  11523. }
  11524. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11525. {
  11526. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11527. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11528. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11529. {
  11530. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11531. }
  11532. else
  11533. {
  11534. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11535. }
  11536. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11537. isKnowKey = TRUE;
  11538. }
  11539. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11540. {
  11541. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11542. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11543. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11544. {
  11545. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11546. }
  11547. else
  11548. {
  11549. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11550. }
  11551. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11552. isKnowKey = TRUE;
  11553. }
  11554. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11555. {
  11556. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11557. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11558. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11559. {
  11560. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11561. }
  11562. else
  11563. {
  11564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11565. }
  11566. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11567. isKnowKey = TRUE;
  11568. }
  11569. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11570. {
  11571. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11572. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11573. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11574. {
  11575. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11576. }
  11577. else
  11578. {
  11579. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11580. }
  11581. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11582. isKnowKey = TRUE;
  11583. }
  11584. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11585. {
  11586. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11587. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11588. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11589. {
  11590. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11591. }
  11592. else
  11593. {
  11594. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11595. }
  11596. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11597. isKnowKey = TRUE;
  11598. }
  11599. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11600. {
  11601. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11602. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11603. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11604. {
  11605. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11606. }
  11607. else
  11608. {
  11609. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11610. }
  11611. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11612. isKnowKey = TRUE;
  11613. }
  11614. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11615. {
  11616. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11617. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11618. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11619. {
  11620. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11621. }
  11622. else
  11623. {
  11624. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11625. }
  11626. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11627. isKnowKey = TRUE;
  11628. }
  11629. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11630. {
  11631. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11632. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11633. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11634. {
  11635. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11636. }
  11637. else
  11638. {
  11639. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11640. }
  11641. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11642. isKnowKey = TRUE;
  11643. }
  11644. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11645. {
  11646. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11647. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11648. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11649. {
  11650. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11651. }
  11652. else
  11653. {
  11654. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11655. }
  11656. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11657. isKnowKey = TRUE;
  11658. }
  11659. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11660. {
  11661. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11662. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11663. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11664. {
  11665. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11666. }
  11667. else
  11668. {
  11669. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11670. }
  11671. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11672. isKnowKey = TRUE;
  11673. }
  11674. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11675. {
  11676. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11677. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11678. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11679. {
  11680. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11681. }
  11682. else
  11683. {
  11684. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11685. }
  11686. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11687. isKnowKey = TRUE;
  11688. }
  11689. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  11690. {
  11691. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  11692. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  11693. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  11694. {
  11695. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  11696. }
  11697. else
  11698. {
  11699. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  11700. }
  11701. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  11702. isKnowKey = TRUE;
  11703. }
  11704. /*
  11705. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  11706. {
  11707. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  11708. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  11709. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  11710. {
  11711. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  11712. }
  11713. else
  11714. {
  11715. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  11716. }
  11717. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  11718. isKnowKey = TRUE;
  11719. }*/
  11720. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  11721. {
  11722. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  11723. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  11724. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  11725. {
  11726. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  11727. }
  11728. else
  11729. {
  11730. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  11731. }
  11732. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  11733. isKnowKey = TRUE;
  11734. }
  11735. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  11736. {
  11737. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  11738. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  11739. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  11740. {
  11741. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  11742. }
  11743. else
  11744. {
  11745. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  11746. }
  11747. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  11748. isKnowKey = TRUE;
  11749. }
  11750. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  11751. {
  11752. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  11753. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  11754. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  11755. {
  11756. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  11757. }
  11758. else
  11759. {
  11760. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  11761. }
  11762. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  11763. isKnowKey = TRUE;
  11764. }
  11765. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  11766. {
  11767. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  11768. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  11769. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  11770. {
  11771. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  11772. }
  11773. else
  11774. {
  11775. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  11776. }
  11777. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  11778. isKnowKey = TRUE;
  11779. }
  11780. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  11781. {
  11782. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  11783. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  11784. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  11785. {
  11786. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  11787. }
  11788. else
  11789. {
  11790. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  11791. }
  11792. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  11793. isKnowKey = TRUE;
  11794. }
  11795. #if 1
  11796. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11797. {
  11798. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11799. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11800. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11801. {
  11802. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11803. }
  11804. else
  11805. {
  11806. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11807. }
  11808. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11809. isKnowKey = TRUE;
  11810. }
  11811. #endif
  11812. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11813. {
  11814. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11815. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11816. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11817. {
  11818. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11819. }
  11820. else
  11821. {
  11822. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11823. }
  11824. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11825. isKnowKey = TRUE;
  11826. }
  11827. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11828. {
  11829. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11830. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11831. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11832. {
  11833. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11834. }
  11835. else
  11836. {
  11837. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11838. }
  11839. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11840. isKnowKey = TRUE;
  11841. }
  11842. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11843. {
  11844. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11845. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11846. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11847. {
  11848. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11849. }
  11850. else
  11851. {
  11852. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11853. }
  11854. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11855. isKnowKey = TRUE;
  11856. }
  11857. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11858. {
  11859. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11860. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11861. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11862. {
  11863. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11864. }
  11865. else
  11866. {
  11867. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11868. }
  11869. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11870. isKnowKey = TRUE;
  11871. }
  11872. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11873. {
  11874. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11875. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11876. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11877. {
  11878. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11879. }
  11880. else
  11881. {
  11882. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11883. }
  11884. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11885. isKnowKey = TRUE;
  11886. }
  11887. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11888. {
  11889. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11890. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11891. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11892. {
  11893. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11894. }
  11895. else
  11896. {
  11897. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11898. }
  11899. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11900. isKnowKey = TRUE;
  11901. }
  11902. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11903. {
  11904. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11905. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11906. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11907. {
  11908. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11909. }
  11910. else
  11911. {
  11912. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11913. }
  11914. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11915. isKnowKey = TRUE;
  11916. }
  11917. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11918. {
  11919. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11920. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11921. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11922. {
  11923. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11924. }
  11925. else
  11926. {
  11927. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11928. }
  11929. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11930. isKnowKey = TRUE;
  11931. }
  11932. //=========================================================
  11933. if(!isEmpty && !isKnowKey)
  11934. {
  11935. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11936. strcpy(unknownkey[UnknownKeynum], keyReq);
  11937. UnknownKeynum = UnknownKeynum + 1;
  11938. }
  11939. }
  11940. void processUnkownKey(void)
  11941. {
  11942. DEBUG_INFO("processUnkownKey...\n");
  11943. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11944. for(int index=0; index < UnknownKeynum; index++)
  11945. {
  11946. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11947. {
  11948. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11949. }
  11950. }
  11951. }
  11952. int setKeyValue(char *key, char *value)
  11953. {
  11954. int isSuccess = NotSupported;
  11955. int check_ascii=0;
  11956. char str[256]={0};
  11957. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  11958. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11959. {
  11960. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11961. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11962. {
  11963. strcpy(str, (const char*)value);
  11964. for(int i = 0; str[i]; i++){
  11965. str[i] = tolower(str[i]);
  11966. }
  11967. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11968. isSuccess = ConfigurationStatus_Accepted;
  11969. }
  11970. else
  11971. {
  11972. isSuccess = ConfigurationStatus_Rejected;
  11973. }
  11974. }
  11975. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11976. {
  11977. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11978. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11979. {
  11980. strcpy(str, (const char*)value);
  11981. for(int i = 0; str[i]; i++){
  11982. str[i] = tolower(str[i]);
  11983. }
  11984. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11985. isSuccess = ConfigurationStatus_Accepted;
  11986. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11987. }
  11988. else
  11989. {
  11990. isSuccess = ConfigurationStatus_Rejected;
  11991. }
  11992. }
  11993. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11994. {
  11995. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11996. {
  11997. strcpy(str, (const char*)value);
  11998. for(int i = 0; str[i]; i++)
  11999. {
  12000. str[i] = tolower(str[i]);
  12001. }
  12002. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  12003. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12004. isSuccess = ConfigurationStatus_Accepted;
  12005. }
  12006. else
  12007. {
  12008. isSuccess = ConfigurationStatus_Rejected;
  12009. }
  12010. }
  12011. if(strcmp(key, "BlinkRepeat") == 0)
  12012. {
  12013. //Charger.BlinkRepeat = Integer.parseInt(value);
  12014. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  12015. {
  12016. check_ascii = value[0];
  12017. if( (check_ascii < 48) || (check_ascii > 57) )
  12018. {
  12019. isSuccess = ConfigurationStatus_Rejected;
  12020. }
  12021. else
  12022. {
  12023. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  12024. isSuccess = ConfigurationStatus_Accepted;
  12025. }
  12026. }
  12027. else
  12028. {
  12029. isSuccess = ConfigurationStatus_Rejected;
  12030. }
  12031. }
  12032. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  12033. {
  12034. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  12035. {
  12036. check_ascii = value[0];
  12037. if( (check_ascii < 48) || (check_ascii > 57) )
  12038. {
  12039. isSuccess = ConfigurationStatus_Rejected;
  12040. }
  12041. else
  12042. {
  12043. if((atoi(value) == 0) || (atoi(value) >= 10))
  12044. {
  12045. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  12046. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  12047. isSuccess = ConfigurationStatus_Accepted;
  12048. }
  12049. else
  12050. isSuccess = ConfigurationStatus_Rejected;
  12051. }
  12052. }
  12053. else
  12054. {
  12055. isSuccess = ConfigurationStatus_Rejected;
  12056. }
  12057. }
  12058. if(strcmp(key, "ConnectionTimeOut") == 0 )
  12059. {
  12060. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  12061. {
  12062. check_ascii = value[0];
  12063. if( (check_ascii < 48) || (check_ascii > 57) )
  12064. {
  12065. isSuccess = ConfigurationStatus_Rejected;
  12066. }
  12067. else
  12068. {
  12069. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  12070. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  12071. isSuccess = ConfigurationStatus_Accepted;
  12072. }
  12073. }
  12074. else
  12075. {
  12076. isSuccess = ConfigurationStatus_Rejected;
  12077. }
  12078. }
  12079. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  12080. {
  12081. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  12082. {
  12083. check_ascii = value[0];
  12084. if( (check_ascii < 48) || (check_ascii > 57) )
  12085. {
  12086. isSuccess = ConfigurationStatus_Rejected;
  12087. }
  12088. else
  12089. {
  12090. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  12091. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  12092. isSuccess = ConfigurationStatus_Accepted;
  12093. }
  12094. }
  12095. else
  12096. {
  12097. isSuccess = ConfigurationStatus_Rejected;
  12098. }
  12099. }
  12100. if(strcmp(key, "HeartbeatInterval") == 0)
  12101. {
  12102. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  12103. {
  12104. check_ascii = value[0];
  12105. if( (check_ascii < 48) || (check_ascii > 57) )
  12106. {
  12107. isSuccess = ConfigurationStatus_Rejected;
  12108. }
  12109. else
  12110. {
  12111. if((atoi(value) == 0) || (atoi(value) >= 10))
  12112. {
  12113. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  12114. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  12115. HeartBeatWaitTime = atoi(value);
  12116. isSuccess = ConfigurationStatus_Accepted;
  12117. }
  12118. else
  12119. {
  12120. isSuccess = ConfigurationStatus_Rejected;
  12121. }
  12122. }
  12123. }
  12124. else
  12125. {
  12126. isSuccess = ConfigurationStatus_Rejected;
  12127. }
  12128. }
  12129. if(strcmp(key, "LightIntensity") == 0)
  12130. {
  12131. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  12132. {
  12133. check_ascii = value[0];
  12134. if( (check_ascii < 48) || (check_ascii > 57) )
  12135. {
  12136. isSuccess = ConfigurationStatus_Rejected;
  12137. }
  12138. else
  12139. {
  12140. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  12141. isSuccess = ConfigurationStatus_Accepted;
  12142. }
  12143. }
  12144. else
  12145. {
  12146. isSuccess = ConfigurationStatus_Rejected;
  12147. }
  12148. }
  12149. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  12150. {
  12151. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  12152. {
  12153. strcpy(str, (const char*)value);
  12154. for(int i = 0; str[i]; i++)
  12155. {
  12156. str[i] = tolower(str[i]);
  12157. }
  12158. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12159. isSuccess = ConfigurationStatus_Accepted;
  12160. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12161. }
  12162. else
  12163. {
  12164. isSuccess = ConfigurationStatus_Rejected;
  12165. }
  12166. }
  12167. if(strcmp(key, "LocalPreAuthorize") == 0)
  12168. {
  12169. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  12170. {
  12171. strcpy(str, (const char*)value);
  12172. for(int i = 0; str[i]; i++)
  12173. {
  12174. str[i] = tolower(str[i]);
  12175. }
  12176. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12177. isSuccess = ConfigurationStatus_Accepted;
  12178. }
  12179. else
  12180. {
  12181. isSuccess = ConfigurationStatus_Rejected;
  12182. }
  12183. }
  12184. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  12185. {
  12186. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  12187. {
  12188. check_ascii = value[0];
  12189. if( (check_ascii < 48) || (check_ascii > 57) )
  12190. {
  12191. isSuccess = ConfigurationStatus_Rejected;
  12192. }
  12193. else
  12194. {
  12195. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  12196. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  12197. isSuccess = ConfigurationStatus_Accepted;
  12198. }
  12199. }
  12200. else
  12201. {
  12202. isSuccess = ConfigurationStatus_Rejected;
  12203. }
  12204. }
  12205. if(strcmp(key, "MeterValuesAlignedData") == 0)
  12206. {
  12207. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  12208. {
  12209. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  12210. isSuccess = ConfigurationStatus_Accepted;
  12211. }
  12212. else
  12213. {
  12214. isSuccess = ConfigurationStatus_Rejected;
  12215. }
  12216. }
  12217. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  12218. {
  12219. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  12220. {
  12221. check_ascii = value[0];
  12222. if( (check_ascii < 48) || (check_ascii > 57) )
  12223. {
  12224. isSuccess = ConfigurationStatus_Rejected;
  12225. }
  12226. else
  12227. {
  12228. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12229. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  12230. isSuccess = ConfigurationStatus_Accepted;
  12231. }
  12232. }
  12233. else
  12234. {
  12235. isSuccess = ConfigurationStatus_Rejected;
  12236. }
  12237. }
  12238. if(strcmp(key, "MeterValuesSampledData") == 0 )
  12239. {
  12240. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  12241. {
  12242. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  12243. isSuccess = ConfigurationStatus_Accepted;
  12244. }
  12245. else
  12246. {
  12247. isSuccess = ConfigurationStatus_Rejected;
  12248. }
  12249. }
  12250. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  12251. {
  12252. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  12253. {
  12254. check_ascii = value[0];
  12255. if( (check_ascii < 48) || (check_ascii > 57) )
  12256. {
  12257. isSuccess = ConfigurationStatus_Rejected;
  12258. }
  12259. else
  12260. {
  12261. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12262. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  12263. isSuccess = ConfigurationStatus_Accepted;
  12264. }
  12265. }
  12266. else
  12267. {
  12268. isSuccess = ConfigurationStatus_Rejected;
  12269. }
  12270. }
  12271. if(strcmp(key, "MeterValueSampleInterval") == 0)
  12272. {
  12273. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12274. {
  12275. check_ascii = value[0];
  12276. if( (check_ascii < 48) || (check_ascii > 57) )
  12277. {
  12278. isSuccess = ConfigurationStatus_Rejected;
  12279. }
  12280. else
  12281. {
  12282. if((atoi(value) == 0) || (atoi(value) >= 10))
  12283. {
  12284. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12285. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  12286. isSuccess = ConfigurationStatus_Accepted;
  12287. }
  12288. else
  12289. {
  12290. isSuccess = ConfigurationStatus_Rejected;
  12291. }
  12292. }
  12293. }
  12294. else
  12295. {
  12296. isSuccess = ConfigurationStatus_Rejected;
  12297. }
  12298. }
  12299. if(strcmp(key, "MinimumStatusDuration") == 0)
  12300. {
  12301. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12302. {
  12303. check_ascii = value[0];
  12304. if( (check_ascii < 48) || (check_ascii > 57) )
  12305. {
  12306. isSuccess = ConfigurationStatus_Rejected;
  12307. }
  12308. else
  12309. {
  12310. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  12311. {
  12312. isSuccess = ConfigurationStatus_Rejected;
  12313. }
  12314. else
  12315. {
  12316. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  12317. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  12318. server_cycle_Status = atoi(value); //StatusNotification Cycle
  12319. isSuccess = ConfigurationStatus_Accepted;
  12320. }
  12321. }
  12322. }
  12323. else
  12324. {
  12325. isSuccess = ConfigurationStatus_Rejected;
  12326. }
  12327. }
  12328. if(strcmp(key, "NumberOfConnectors") == 0)
  12329. {
  12330. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12331. {
  12332. check_ascii = value[0];
  12333. if( (check_ascii < 48) || (check_ascii > 57) )
  12334. {
  12335. isSuccess = ConfigurationStatus_Rejected;
  12336. }
  12337. else
  12338. {
  12339. //Charger.ResetRetries = Integer.parseInt(value);
  12340. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  12341. isSuccess = ConfigurationStatus_Accepted;
  12342. }
  12343. }
  12344. else
  12345. {
  12346. isSuccess = ConfigurationStatus_Rejected;
  12347. }
  12348. }
  12349. if(strcmp(key, "ResetRetries") == 0)
  12350. {
  12351. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12352. {
  12353. check_ascii = value[0];
  12354. if( (check_ascii < 48) || (check_ascii > 57) )
  12355. {
  12356. isSuccess = ConfigurationStatus_Rejected;
  12357. }
  12358. else
  12359. {
  12360. //Charger.ResetRetries = Integer.parseInt(value);
  12361. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  12362. isSuccess = ConfigurationStatus_Accepted;
  12363. }
  12364. }
  12365. else
  12366. {
  12367. isSuccess = ConfigurationStatus_Rejected;
  12368. }
  12369. }
  12370. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  12371. {
  12372. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12373. {
  12374. strcpy(str, (const char*)value);
  12375. for(int i = 0; str[i]; i++)
  12376. {
  12377. str[i] = tolower(str[i]);
  12378. }
  12379. if(strcmp(str, "notapplicable")== 0)
  12380. {
  12381. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  12382. isSuccess = ConfigurationStatus_Accepted;
  12383. }
  12384. else if(strcmp(str, "unknown")== 0)
  12385. {
  12386. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  12387. isSuccess = ConfigurationStatus_Accepted;
  12388. }
  12389. else if(strcmp(str, "rst")== 0)
  12390. {
  12391. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  12392. isSuccess = ConfigurationStatus_Accepted;
  12393. }
  12394. else if(strcmp(str, "rts")== 0)
  12395. {
  12396. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  12397. isSuccess = ConfigurationStatus_Accepted;
  12398. }
  12399. else if(strcmp(str, "srt")== 0)
  12400. {
  12401. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  12402. isSuccess = ConfigurationStatus_Accepted;
  12403. }
  12404. else if(strcmp(str, "str")== 0)
  12405. {
  12406. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  12407. isSuccess = ConfigurationStatus_Accepted;
  12408. }
  12409. else if(strcmp(str, "trs")== 0)
  12410. {
  12411. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  12412. isSuccess = ConfigurationStatus_Accepted;
  12413. }
  12414. else if(strcmp(str, "tsr")== 0)
  12415. {
  12416. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  12417. isSuccess = ConfigurationStatus_Accepted;
  12418. }
  12419. else
  12420. {
  12421. isSuccess = ConfigurationStatus_Rejected;
  12422. }
  12423. }
  12424. else
  12425. {
  12426. isSuccess = ConfigurationStatus_Rejected;
  12427. }
  12428. }
  12429. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  12430. {
  12431. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].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[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  12441. isSuccess = ConfigurationStatus_Accepted;
  12442. }
  12443. }
  12444. else
  12445. {
  12446. isSuccess = ConfigurationStatus_Rejected;
  12447. }
  12448. }
  12449. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  12450. {
  12451. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12452. {
  12453. strcpy(str, (const char*)value);
  12454. for(int i = 0; str[i]; i++)
  12455. {
  12456. str[i] = tolower(str[i]);
  12457. }
  12458. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12459. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12460. isSuccess = ConfigurationStatus_Accepted;
  12461. }
  12462. else
  12463. {
  12464. isSuccess = ConfigurationStatus_Rejected;
  12465. }
  12466. }
  12467. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  12468. {
  12469. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12470. {
  12471. strcpy(str, (const char*)value);
  12472. for(int i = 0; str[i]; i++)
  12473. {
  12474. str[i] = tolower(str[i]);
  12475. }
  12476. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  12477. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12478. isSuccess = ConfigurationStatus_Accepted;
  12479. }
  12480. else
  12481. {
  12482. isSuccess = ConfigurationStatus_Rejected;
  12483. }
  12484. }
  12485. if(strcmp(key, "StopTxnAlignedData") == 0)
  12486. {
  12487. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12488. {
  12489. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  12490. isSuccess = ConfigurationStatus_Accepted;
  12491. }
  12492. else
  12493. {
  12494. isSuccess = ConfigurationStatus_Rejected;
  12495. }
  12496. }
  12497. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  12498. {
  12499. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12500. {
  12501. check_ascii = value[0];
  12502. if( (check_ascii < 48) || (check_ascii > 57) )
  12503. {
  12504. isSuccess = ConfigurationStatus_Rejected;
  12505. }
  12506. else
  12507. {
  12508. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  12509. isSuccess = ConfigurationStatus_Accepted;
  12510. }
  12511. }
  12512. else
  12513. {
  12514. isSuccess = ConfigurationStatus_Rejected;
  12515. }
  12516. }
  12517. if(strcmp(key, "StopTxnSampledData") == 0)
  12518. {
  12519. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12520. {
  12521. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  12522. isSuccess = ConfigurationStatus_Accepted;
  12523. }
  12524. else
  12525. {
  12526. isSuccess = ConfigurationStatus_Rejected;
  12527. }
  12528. }
  12529. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  12530. {
  12531. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12532. {
  12533. check_ascii = value[0];
  12534. if( (check_ascii < 48) || (check_ascii > 57) )
  12535. {
  12536. isSuccess = ConfigurationStatus_Rejected;
  12537. }
  12538. else
  12539. {
  12540. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  12541. isSuccess = ConfigurationStatus_Accepted;
  12542. }
  12543. }
  12544. else
  12545. {
  12546. isSuccess = ConfigurationStatus_Rejected;
  12547. }
  12548. }
  12549. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  12550. {
  12551. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12552. {
  12553. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  12554. isSuccess = ConfigurationStatus_Accepted;
  12555. }
  12556. else
  12557. {
  12558. isSuccess = ConfigurationStatus_Rejected;
  12559. }
  12560. }
  12561. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  12562. {
  12563. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12564. {
  12565. check_ascii = value[0];
  12566. if( (check_ascii < 48) || (check_ascii > 57) )
  12567. {
  12568. isSuccess = ConfigurationStatus_Rejected;
  12569. }
  12570. else
  12571. {
  12572. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  12573. isSuccess = ConfigurationStatus_Accepted;
  12574. }
  12575. }
  12576. else
  12577. {
  12578. isSuccess = ConfigurationStatus_Rejected;
  12579. }
  12580. }
  12581. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12582. {
  12583. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12584. {
  12585. check_ascii = value[0];
  12586. if( (check_ascii < 48) || (check_ascii > 57) )
  12587. {
  12588. isSuccess = ConfigurationStatus_Rejected;
  12589. }
  12590. else
  12591. {
  12592. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12593. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12594. TransactionMessageAttemptsValue = atoi(value);
  12595. isSuccess = ConfigurationStatus_Accepted;
  12596. }
  12597. }
  12598. else
  12599. {
  12600. isSuccess = ConfigurationStatus_Rejected;
  12601. }
  12602. }
  12603. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12604. {
  12605. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12606. {
  12607. check_ascii = value[0];
  12608. if( (check_ascii < 48) || (check_ascii > 57) )
  12609. {
  12610. isSuccess = ConfigurationStatus_Rejected;
  12611. }
  12612. else
  12613. {
  12614. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12615. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12616. TransactionMessageRetryIntervalValue = atoi(value);
  12617. isSuccess = ConfigurationStatus_Accepted;
  12618. }
  12619. }
  12620. else
  12621. {
  12622. isSuccess = ConfigurationStatus_Rejected;
  12623. }
  12624. }
  12625. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12626. {
  12627. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12628. {
  12629. strcpy(str, (const char*)value);
  12630. for(int i = 0; str[i]; i++)
  12631. {
  12632. str[i] = tolower(str[i]);
  12633. }
  12634. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12635. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12636. isSuccess = ConfigurationStatus_Accepted;
  12637. }
  12638. else
  12639. {
  12640. isSuccess = ConfigurationStatus_Rejected;
  12641. }
  12642. }
  12643. if(strcmp(key, "WebSocketPingInterval") == 0)
  12644. {
  12645. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12646. {
  12647. check_ascii = value[0];
  12648. if( (check_ascii < 48) || (check_ascii > 57) )
  12649. {
  12650. isSuccess = ConfigurationStatus_Rejected;
  12651. }
  12652. else
  12653. {
  12654. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12655. isSuccess = ConfigurationStatus_Accepted;
  12656. }
  12657. }
  12658. else
  12659. {
  12660. isSuccess = ConfigurationStatus_Rejected;
  12661. }
  12662. }
  12663. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  12664. {
  12665. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12666. {
  12667. strcpy(str, (const char*)value);
  12668. for(int i = 0; str[i]; i++)
  12669. {
  12670. str[i] = tolower(str[i]);
  12671. }
  12672. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12673. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12674. isSuccess = ConfigurationStatus_Accepted;
  12675. }
  12676. else
  12677. {
  12678. isSuccess = ConfigurationStatus_Rejected;
  12679. }
  12680. }
  12681. if(strcmp(key, "AuthorizationKey") == 0)
  12682. {
  12683. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  12684. {
  12685. strcpy(str, (const char*)value);
  12686. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  12687. isSuccess = ConfigurationStatus_Accepted;
  12688. }
  12689. else
  12690. {
  12691. isSuccess = ConfigurationStatus_Rejected;
  12692. }
  12693. }
  12694. if(strcmp(key, "SecurityProfile") == 0)
  12695. {
  12696. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  12697. {
  12698. check_ascii = value[0];
  12699. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  12700. {
  12701. isSuccess = ConfigurationStatus_Rejected;
  12702. }
  12703. else if(check_ascii == 0x33)
  12704. {
  12705. isSuccess = NotSupported;
  12706. }
  12707. else
  12708. {
  12709. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  12710. {
  12711. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  12712. isSuccess = ConfigurationStatus_Accepted;
  12713. }
  12714. else
  12715. isSuccess = ConfigurationStatus_Rejected;
  12716. }
  12717. }
  12718. else
  12719. {
  12720. isSuccess = ConfigurationStatus_Rejected;
  12721. }
  12722. }
  12723. if(strcmp(key, "DefaultPrice") == 0)
  12724. {
  12725. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  12726. {
  12727. strcpy(str, (const char*)value);
  12728. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  12729. isSuccess = ConfigurationStatus_Accepted;
  12730. }
  12731. else
  12732. {
  12733. isSuccess = ConfigurationStatus_Rejected;
  12734. }
  12735. }
  12736. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  12737. {
  12738. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  12739. {
  12740. strcpy(str, (const char*)value);
  12741. for(int i = 0; str[i]; i++)
  12742. {
  12743. str[i] = tolower(str[i]);
  12744. }
  12745. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12746. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12747. isSuccess = ConfigurationStatus_Accepted;
  12748. }
  12749. else
  12750. {
  12751. isSuccess = ConfigurationStatus_Rejected;
  12752. }
  12753. }
  12754. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  12755. {
  12756. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  12757. {
  12758. strcpy(str, (const char*)value);
  12759. for(int i = 0; str[i]; i++)
  12760. {
  12761. str[i] = tolower(str[i]);
  12762. }
  12763. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12764. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12765. isSuccess = ConfigurationStatus_Accepted;
  12766. }
  12767. else
  12768. {
  12769. isSuccess = ConfigurationStatus_Rejected;
  12770. }
  12771. }
  12772. #if 0
  12773. //For OCPP Test Case
  12774. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  12775. {
  12776. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12777. {
  12778. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  12779. isSuccess = ConfigurationStatus_Accepted;
  12780. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12781. }
  12782. else
  12783. {
  12784. isSuccess = ConfigurationStatus_Rejected;
  12785. }
  12786. }
  12787. #endif
  12788. #if 1
  12789. if(strcmp(key, "LocalAuthListEnabled") == 0)
  12790. {
  12791. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12792. {
  12793. strcpy(str, (const char*)value);
  12794. for(int i = 0; str[i]; i++)
  12795. {
  12796. str[i] = tolower(str[i]);
  12797. }
  12798. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12799. isSuccess = ConfigurationStatus_Accepted;
  12800. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12801. }
  12802. else
  12803. {
  12804. isSuccess = ConfigurationStatus_Rejected;
  12805. }
  12806. }
  12807. #endif
  12808. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12809. {
  12810. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12811. {
  12812. check_ascii = value[0];
  12813. if( (check_ascii < 48) || (check_ascii > 57) )
  12814. {
  12815. isSuccess = ConfigurationStatus_Rejected;
  12816. }
  12817. else
  12818. {
  12819. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12820. isSuccess = ConfigurationStatus_Accepted;
  12821. }
  12822. }
  12823. else
  12824. {
  12825. isSuccess = ConfigurationStatus_Rejected;
  12826. }
  12827. }
  12828. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12829. {
  12830. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12831. {
  12832. check_ascii = value[0];
  12833. if( (check_ascii < 48) || (check_ascii > 57) )
  12834. {
  12835. isSuccess = ConfigurationStatus_Rejected;
  12836. }
  12837. else
  12838. {
  12839. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12840. isSuccess = ConfigurationStatus_Accepted;
  12841. }
  12842. }
  12843. else
  12844. {
  12845. isSuccess = ConfigurationStatus_Rejected;
  12846. }
  12847. }
  12848. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12849. {
  12850. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12851. {
  12852. strcpy(str, (const char*)value);
  12853. for(int i = 0; str[i]; i++)
  12854. {
  12855. str[i] = tolower(str[i]);
  12856. }
  12857. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12858. isSuccess = ConfigurationStatus_Accepted;
  12859. }
  12860. else
  12861. {
  12862. isSuccess = ConfigurationStatus_Rejected;
  12863. }
  12864. }
  12865. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12866. {
  12867. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12868. {
  12869. check_ascii = value[0];
  12870. if( (check_ascii < 48) || (check_ascii > 57) )
  12871. {
  12872. isSuccess = ConfigurationStatus_Rejected;
  12873. }
  12874. else
  12875. {
  12876. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12877. isSuccess = ConfigurationStatus_Accepted;
  12878. }
  12879. }
  12880. else
  12881. {
  12882. isSuccess = ConfigurationStatus_Rejected;
  12883. }
  12884. }
  12885. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12886. {
  12887. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12888. {
  12889. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12890. isSuccess = ConfigurationStatus_Accepted;
  12891. }
  12892. else
  12893. {
  12894. isSuccess = ConfigurationStatus_Rejected;
  12895. }
  12896. }
  12897. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12898. {
  12899. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12900. {
  12901. check_ascii = value[0];
  12902. if( (check_ascii < 48) || (check_ascii > 57) )
  12903. {
  12904. isSuccess = ConfigurationStatus_Rejected;
  12905. }
  12906. else
  12907. {
  12908. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12909. isSuccess = ConfigurationStatus_Accepted;
  12910. }
  12911. }
  12912. else
  12913. {
  12914. isSuccess = ConfigurationStatus_Rejected;
  12915. }
  12916. }
  12917. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12918. {
  12919. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12920. {
  12921. strcpy(str, (const char*)value);
  12922. for(int i = 0; str[i]; i++)
  12923. {
  12924. str[i] = tolower(str[i]);
  12925. }
  12926. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12927. isSuccess = ConfigurationStatus_Accepted;
  12928. }
  12929. else
  12930. {
  12931. isSuccess = ConfigurationStatus_Rejected;
  12932. }
  12933. }
  12934. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12935. {
  12936. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12937. {
  12938. check_ascii = value[0];
  12939. if( (check_ascii < 48) || (check_ascii > 57) )
  12940. {
  12941. isSuccess = ConfigurationStatus_Rejected;
  12942. }
  12943. else
  12944. {
  12945. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12946. isSuccess = ConfigurationStatus_Accepted;
  12947. }
  12948. }
  12949. else
  12950. {
  12951. isSuccess = ConfigurationStatus_Rejected;
  12952. }
  12953. }
  12954. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12955. return isSuccess;
  12956. }
  12957. int TransactionMessageAttemptsGet(void)
  12958. {
  12959. return TransactionMessageAttemptsValue;
  12960. }
  12961. int FirstHeartBeatResponse(void)
  12962. {
  12963. return FirstHeartBeat;
  12964. }
  12965. int TransactionMessageRetryIntervalGet(void)
  12966. {
  12967. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12968. }
  12969. int ReadHttpStatus(int sock)
  12970. {
  12971. //char c;
  12972. char buff[1024]="",*ptr=buff+1;
  12973. int bytes_received, status;
  12974. DEBUG_INFO("Begin Response ..\n");
  12975. while((bytes_received = recv(sock, ptr, 1, 0))){
  12976. if(bytes_received==-1){
  12977. perror("ReadHttpStatus");
  12978. exit(1);
  12979. }
  12980. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  12981. ptr++;
  12982. }
  12983. *ptr=0;
  12984. ptr=buff+1;
  12985. sscanf(ptr,"%*s %d ", &status);
  12986. DEBUG_INFO("%s\n",ptr);
  12987. DEBUG_INFO("status=%d\n",status);
  12988. DEBUG_INFO("End Response ..\n");
  12989. return (bytes_received>0)?status:0;
  12990. }
  12991. //the only filed that it parsed is 'Content-Length'
  12992. int ParseHeader(int sock)
  12993. {
  12994. //char c;
  12995. char buff[1024]="",*ptr=buff+4;
  12996. int bytes_received;
  12997. DEBUG_INFO("Begin HEADER ..\n");
  12998. while((bytes_received = recv(sock, ptr, 1, 0))){
  12999. if(bytes_received==-1){
  13000. perror("Parse Header");
  13001. exit(1);
  13002. }
  13003. if(
  13004. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  13005. (ptr[-1]=='\r') && (*ptr=='\n' )
  13006. ) break;
  13007. ptr++;
  13008. }
  13009. *ptr=0;
  13010. ptr=buff+4;
  13011. //printf("%s",ptr);
  13012. if(bytes_received){
  13013. ptr=strstr(ptr,"Content-Length:");
  13014. if(ptr){
  13015. sscanf(ptr,"%*s %d",&bytes_received);
  13016. }else
  13017. bytes_received=-1; //unknown size
  13018. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  13019. }
  13020. DEBUG_INFO("End HEADER ..\n");
  13021. return bytes_received ;
  13022. }
  13023. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  13024. {
  13025. char rmFileCmd[100]={0};
  13026. char FilePath[100]={0};
  13027. char ftpbuf[200];
  13028. int systemresult;
  13029. //DEBUG_INFO("filename=%s\n",filename);
  13030. //DEBUG_INFO("url=%s\n",url);
  13031. sprintf(FilePath,"/mnt/%s",filename);
  13032. system("ping 8.8.8.8 &");
  13033. if((access(FilePath,F_OK))!=-1)
  13034. {
  13035. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13036. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13037. system(rmFileCmd);
  13038. }
  13039. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13040. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  13041. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13042. systemresult = system(ftpbuf);
  13043. //DEBUG_INFO("systemresult=%d\n",systemresult);
  13044. if(systemresult != 0)
  13045. {
  13046. DEBUG_INFO("http DownLoad error!\n");
  13047. return FALSE;
  13048. }
  13049. system("pkill ping");
  13050. return TRUE;
  13051. }
  13052. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  13053. {
  13054. char rmFileCmd[100]={0};
  13055. char FilePath[100]={0};
  13056. char ftpbuf[200];
  13057. int systemresult;
  13058. //char temp[100];
  13059. sprintf(FilePath,"/mnt/%s",filename);
  13060. system("ping 8.8.8.8 &");
  13061. if((access(FilePath,F_OK))!=-1)
  13062. {
  13063. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13064. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13065. system(rmFileCmd);
  13066. }
  13067. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13068. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  13069. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  13070. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  13071. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13072. systemresult = system(ftpbuf);
  13073. //DEBUG_INFO("systemresult=%d\n",systemresult);
  13074. if(systemresult != 0)
  13075. {
  13076. printf("wget error!\n");
  13077. return FALSE;
  13078. }
  13079. system("pkill ping");
  13080. return TRUE;
  13081. }
  13082. int httpUploadFile(char *location, char *path, char *filename,char *url)
  13083. {
  13084. char rmFileCmd[100]={0};
  13085. char FilePath[100]={0};
  13086. char ftpbuf[200];
  13087. int systemresult;
  13088. //DEBUG_INFO("filename=%s\n",filename);
  13089. //DEBUG_INFO("url=%s\n",url);
  13090. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  13091. if((access(FilePath,F_OK))!=-1)
  13092. {
  13093. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13094. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13095. system(rmFileCmd);
  13096. }
  13097. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  13098. if(fp == NULL)
  13099. {
  13100. DEBUG_INFO("log is NULL\n");
  13101. return FALSE;
  13102. }
  13103. else
  13104. {
  13105. fprintf(fp, "%s\n", url);
  13106. fprintf(fp, "%s\n", filename);
  13107. fclose(fp);
  13108. }
  13109. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13110. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  13111. systemresult = system(ftpbuf);
  13112. DEBUG_INFO("systemresult = %d\n",systemresult);
  13113. if(systemresult != 0)
  13114. {
  13115. DEBUG_INFO("http upload error!\n");
  13116. return FALSE;
  13117. }
  13118. return TRUE;
  13119. }
  13120. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  13121. {
  13122. struct hostent* server;
  13123. char *IPbuffer;
  13124. char ftpbuf[200];
  13125. int systemresult;
  13126. // To retrieve host information
  13127. server = gethostbyname(location);
  13128. // To convert an Internet network
  13129. // address into ASCII string
  13130. IPbuffer = inet_ntoa(*((struct in_addr*)
  13131. server->h_addr_list[0]));
  13132. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13133. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  13134. /* format : ftpput -u username -p passwd IP target source*/
  13135. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  13136. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  13137. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13138. systemresult = system(ftpbuf);
  13139. DEBUG_INFO("systemresult=%d\n",systemresult);
  13140. if(systemresult != 0)
  13141. {
  13142. DEBUG_INFO("ftpput error!\n");
  13143. return FALSE;
  13144. }
  13145. return TRUE;
  13146. }
  13147. /**
  13148. * Place the contents of the specified file into a memory buffer
  13149. *
  13150. * @param[in] filename The path and name of the file to read
  13151. * @param[out] filebuffer A pointer to the contents in memory
  13152. * @return status 0 success, 1 on failure
  13153. */
  13154. int get_file_contents(const char* filename, char** outbuffer) {
  13155. FILE* file = NULL;
  13156. long filesize;
  13157. const int blocksize = 1;
  13158. size_t readsize;
  13159. char* filebuffer;
  13160. // Open the file
  13161. file = fopen(filename, "r");
  13162. if (NULL == file)
  13163. {
  13164. printf("'%s' not opened\n", filename);
  13165. exit(EXIT_FAILURE);
  13166. }
  13167. // Determine the file size
  13168. fseek(file, 0, SEEK_END);
  13169. filesize = ftell(file);
  13170. rewind (file);
  13171. // Allocate memory for the file contents
  13172. filebuffer = (char*) malloc(sizeof(char) * filesize);
  13173. *outbuffer = filebuffer;
  13174. if (filebuffer == NULL)
  13175. {
  13176. fputs ("malloc out-of-memory", stderr);
  13177. exit(EXIT_FAILURE);
  13178. }
  13179. // Read in the file
  13180. readsize = fread(filebuffer, blocksize, filesize, file);
  13181. if (readsize != filesize)
  13182. {
  13183. fputs ("didn't read file completely",stderr);
  13184. exit(EXIT_FAILURE);
  13185. }
  13186. // Clean exit
  13187. fclose(file);
  13188. return EXIT_SUCCESS;
  13189. }
  13190. static int selectSqlCount = 0;
  13191. static int callback(void *data, int argc, char **argv, char **azColName){
  13192. int i;
  13193. //printf("%s: ", (const char*)data);
  13194. selectSqlCount = argc;
  13195. for(i = 0; i<argc; i++){
  13196. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  13197. }
  13198. //printf("\n");
  13199. return 0;
  13200. }
  13201. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  13202. //int i;
  13203. //printf("%s:\n", (const char*)data);
  13204. localversion = argv[5] ? atoi(argv[5]) : 0;
  13205. //printf("localversion=%d\n", localversion);
  13206. return 0;
  13207. }
  13208. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  13209. //printf("%s:\n", (const char*)data);
  13210. //idTag
  13211. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  13212. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  13213. //parentIdTag
  13214. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  13215. //expir_date
  13216. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  13217. //status
  13218. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  13219. //version
  13220. if(columenCount > 5)
  13221. idTagQuery.listVersionInt = atoi(columnValue[5]);
  13222. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  13223. return 0;
  13224. }
  13225. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  13226. {
  13227. // localversion = argv[5] ? atoi(argv[5]) : 0;
  13228. // printf("localversion=%d\n", localversion);
  13229. return 0;
  13230. }
  13231. //=========================================
  13232. // Sqlite3 related function
  13233. //=========================================
  13234. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  13235. {
  13236. for (int i = 0; i < n_columns; i++)
  13237. {
  13238. DEBUG_INFO("%s\t", col_values[i]);
  13239. }
  13240. DEBUG_INFO("\n");
  13241. return 0;
  13242. }
  13243. int OCPP_cleanLocalCache()
  13244. {
  13245. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  13246. char *errMsg = 0;
  13247. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  13248. if (SQLITE_OK != rc)
  13249. {
  13250. DEBUG_INFO("SQL error: %s\n",errMsg);
  13251. return FALSE;
  13252. }
  13253. return TRUE;
  13254. }
  13255. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  13256. {
  13257. int isSuccess = TRUE;
  13258. int ret = 0;
  13259. //const char* data = "Callback function called";
  13260. char sql[300];
  13261. char zErrMsg[200];
  13262. memset(sql, 0, 300);
  13263. memset(zErrMsg, 0, 200);
  13264. 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);
  13265. //* Execute SQL statement */
  13266. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  13267. if( ret != SQLITE_OK )
  13268. {
  13269. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13270. isSuccess = FALSE;
  13271. }
  13272. return isSuccess;
  13273. }
  13274. void OCPP_getIdTagFromLocalCache(char idTag[])
  13275. {
  13276. int rc = 0;
  13277. char sql[100];
  13278. char zErrMsg[100];
  13279. memset(sql, 0, 100);
  13280. memset(zErrMsg, 0, 100);
  13281. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  13282. memset(&idTagQuery, 0, sizeof(idTagQuery));
  13283. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  13284. /* Execute SQL statement */
  13285. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  13286. if( rc != SQLITE_OK )
  13287. {
  13288. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13289. }
  13290. }
  13291. void OCPP_getListVerion()
  13292. {
  13293. int rc = 0;
  13294. // const char* data = "Callback function called";
  13295. char sql[100];
  13296. char zErrMsg[100];
  13297. memset(sql, 0, 100);
  13298. memset(zErrMsg, 0, 100);
  13299. strcpy(sql, "select * from ocpp_auth_local order by idx");
  13300. /* Execute SQL statement */
  13301. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  13302. if( rc != SQLITE_OK )
  13303. {
  13304. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13305. }
  13306. }
  13307. void OCPP_get_TableAuthlocalAllData(void)
  13308. {
  13309. int rc = 0;
  13310. char sql[100];
  13311. char zErrMsg[100];
  13312. memset(sql, 0, 100);
  13313. memset(zErrMsg, 0, 100);
  13314. sprintf(sql,"select * from ocpp_auth_local ");
  13315. /* Execute SQL statement */
  13316. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  13317. if( rc != SQLITE_OK )
  13318. {
  13319. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13320. }
  13321. //return ver;
  13322. }
  13323. int OCPP_cleanLocalList()
  13324. {
  13325. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  13326. char *errMsg = 0;
  13327. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  13328. if (SQLITE_OK != rc)
  13329. {
  13330. DEBUG_INFO("%s\n",errMsg);
  13331. return FALSE;
  13332. }
  13333. return TRUE;
  13334. }
  13335. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  13336. {
  13337. int isSuccess = FALSE;
  13338. int ret = 0;
  13339. //const char* data = "Callback function called";
  13340. char sql[300];
  13341. char zErrMsg[200];
  13342. memset(sql, 0, 300);
  13343. memset(zErrMsg, 0, 200);
  13344. 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);
  13345. //* Execute SQL statement */
  13346. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  13347. if( ret != SQLITE_OK )
  13348. {
  13349. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13350. return isSuccess;
  13351. }
  13352. memset(sql, 0, 300);
  13353. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  13354. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  13355. if( ret != SQLITE_OK )
  13356. {
  13357. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13358. return isSuccess;
  13359. }
  13360. isSuccess = TRUE;
  13361. return isSuccess;
  13362. }
  13363. void OCPP_getIdTagFromLocalList(char idTag[])
  13364. {
  13365. int rc = 0;
  13366. // const char* data = "Callback function called";
  13367. char sql[100];
  13368. char zErrMsg[100];
  13369. memset(sql, 0, 100);
  13370. memset(zErrMsg, 0, 100);
  13371. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  13372. memset(&idTagQuery, 0, sizeof(idTagQuery));
  13373. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  13374. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  13375. /* Execute SQL statement */
  13376. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  13377. if( rc != SQLITE_OK )
  13378. {
  13379. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13380. }
  13381. //return ver;
  13382. }
  13383. void OCPP_deleteIdTagFromLocalList(char idTag[])
  13384. {
  13385. //int ver = 0;
  13386. //int isSuccess = FALSE;
  13387. int rc = 0;
  13388. char sql[100];
  13389. char zErrMsg[100];
  13390. memset(sql, 0, 100);
  13391. memset(zErrMsg, 0, 100);
  13392. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  13393. //* Execute SQL statement */
  13394. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  13395. if( rc != SQLITE_OK )
  13396. {
  13397. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13398. }
  13399. }
  13400. int GetOcppServerURL()
  13401. {
  13402. int result = FALSE;
  13403. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  13404. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  13405. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  13406. struct yuarel url;
  13407. char urlStr[512];
  13408. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  13409. {
  13410. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  13411. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13412. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  13413. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  13414. if(yuarel_parse(&url, urlStr) != -1)
  13415. {
  13416. sprintf(OcppProtocol, "%s", url.scheme);
  13417. sprintf(OcppHost, "%s", url.host);
  13418. if(url.path == NULL)
  13419. OcppTempPath[0] = '\0';
  13420. else
  13421. {
  13422. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  13423. {
  13424. sprintf(OcppTempPath, "%s/", url.path);
  13425. }
  13426. else
  13427. {
  13428. sprintf(OcppTempPath, "%s", url.path);
  13429. }
  13430. }
  13431. if(url.port == 0)
  13432. {
  13433. if(strcmp(OcppProtocol, "wss") == 0)
  13434. OcppPort = 443;
  13435. else
  13436. OcppPort = 80;
  13437. }
  13438. else
  13439. OcppPort = url.port;
  13440. result = TRUE;
  13441. }
  13442. }
  13443. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  13444. {
  13445. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  13446. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13447. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  13448. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  13449. if(yuarel_parse(&url, urlStr) != -1)
  13450. {
  13451. sprintf(OcppProtocol, "%s", url.scheme);
  13452. sprintf(OcppHost, "%s", url.host);
  13453. if(url.path == NULL)
  13454. OcppTempPath[0] = '\0';
  13455. else
  13456. sprintf(OcppTempPath, "%s", url.path);
  13457. if(url.port == 0)
  13458. {
  13459. if(strcmp(OcppProtocol, "wss") == 0)
  13460. OcppPort = 443;
  13461. else
  13462. OcppPort = 80;
  13463. }
  13464. else
  13465. OcppPort = url.port;
  13466. result = TRUE;
  13467. }
  13468. }
  13469. else
  13470. {
  13471. strcpy(OcppHost,"");
  13472. }
  13473. return result;
  13474. }
  13475. int GetOcppPath()
  13476. {
  13477. int result = FALSE;
  13478. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  13479. {
  13480. if(OcppTempPath == NULL)
  13481. {
  13482. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13483. }
  13484. else
  13485. {
  13486. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13487. }
  13488. result = TRUE;
  13489. goto End;
  13490. }
  13491. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  13492. {
  13493. if(OcppTempPath == NULL)
  13494. {
  13495. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  13496. }
  13497. else
  13498. {
  13499. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  13500. }
  13501. result = TRUE;
  13502. goto End;
  13503. }
  13504. else
  13505. {
  13506. strcpy(OcppPath,"");
  13507. }
  13508. End:
  13509. return result;
  13510. }
  13511. int GetOcppPort()
  13512. {
  13513. return OcppPort;
  13514. }
  13515. int GetOcppConnStatus(void)
  13516. {
  13517. return ShmOCPP16Data->OcppConnStatus;
  13518. }
  13519. void SetOcppConnStatus(uint8_t status)
  13520. {
  13521. ShmOCPP16Data->OcppConnStatus = status;
  13522. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  13523. }
  13524. int GetHeartBeatWithNOResponse(void)
  13525. {
  13526. return HeartBeatWithNOResponse;
  13527. }
  13528. void SetHeartBeatWithNOResponse(void)
  13529. {
  13530. HeartBeatWithNOResponse = 0;
  13531. }
  13532. void GetStartTransactionIdTag(int gun_index)
  13533. {
  13534. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  13535. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13536. }
  13537. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  13538. {
  13539. char ch;
  13540. FILE *fptr1;
  13541. int temptransactionId;
  13542. char str[100]={0};
  13543. temptransactionId = 0;
  13544. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  13545. {
  13546. DEBUG_INFO("IdTag is empty.\n");
  13547. return temptransactionId;
  13548. }
  13549. /*------ Read the file ----------------*/
  13550. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  13551. if (!fptr1)
  13552. {
  13553. DEBUG_INFO("QueueTransactionId file open error.\n");
  13554. //printf(" File not found or unable to open the input file!!\n");
  13555. return temptransactionId;
  13556. }
  13557. ch=fgetc(fptr1);
  13558. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  13559. rewind(fptr1);
  13560. if(ch!=EOF)
  13561. {
  13562. // printf("%c",ch);
  13563. while (fgets(str, 100, fptr1) != NULL)
  13564. {
  13565. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13566. if(str[0]=='\0')
  13567. {
  13568. break;
  13569. }
  13570. char *revbuf[8] = {0}; // Variable store string split
  13571. int num = 0;// Quantity after string split
  13572. DEBUG_INFO("Transaction queue data= %s\n", str);
  13573. splitstring(str,",",revbuf,&num); // String split
  13574. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  13575. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  13576. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  13577. DEBUG_INFO("------------------------------\n");
  13578. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  13579. {
  13580. if(isStopTransaction)
  13581. {
  13582. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  13583. {
  13584. temptransactionId = atoi(revbuf[2]);
  13585. //break;
  13586. }
  13587. }
  13588. else
  13589. {
  13590. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  13591. {
  13592. temptransactionId = atoi(revbuf[2]);
  13593. //break;
  13594. }
  13595. }
  13596. }
  13597. }
  13598. }
  13599. else
  13600. DEBUG_INFO("EOF\n");
  13601. fclose(fptr1);
  13602. /*------- End of reading ---------------*/
  13603. return temptransactionId;
  13604. }
  13605. void SetTransactionIdZero(int transactionId)
  13606. {
  13607. char ch;
  13608. FILE *fptr1, *fptr2;
  13609. int temptransactionId = 0;
  13610. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  13611. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  13612. if (!fptr1)
  13613. {
  13614. //printf(" File not found or unable to open the input file!!\n");
  13615. return ;
  13616. }
  13617. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13618. if (!fptr2)
  13619. {
  13620. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  13621. fclose(fptr1);
  13622. return ;
  13623. }
  13624. ch=fgetc(fptr1);
  13625. rewind(fptr1);
  13626. if(ch!=EOF)
  13627. {
  13628. // copy all contents to the temporary file except the specific line
  13629. while (fgets(str, 100, fptr1) != NULL)
  13630. {
  13631. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13632. if(str[0]=='\0')
  13633. {
  13634. break;
  13635. }
  13636. char *revbuf[8] = {0};
  13637. int num = 0;
  13638. strcpy(strtemp, str);
  13639. splitstring(str,",",revbuf,&num);
  13640. if(revbuf[2][0] != '\0')
  13641. {
  13642. temptransactionId = atoi(revbuf[2]);
  13643. if(transactionId != temptransactionId)
  13644. {
  13645. fprintf(fptr2, "%s\n", strtemp);
  13646. }
  13647. }
  13648. }
  13649. }
  13650. fclose(fptr1);
  13651. fclose(fptr2);
  13652. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13653. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13654. /*------ Read the file ----------------*/
  13655. }
  13656. int InternetDisconnect(void)
  13657. {
  13658. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13659. }
  13660. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  13661. void storeTempStopTransaction(int gun_index)
  13662. {
  13663. char guid[37]={0};
  13664. int tempIndex = 0;
  13665. char TempStopTransaction[256];
  13666. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  13667. DEBUG_INFO("storeTempStopTransaction...\n");
  13668. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  13669. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  13670. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  13671. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13672. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  13673. {
  13674. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13675. {
  13676. tempIndex = ((gun_index==2) ? 1: 0);
  13677. }
  13678. else
  13679. {
  13680. tempIndex = gun_index;
  13681. }
  13682. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13683. {
  13684. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13685. {
  13686. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  13687. }
  13688. }// END OF CHAdeMO_QUANTITY
  13689. }
  13690. else if(gunType[gun_index] == GUN_TYPE_CCS)
  13691. {
  13692. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13693. {
  13694. tempIndex = ((gun_index==2) ? 1: 0);
  13695. }
  13696. else
  13697. {
  13698. tempIndex = gun_index;
  13699. }
  13700. for (int index = 0; index < CCS_QUANTITY; index++)
  13701. {
  13702. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13703. {
  13704. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  13705. }
  13706. }// END OF CCS_QUANTITY
  13707. }
  13708. else if(gunType[gun_index] == GUN_TYPE_GBT)
  13709. {
  13710. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13711. {
  13712. tempIndex = ((gun_index==2) ? 1: 0);
  13713. }
  13714. else
  13715. {
  13716. tempIndex = gun_index;
  13717. }
  13718. for (int index = 0; index < GB_QUANTITY; index++)
  13719. {
  13720. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13721. {
  13722. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  13723. }
  13724. }// END OF GB_QUANTITY
  13725. }
  13726. else if(gunType[gun_index] == GUN_TYPE_DO)
  13727. {
  13728. tempIndex = gun_index;
  13729. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13730. {
  13731. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13732. {
  13733. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  13734. }
  13735. }
  13736. }
  13737. else
  13738. {
  13739. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13740. {
  13741. tempIndex = 2;
  13742. }
  13743. else
  13744. {
  13745. tempIndex = gun_index;
  13746. }
  13747. for (int index = 0; index < AC_QUANTITY; index++)
  13748. {
  13749. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13750. {
  13751. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  13752. }
  13753. }// END OF AC_QUANTITY
  13754. }
  13755. //Stop Transaction Time
  13756. struct timeval tmnow;
  13757. struct tm *tm;
  13758. char buf[28];//, usec_buf[6];
  13759. gettimeofday(&tmnow, NULL);
  13760. time_t t;
  13761. t = time(NULL);
  13762. /*UTC time and date*/
  13763. tm = gmtime(&t);
  13764. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  13765. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  13766. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  13767. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13768. random_uuid(guid);
  13769. /***********************************transactionData******************************************************/
  13770. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  13771. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  13772. //=================================
  13773. //1. Transaction_Begin
  13774. //=================================
  13775. //============================== Energy.Active.Import.Interval ===========================================
  13776. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  13777. {
  13778. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  13779. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  13780. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  13781. 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*/]);
  13782. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13783. 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))
  13784. {
  13785. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  13786. }
  13787. else
  13788. {
  13789. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  13790. }
  13791. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  13792. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13793. }
  13794. //=================================
  13795. //2. Transaction_End
  13796. //=================================
  13797. //2.1====================================== Current.Import L1 ==============================================
  13798. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  13799. {
  13800. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  13801. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  13802. {
  13803. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13804. {
  13805. tempIndex = ((gun_index==2) ? 1: 0);
  13806. }
  13807. else
  13808. {
  13809. tempIndex = gun_index;
  13810. }
  13811. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13812. {
  13813. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13814. {
  13815. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13816. }
  13817. }// End of for CHAdeMO_QUANTITY
  13818. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13819. }
  13820. else if(gunType[gun_index] == GUN_TYPE_CCS)
  13821. {
  13822. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13823. {
  13824. tempIndex = ((gun_index==2) ? 1: 0);
  13825. }
  13826. else
  13827. {
  13828. tempIndex = gun_index;
  13829. }
  13830. for (int index = 0; index < CCS_QUANTITY; index++)
  13831. {
  13832. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13833. {
  13834. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13835. }
  13836. }// End of for CCS_QUANTITY
  13837. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13838. }
  13839. else if(gunType[gun_index] == GUN_TYPE_GBT)
  13840. {
  13841. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13842. {
  13843. tempIndex = ((gun_index==2) ? 1: 0);
  13844. }
  13845. else
  13846. {
  13847. tempIndex = gun_index;
  13848. }
  13849. for (int index = 0; index < GB_QUANTITY; index++)
  13850. {
  13851. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13852. {
  13853. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13854. }
  13855. }// End of for GB_QUANTITY
  13856. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13857. }
  13858. else if(gunType[gun_index] == GUN_TYPE_DO)
  13859. {
  13860. tempIndex = gun_index;
  13861. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13862. {
  13863. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13864. {
  13865. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13866. }
  13867. }
  13868. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13869. }
  13870. else
  13871. {
  13872. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13873. {
  13874. tempIndex = 2;
  13875. }
  13876. else
  13877. {
  13878. tempIndex = gun_index;
  13879. }
  13880. for (int index = 0; index < AC_QUANTITY; index++)
  13881. {
  13882. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13883. {
  13884. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  13885. }
  13886. }// End of for AC_QUANTITY
  13887. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13888. }
  13889. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13890. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  13891. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  13892. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13893. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  13894. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13895. }
  13896. //2.2===================================== Energy.Active.Import.Interval ==========================================
  13897. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  13898. {
  13899. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13900. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  13901. {
  13902. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13903. {
  13904. tempIndex = ((gun_index==2) ? 1: 0);
  13905. }
  13906. else
  13907. {
  13908. tempIndex = gun_index;
  13909. }
  13910. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13911. {
  13912. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13913. {
  13914. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13915. }
  13916. }// END OF CHAdeMO_QUANTITY
  13917. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13918. }
  13919. else if(gunType[gun_index] == GUN_TYPE_CCS)
  13920. {
  13921. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13922. {
  13923. tempIndex = ((gun_index==2) ? 1: 0);
  13924. }
  13925. else
  13926. {
  13927. tempIndex = gun_index;
  13928. }
  13929. for (int index = 0; index < CCS_QUANTITY; index++)
  13930. {
  13931. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13932. {
  13933. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13934. }
  13935. }// END OF CCS_QUANTITY
  13936. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13937. }
  13938. else if(gunType[gun_index] == GUN_TYPE_GBT)
  13939. {
  13940. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13941. {
  13942. tempIndex = ((gun_index==2) ? 1: 0);
  13943. }
  13944. else
  13945. {
  13946. tempIndex = gun_index;
  13947. }
  13948. for (int index = 0; index < GB_QUANTITY; index++)
  13949. {
  13950. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13951. {
  13952. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13953. }
  13954. }// END OF GB_QUANTITY
  13955. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13956. }
  13957. else if(gunType[gun_index] == GUN_TYPE_DO)
  13958. {
  13959. tempIndex = gun_index;
  13960. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13961. {
  13962. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13963. {
  13964. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13965. }
  13966. }
  13967. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13968. }
  13969. else
  13970. {
  13971. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13972. {
  13973. tempIndex = 2;
  13974. }
  13975. else
  13976. {
  13977. tempIndex = gun_index;
  13978. }
  13979. for (int index = 0; index < AC_QUANTITY; index++)
  13980. {
  13981. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13982. {
  13983. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13984. }
  13985. }// END OF AC_QUANTITY
  13986. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13987. }
  13988. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13989. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  13990. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  13991. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13992. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  13993. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13994. }
  13995. //2.3====================================== Power.Active.Import =========================================
  13996. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  13997. {
  13998. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13999. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14000. {
  14001. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14002. {
  14003. tempIndex = ((gun_index==2) ? 1: 0);
  14004. }
  14005. else
  14006. {
  14007. tempIndex = gun_index;
  14008. }
  14009. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14010. {
  14011. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14012. {
  14013. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14014. }
  14015. } // End for CHAdeMO_QUANTITY
  14016. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14017. }
  14018. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14019. {
  14020. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14021. {
  14022. tempIndex = ((gun_index==2) ? 1: 0);
  14023. }
  14024. else
  14025. {
  14026. tempIndex = gun_index;
  14027. }
  14028. for (int index = 0; index < CCS_QUANTITY; index++)
  14029. {
  14030. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14031. {
  14032. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14033. }
  14034. } // END for CCS_QUANTITY
  14035. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14036. }
  14037. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14038. {
  14039. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14040. {
  14041. tempIndex = ((gun_index==2) ? 1: 0);
  14042. }
  14043. else
  14044. {
  14045. tempIndex = gun_index;
  14046. }
  14047. for (int index = 0; index < GB_QUANTITY; index++)
  14048. {
  14049. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14050. {
  14051. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14052. }
  14053. }// END for GB_QUANTITY
  14054. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14055. }
  14056. else if(gunType[gun_index] == GUN_TYPE_DO)
  14057. {
  14058. tempIndex = gun_index;
  14059. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14060. {
  14061. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14062. {
  14063. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14064. }
  14065. }
  14066. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14067. }
  14068. else
  14069. {
  14070. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14071. {
  14072. tempIndex = 2;
  14073. }
  14074. else
  14075. {
  14076. tempIndex = gun_index;
  14077. }
  14078. for (int index = 0; index < AC_QUANTITY; index++)
  14079. {
  14080. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14081. {
  14082. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14083. }
  14084. } // END for AC_QUANTITY
  14085. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  14086. }
  14087. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14088. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  14089. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  14090. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  14091. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  14092. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  14093. }
  14094. //2.4====================================== Voltage L1 ====================================================
  14095. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  14096. {
  14097. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14098. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14099. {
  14100. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14101. {
  14102. tempIndex = ((gun_index==2) ? 1: 0);
  14103. }
  14104. else
  14105. {
  14106. tempIndex = gun_index;
  14107. }
  14108. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14109. {
  14110. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14111. {
  14112. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14113. }
  14114. } // END OF FOR CHAdeMO_QUANTITY
  14115. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14116. }
  14117. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14118. {
  14119. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14120. {
  14121. tempIndex = ((gun_index==2) ? 1: 0);
  14122. }
  14123. else
  14124. {
  14125. tempIndex = gun_index;
  14126. }
  14127. for (int index = 0; index < CCS_QUANTITY; index++)
  14128. {
  14129. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14130. {
  14131. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14132. }
  14133. } // END OF FOR CCS_QUANTITY
  14134. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14135. }
  14136. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14137. {
  14138. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14139. {
  14140. tempIndex = ((gun_index==2) ? 1: 0);
  14141. }
  14142. else
  14143. {
  14144. tempIndex = gun_index;
  14145. }
  14146. for (int index = 0; index < GB_QUANTITY; index++)
  14147. {
  14148. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14149. {
  14150. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14151. }
  14152. } // END OF FOR GB_QUANTITY
  14153. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14154. }
  14155. else if(gunType[gun_index] == GUN_TYPE_DO)
  14156. {
  14157. tempIndex = gun_index;
  14158. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14159. {
  14160. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14161. {
  14162. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14163. }
  14164. }
  14165. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14166. }
  14167. else
  14168. {
  14169. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14170. {
  14171. tempIndex = 2;
  14172. }
  14173. else
  14174. {
  14175. tempIndex = gun_index;
  14176. }
  14177. for (int index = 0; index < AC_QUANTITY; index++)
  14178. {
  14179. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14180. {
  14181. 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
  14182. }
  14183. } // END OF FOR AC_QUANTITY
  14184. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  14185. }
  14186. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14187. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  14188. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  14189. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  14190. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  14191. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  14192. }
  14193. //2.5============================================== End SoC =========================================================
  14194. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  14195. {
  14196. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14197. 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))
  14198. {
  14199. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  14200. {
  14201. tempIndex = ((gun_index==2) ? 1: 0);
  14202. }
  14203. else
  14204. {
  14205. tempIndex = gun_index;
  14206. }
  14207. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14208. {
  14209. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14210. {
  14211. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14212. {
  14213. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  14214. }
  14215. }
  14216. }
  14217. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14218. {
  14219. for (int index = 0; index < CCS_QUANTITY; index++)
  14220. {
  14221. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14222. {
  14223. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  14224. }
  14225. }
  14226. }
  14227. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14228. {
  14229. for (int index = 0; index < GB_QUANTITY; index++)
  14230. {
  14231. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14232. {
  14233. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  14234. }
  14235. }
  14236. }
  14237. else if(gunType[gun_index] == GUN_TYPE_DO)
  14238. {
  14239. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14240. {
  14241. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14242. {
  14243. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  14244. }
  14245. }
  14246. }
  14247. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14248. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  14249. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  14250. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  14251. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  14252. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  14253. } // END FOR DC CASE
  14254. }
  14255. //2.6====================================== Current.Import L2 ==============================================
  14256. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  14257. {
  14258. // AC 3 phase L2 current
  14259. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  14260. {
  14261. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14262. {
  14263. tempIndex = 2;
  14264. }
  14265. else
  14266. {
  14267. tempIndex = gun_index;
  14268. }
  14269. for (int index = 0; index < AC_QUANTITY; index++)
  14270. {
  14271. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14272. {
  14273. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  14274. }
  14275. }// End of for AC_QUANTITY
  14276. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  14277. }
  14278. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14279. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  14280. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  14281. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  14282. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14283. }
  14284. //2.7====================================== Current.Import L3 ==============================================
  14285. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  14286. {
  14287. // AC 3 phase L3 current
  14288. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  14289. {
  14290. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14291. {
  14292. tempIndex = 2;
  14293. }
  14294. else
  14295. {
  14296. tempIndex = gun_index;
  14297. }
  14298. for (int index = 0; index < AC_QUANTITY; index++)
  14299. {
  14300. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14301. {
  14302. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  14303. }
  14304. }// End of for AC_QUANTITY
  14305. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  14306. }
  14307. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14308. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  14309. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  14310. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  14311. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14312. }
  14313. //2.9====================================== Voltage L2 ====================================================
  14314. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  14315. {
  14316. // AC 3 phase L2 volatge
  14317. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  14318. {
  14319. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14320. {
  14321. tempIndex = 2;
  14322. }
  14323. else
  14324. {
  14325. tempIndex = gun_index;
  14326. }
  14327. for (int index = 0; index < AC_QUANTITY; index++)
  14328. {
  14329. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14330. {
  14331. 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
  14332. }
  14333. } // END OF FOR AC_QUANTITY
  14334. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  14335. }
  14336. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14337. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  14338. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  14339. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  14340. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  14341. }
  14342. //2.10====================================== Voltage L3 ====================================================
  14343. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  14344. {
  14345. // AC 3 phase L3 volatge
  14346. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  14347. {
  14348. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14349. {
  14350. tempIndex = 2;
  14351. }
  14352. else
  14353. {
  14354. tempIndex = gun_index;
  14355. }
  14356. for (int index = 0; index < AC_QUANTITY; index++)
  14357. {
  14358. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14359. {
  14360. 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
  14361. }
  14362. } // END OF FOR AC_QUANTITY
  14363. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  14364. }
  14365. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14366. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  14367. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  14368. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  14369. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  14370. }
  14371. //====================== Start SoC ================================
  14372. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  14373. {
  14374. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14375. 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))
  14376. {
  14377. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  14378. {
  14379. tempIndex = ((gun_index==2) ? 1: 0);
  14380. }
  14381. else
  14382. {
  14383. tempIndex = gun_index;
  14384. }
  14385. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14386. {
  14387. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14388. {
  14389. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14390. {
  14391. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  14392. }
  14393. }
  14394. }
  14395. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14396. {
  14397. for (int index = 0; index < CCS_QUANTITY; index++)
  14398. {
  14399. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14400. {
  14401. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  14402. }
  14403. }
  14404. }
  14405. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14406. {
  14407. for (int index = 0; index < GB_QUANTITY; index++)
  14408. {
  14409. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14410. {
  14411. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  14412. }
  14413. }
  14414. }
  14415. else if(gunType[gun_index] == GUN_TYPE_DO)
  14416. {
  14417. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14418. {
  14419. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14420. {
  14421. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  14422. }
  14423. }
  14424. }
  14425. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  14426. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  14427. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  14428. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  14429. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  14430. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  14431. } // END FOR DC CASE
  14432. }
  14433. //======================================== Message create ==============================================
  14434. json_object *StopTransaction = json_object_new_object();
  14435. json_object *transactionDatas = json_object_new_array();
  14436. json_object *sampledValues = json_object_new_array();
  14437. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  14438. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  14439. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  14440. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  14441. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  14442. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  14443. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  14444. {
  14445. json_object *transactionData = json_object_new_object();
  14446. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  14447. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  14448. {
  14449. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  14450. {
  14451. json_object *sampledValue = json_object_new_object();
  14452. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  14453. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  14454. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  14455. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  14456. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  14457. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  14458. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  14459. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  14460. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  14461. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  14462. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  14463. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  14464. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  14465. json_object_array_add(sampledValues, sampledValue);
  14466. }
  14467. }
  14468. json_object_object_add(transactionData, "sampledValue", sampledValues);
  14469. json_object_array_add(transactionDatas, transactionData);
  14470. }
  14471. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  14472. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  14473. ,MESSAGE_TYPE_CALL
  14474. ,guid
  14475. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  14476. json_object_put(StopTransaction);
  14477. // Check File "TempStopTransaction" Exist
  14478. if((access(TempStopTransaction,F_OK))!=-1)
  14479. {
  14480. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  14481. fclose(fopen(TempStopTransaction, "w"));
  14482. }
  14483. else
  14484. {
  14485. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  14486. FILE *log = fopen(TempStopTransaction, "w+");
  14487. if(log == NULL)
  14488. {
  14489. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  14490. return ;
  14491. }
  14492. else
  14493. {
  14494. fclose(log);
  14495. }
  14496. }
  14497. //Add TempStopTransaction | Update TempStopTransaction
  14498. // open file for writing
  14499. FILE *outfile;
  14500. outfile = fopen (TempStopTransaction, "a");
  14501. //DEBUG_INFO("data = %s\n", queuedata);
  14502. fputs(queuedata, outfile);
  14503. fputs("\n", outfile);
  14504. fclose (outfile);
  14505. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14506. }
  14507. void checkTempStopTransaction(int gun_index)
  14508. {
  14509. FILE *fptr1;
  14510. char ch;
  14511. char str[QUEUE_MESSAGE_LENGTH]={0};
  14512. char guid[37]={0};
  14513. char tempdata[65]={0};
  14514. char connectorStr[2]={0};
  14515. char TempStopTransaction[256];
  14516. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  14517. fptr1 = fopen(TempStopTransaction, "r");
  14518. //TempStopTransaction格式: 槍號,StopTransaction封包
  14519. if (!fptr1)
  14520. {
  14521. //printf(" File not found or unable to open the input file!!\n");
  14522. return ;
  14523. }
  14524. ch=fgetc(fptr1);
  14525. //printf(" Now the content of the file %s is : \n",fname);
  14526. rewind(fptr1);
  14527. if(ch!=EOF)
  14528. {
  14529. // copy all contents to the temporary file except the specific line
  14530. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  14531. {
  14532. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14533. if(str[0]=='\0')
  14534. {
  14535. break;
  14536. }
  14537. //TempStopTransaction格式: 槍號,StopTransaction封包
  14538. strncpy(connectorStr, str, 1);
  14539. if(atoi(connectorStr) != (gun_index+1))
  14540. {
  14541. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  14542. fclose(fptr1);
  14543. return ;
  14544. }
  14545. //random_uuid(guid);
  14546. strncpy(guid, str+6, 36); //copy guid
  14547. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  14548. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  14549. {
  14550. //DEBUG_INFO("StopTransaction mapitem pass\n");
  14551. }
  14552. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  14553. memset(str,0,ARRAY_SIZE(str));
  14554. }
  14555. }
  14556. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  14557. fclose(fptr1);
  14558. remove(TempStopTransaction); // remove the original file
  14559. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14560. }
  14561. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  14562. {
  14563. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  14564. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  14565. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  14566. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  14567. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  14568. }
  14569. int GetWebSocketPingInterval(void)
  14570. {
  14571. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14572. }
  14573. int GetServerSign(void)
  14574. {
  14575. return server_sign;
  14576. }
  14577. uint8_t GetOcppSecurityProfile()
  14578. {
  14579. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14580. }
  14581. void GetOcppChargerBoxId(uint8_t *data)
  14582. {
  14583. sprintf((char*)data, "%s", ShmOCPP16Data->ChargeBoxId);
  14584. }
  14585. void GetOcppSecurityPassword(uint8_t *data)
  14586. {
  14587. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14588. }
  14589. void SetOcppVersion(uint8_t *version)
  14590. {
  14591. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  14592. DEBUG_INFO("ocpp version: %s\n", version);
  14593. if(strstr((char*)version, "ocpp1.6") != NULL)
  14594. {
  14595. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  14596. }
  14597. else if(strstr((char*)version, "ocpp2.0") != NULL)
  14598. {
  14599. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  14600. system("pkill OcppBackend");
  14601. }
  14602. }
  14603. void SetServerSign(int value)
  14604. {
  14605. server_sign = value;
  14606. }
  14607. int GetBootNotificationInterval(void)
  14608. {
  14609. return BootNotificationInterval;
  14610. }
  14611. int GetInternetConn(void)
  14612. {
  14613. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  14614. }
  14615. int isConnectorInitMode(int gun_index)
  14616. {
  14617. int tempIndex = 0;
  14618. int result = TRUE;
  14619. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14620. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14621. {
  14622. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14623. {
  14624. tempIndex = ((gun_index==2) ? 1: 0);
  14625. }
  14626. else
  14627. {
  14628. tempIndex = gun_index;
  14629. }
  14630. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14631. {
  14632. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  14633. {
  14634. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  14635. } //end of the same index
  14636. }//end of for CHAdeMO_QUANTITY
  14637. }
  14638. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14639. {
  14640. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14641. {
  14642. tempIndex = ((gun_index==2) ? 1: 0);
  14643. }
  14644. else
  14645. {
  14646. tempIndex = gun_index;
  14647. }
  14648. for (int index = 0; index < CCS_QUANTITY; index++)
  14649. {
  14650. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14651. {
  14652. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  14653. } //end of the same index
  14654. } // end of for CCS_QUANTITY
  14655. }
  14656. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14657. {
  14658. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14659. {
  14660. tempIndex = ((gun_index==2) ? 1: 0);
  14661. }
  14662. else
  14663. {
  14664. tempIndex = gun_index;
  14665. }
  14666. for (int index = 0; index < GB_QUANTITY; index++)
  14667. {
  14668. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14669. {
  14670. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  14671. } //end of the same index
  14672. } // end of for GB_QUANTITY
  14673. }
  14674. else if(gunType[gun_index] == GUN_TYPE_DO)
  14675. {
  14676. tempIndex = gun_index;
  14677. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14678. {
  14679. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14680. {
  14681. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  14682. } //end of the same index
  14683. }
  14684. }
  14685. else
  14686. {
  14687. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14688. {
  14689. tempIndex = 2;
  14690. }
  14691. else
  14692. {
  14693. tempIndex = gun_index;
  14694. }
  14695. for (int index = 0; index < AC_QUANTITY; index++)
  14696. {
  14697. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14698. {
  14699. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  14700. }//end of the same index
  14701. }//end of for AC_QUANTITY
  14702. }
  14703. return result;
  14704. }
  14705. void refreshProcDogTimer()
  14706. {
  14707. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  14708. }
  14709. void InitialSystemValue(void)
  14710. {
  14711. int connectorIndex = 0;
  14712. //int valueASCII = 0;
  14713. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14714. gunTotalNumber=0;
  14715. SystemInitial = 0;
  14716. localversion=0;
  14717. BootNotificationInterval = 0;
  14718. authorizeRetryTimes = 0;
  14719. GunStatusInterval = 10;
  14720. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14721. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14722. //Hear Beat
  14723. HeartBeatWithNOResponse = 0;
  14724. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  14725. FirstHeartBeat = 0;
  14726. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  14727. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  14728. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  14729. memset(statusModeChage, 0, ARRAY_SIZE(statusModeChage));
  14730. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  14731. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  14732. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  14733. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  14734. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  14735. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  14736. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  14737. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  14738. memset(gunType, 0, ARRAY_SIZE(gunType));
  14739. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14740. {
  14741. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O')
  14742. {
  14743. // DO series
  14744. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  14745. {
  14746. SystemInitial = SystemInitial + 1;
  14747. gunTotalNumber = gunTotalNumber + 1;
  14748. gunType[connectorIndex] = GUN_TYPE_DO;
  14749. connectorIndex = connectorIndex + 1;
  14750. }
  14751. }
  14752. else
  14753. {
  14754. // DM, DW, DS series
  14755. //check connector / socket type (index: 8, 9, 10)
  14756. for(int index=7; index <10 ; index++)
  14757. {
  14758. if(index != 8)
  14759. {
  14760. // DC Connector
  14761. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  14762. {
  14763. SystemInitial = SystemInitial + 1;
  14764. gunTotalNumber = gunTotalNumber + 1;
  14765. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  14766. connectorIndex = connectorIndex + 1;
  14767. }
  14768. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  14769. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  14770. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  14771. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  14772. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  14773. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  14774. {
  14775. SystemInitial = SystemInitial + 1;
  14776. gunTotalNumber = gunTotalNumber + 1;
  14777. gunType[connectorIndex] = GUN_TYPE_CCS;
  14778. connectorIndex = connectorIndex + 1;
  14779. }
  14780. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  14781. {
  14782. SystemInitial = SystemInitial + 1;
  14783. gunTotalNumber = gunTotalNumber + 1;
  14784. gunType[connectorIndex] = GUN_TYPE_GBT;
  14785. connectorIndex = connectorIndex + 1;
  14786. }
  14787. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  14788. {
  14789. SystemInitial = SystemInitial + 1;
  14790. gunTotalNumber = gunTotalNumber + 1;
  14791. gunType[connectorIndex] = GUN_TYPE_DO;
  14792. connectorIndex = connectorIndex + 1;
  14793. }
  14794. }
  14795. else
  14796. {
  14797. // AC Connector
  14798. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14799. {
  14800. SystemInitial = SystemInitial + 1;
  14801. gunTotalNumber = gunTotalNumber + 1;
  14802. gunType[connectorIndex] = GUN_TYPE_AC;
  14803. connectorIndex = connectorIndex + 1;
  14804. }
  14805. }
  14806. }
  14807. }
  14808. //DEBUG_INFO("DC ...\n");
  14809. }
  14810. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  14811. {
  14812. //check connector / socket type (index: 8, 9, 10)
  14813. for(int index=7; index <10 ; index++)
  14814. {
  14815. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14816. {
  14817. SystemInitial = SystemInitial + 1;
  14818. gunTotalNumber = gunTotalNumber + 1;
  14819. gunType[connectorIndex] = GUN_TYPE_AC;
  14820. connectorIndex = connectorIndex + 1;
  14821. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  14822. }
  14823. }
  14824. }
  14825. //Status && ConnectorPlugIn Setting
  14826. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14827. {
  14828. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  14829. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  14830. }
  14831. for (int index = 0; index < CCS_QUANTITY; index++)
  14832. {
  14833. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  14834. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  14835. }
  14836. for (int index = 0; index < GB_QUANTITY; index++)
  14837. {
  14838. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  14839. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  14840. }
  14841. for (int index = 0; index < AC_QUANTITY; index++)
  14842. {
  14843. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  14844. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  14845. }
  14846. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14847. {
  14848. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  14849. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  14850. }
  14851. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  14852. {
  14853. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  14854. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  14855. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  14856. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  14857. }
  14858. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  14859. clientTime.Heartbeat=time((time_t*)NULL);
  14860. sleep(1);
  14861. }
  14862. void LWS_Send(char * str)
  14863. {
  14864. //=====================================================
  14865. // Check InternetConn 0: disconnected, 1: connected
  14866. //====================================================
  14867. if(GetOcppConnStatus() == 0)
  14868. {
  14869. DEBUG_INFO("offline now !!!\n");
  14870. return;
  14871. }
  14872. pthread_mutex_lock(&lock_send);
  14873. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14874. sprintf((char *)SendBuffer, "%s", str);
  14875. SendBufLen = strlen(str);
  14876. pthread_mutex_unlock(&lock_send);
  14877. lws_callback_on_writable(wsi_client);
  14878. //lws_service(context, 0);
  14879. //sleep(1);
  14880. }
  14881. void LWS_SendNow(char * str)
  14882. {
  14883. //=====================================================
  14884. // Check InternetConn 0: disconnected, 1: connected
  14885. //====================================================
  14886. if(GetOcppConnStatus() == 0)
  14887. {
  14888. DEBUG_INFO("offline now !!!\n");
  14889. return;
  14890. }
  14891. pthread_mutex_lock(&lock_send);
  14892. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14893. sprintf((char *)SendBuffer, "%s", str);
  14894. SendBufLen = strlen(str);
  14895. pthread_mutex_unlock(&lock_send);
  14896. lws_callback_on_writable(wsi_client);
  14897. lws_service(context, 0);
  14898. //sleep(1);
  14899. }